Commit 54fcabd1 authored by Kelly Guo's avatar Kelly Guo Committed by Kelly Guo

Updates benchmarking scripts for Isaac Sim 4.5 and hydra (#143)

This change updates the benchmarking utilities to follow new module
naming for Isaac Sim 4.5. In addition, hydra support is added for the
benchmark scripts to allow modifications of config parameters via
command line. Hydra config parsing utilities are updated to allow for
missing agent configurations when benchmarking non-RL workflows.

<!-- As you go through the list, delete the ones that are not
applicable. -->

- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)

- [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
- [ ] 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
- [ ] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->
parent d94f9d4d
......@@ -40,13 +40,15 @@ def register_task_to_hydra(
"""
# load the configurations
env_cfg = load_cfg_from_registry(task_name, "env_cfg_entry_point")
agent_cfg = load_cfg_from_registry(task_name, agent_cfg_entry_point)
# replace gymnasium spaces with strings because OmegaConf does not support them.
# this must be done before converting the env configs to dictionary to avoid internal reinterpretations
replace_env_cfg_spaces_with_strings(env_cfg)
agent_cfg = None
if agent_cfg_entry_point:
agent_cfg = load_cfg_from_registry(task_name, agent_cfg_entry_point)
# replace gymnasium spaces with strings because OmegaConf does not support them.
# this must be done before converting the env configs to dictionary to avoid internal reinterpretations
replace_env_cfg_spaces_with_strings(env_cfg)
# convert the configs to dictionary
env_cfg_dict = env_cfg.to_dict()
if isinstance(agent_cfg, dict):
if isinstance(agent_cfg, dict) or agent_cfg is None:
agent_cfg_dict = agent_cfg
else:
agent_cfg_dict = agent_cfg.to_dict()
......@@ -91,7 +93,7 @@ def hydra_task_config(task_name: str, agent_cfg_entry_point: str) -> Callable:
# this must be done after converting the env configs from dictionary to avoid internal reinterpretations
replace_strings_with_env_cfg_spaces(env_cfg)
# get agent configs
if isinstance(agent_cfg, dict):
if isinstance(agent_cfg, dict) or agent_cfg is None:
agent_cfg = hydra_env_cfg["agent"]
else:
agent_cfg.from_dict(hydra_env_cfg["agent"])
......
......@@ -8,6 +8,7 @@
"""Launch Isaac Sim Simulator first."""
import argparse
import sys
import time
from omni.isaac.lab.app import AppLauncher
......@@ -17,9 +18,6 @@ parser = argparse.ArgumentParser(description="Train an RL agent with RL-Games.")
parser.add_argument("--video", action="store_true", default=False, help="Record videos during training.")
parser.add_argument("--video_length", type=int, default=200, help="Length of the recorded video (in steps).")
parser.add_argument("--video_interval", type=int, default=2000, help="Interval between video recordings (in steps).")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
parser.add_argument("--num_envs", type=int, default=None, help="Number of environments to simulate.")
parser.add_argument("--task", type=str, default=None, help="Name of the task.")
parser.add_argument("--seed", type=int, default=None, help="Seed used for the environment")
......@@ -38,11 +36,14 @@ parser.add_argument(
# append AppLauncher cli args
AppLauncher.add_app_launcher_args(parser)
# parse the arguments
args_cli, _ = parser.parse_known_args()
args_cli, hydra_args = parser.parse_known_args()
# always enable cameras to record video
if args_cli.video:
args_cli.enable_cameras = True
# clear out sys.argv for Hydra
sys.argv = [sys.argv[0]] + hydra_args
app_start_time_begin = time.perf_counter_ns()
# launch omniverse app
......@@ -78,10 +79,11 @@ import os
import torch
from datetime import datetime
from omni.isaac.lab.envs import DirectMARLEnvCfg, DirectRLEnvCfg, ManagerBasedRLEnvCfg
from omni.isaac.lab.utils.dict import print_dict
import omni.isaac.lab_tasks # noqa: F401
from omni.isaac.lab_tasks.utils import parse_env_cfg
from omni.isaac.lab_tasks.utils.hydra import hydra_task_config
imports_time_end = time.perf_counter_ns()
......@@ -101,13 +103,13 @@ benchmark = BaseIsaacBenchmark(
)
def main():
"""Train with RL-Games agent."""
@hydra_task_config(args_cli.task, None)
def main(env_cfg: ManagerBasedRLEnvCfg | DirectRLEnvCfg | DirectMARLEnvCfg, agent_cfg: dict):
"""Benchmark without RL in the loop."""
# parse configuration
env_cfg = parse_env_cfg(
args_cli.task, device=args_cli.device, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
)
# override configurations with non-hydra CLI arguments
env_cfg.scene.num_envs = args_cli.num_envs if args_cli.num_envs is not None else env_cfg.scene.num_envs
env_cfg.sim.device = args_cli.device if args_cli.device is not None else env_cfg.sim.device
# process distributed
world_size = 1
......
......@@ -8,6 +8,7 @@
"""Launch Isaac Sim Simulator first."""
import argparse
import sys
import time
from omni.isaac.lab.app import AppLauncher
......@@ -17,9 +18,6 @@ parser = argparse.ArgumentParser(description="Train an RL agent with RL-Games.")
parser.add_argument("--video", action="store_true", default=False, help="Record videos during training.")
parser.add_argument("--video_length", type=int, default=200, help="Length of the recorded video (in steps).")
parser.add_argument("--video_interval", type=int, default=2000, help="Interval between video recordings (in steps).")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
parser.add_argument("--num_envs", type=int, default=None, help="Number of environments to simulate.")
parser.add_argument("--task", type=str, default=None, help="Name of the task.")
parser.add_argument("--seed", type=int, default=None, help="Seed used for the environment")
......@@ -38,11 +36,14 @@ parser.add_argument(
# append AppLauncher cli args
AppLauncher.add_app_launcher_args(parser)
# parse the arguments
args_cli, _ = parser.parse_known_args()
args_cli, hydra_args = parser.parse_known_args()
# always enable cameras to record video
if args_cli.video:
args_cli.enable_cameras = True
# clear out sys.argv for Hydra
sys.argv = [sys.argv[0]] + hydra_args
app_start_time_begin = time.perf_counter_ns()
# launch omniverse app
......@@ -64,6 +65,7 @@ imports_time_begin = time.perf_counter_ns()
import gymnasium as gym
import math
import os
import random
import torch
from datetime import datetime
......@@ -71,11 +73,12 @@ from rl_games.common import env_configurations, vecenv
from rl_games.common.algo_observer import IsaacAlgoObserver
from rl_games.torch_runner import Runner
from omni.isaac.lab.envs import DirectMARLEnvCfg, DirectRLEnvCfg, ManagerBasedRLEnvCfg
from omni.isaac.lab.utils.dict import print_dict
from omni.isaac.lab.utils.io import dump_pickle, dump_yaml
import omni.isaac.lab_tasks # noqa: F401
from omni.isaac.lab_tasks.utils import load_cfg_from_registry, parse_env_cfg
from omni.isaac.lab_tasks.utils.hydra import hydra_task_config
from omni.isaac.lab_tasks.utils.wrappers.rl_games import RlGamesGpuEnv, RlGamesVecEnvWrapper
imports_time_end = time.perf_counter_ns()
......@@ -115,17 +118,18 @@ benchmark = BaseIsaacBenchmark(
)
def main():
@hydra_task_config(args_cli.task, "rl_games_cfg_entry_point")
def main(env_cfg: ManagerBasedRLEnvCfg | DirectRLEnvCfg | DirectMARLEnvCfg, agent_cfg: dict):
"""Train with RL-Games agent."""
# parse seed from command line
args_cli_seed = args_cli.seed
# parse configuration
env_cfg = parse_env_cfg(
args_cli.task, device=args_cli.device, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
)
# override configurations with non-hydra CLI arguments
env_cfg.scene.num_envs = args_cli.num_envs if args_cli.num_envs is not None else env_cfg.scene.num_envs
env_cfg.sim.device = args_cli.device if args_cli.device is not None else env_cfg.sim.device
agent_cfg = load_cfg_from_registry(args_cli.task, "rl_games_cfg_entry_point")
# randomly sample a seed if seed = -1
if args_cli.seed == -1:
args_cli.seed = random.randint(0, 10000)
agent_cfg["params"]["seed"] = args_cli.seed if args_cli.seed is not None else agent_cfg["params"]["seed"]
# process distributed
world_rank = 0
......@@ -134,10 +138,6 @@ def main():
agent_cfg.device = f"cuda:{app_launcher.local_rank}"
world_rank = app_launcher.global_rank
# override from command line
if args_cli_seed is not None:
agent_cfg["params"]["seed"] = args_cli_seed
# specify directory for logging experiments
log_root_path = os.path.join("logs", "rl_games", agent_cfg["params"]["config"]["name"])
log_root_path = os.path.abspath(log_root_path)
......
......@@ -13,6 +13,7 @@
"""Launch Isaac Sim Simulator first."""
import argparse
import sys
import time
from omni.isaac.lab.app import AppLauncher
......@@ -24,9 +25,6 @@ parser = argparse.ArgumentParser(description="Train an RL agent with RSL-RL.")
parser.add_argument("--video", action="store_true", default=False, help="Record videos during training.")
parser.add_argument("--video_length", type=int, default=200, help="Length of the recorded video (in steps).")
parser.add_argument("--video_interval", type=int, default=2000, help="Interval between video recordings (in steps).")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
parser.add_argument("--num_envs", type=int, default=4096, help="Number of environments to simulate.")
parser.add_argument("--task", type=str, default=None, help="Name of the task.")
parser.add_argument("--seed", type=int, default=42, help="Seed used for the environment")
......@@ -44,7 +42,14 @@ cli_args.add_rsl_rl_args(parser)
# append AppLauncher cli args
AppLauncher.add_app_launcher_args(parser)
# to ensure kit args don't break the benchmark arg parsing
args_cli, _ = parser.parse_known_args()
args_cli, hydra_args = parser.parse_known_args()
# always enable cameras to record video
if args_cli.video:
args_cli.enable_cameras = True
# clear out sys.argv for Hydra
sys.argv = [sys.argv[0]] + hydra_args
app_start_time_begin = time.perf_counter_ns()
......@@ -64,12 +69,13 @@ from datetime import datetime
from rsl_rl.runners import OnPolicyRunner
from omni.isaac.lab.envs import ManagerBasedRLEnvCfg
from omni.isaac.lab.envs import DirectMARLEnvCfg, DirectRLEnvCfg, ManagerBasedRLEnvCfg
from omni.isaac.lab.utils.dict import print_dict
from omni.isaac.lab.utils.io import dump_pickle, dump_yaml
import omni.isaac.lab_tasks # noqa: F401
from omni.isaac.lab_tasks.utils import get_checkpoint_path, parse_env_cfg
from omni.isaac.lab_tasks.utils import get_checkpoint_path
from omni.isaac.lab_tasks.utils.hydra import hydra_task_config
from omni.isaac.lab_tasks.utils.wrappers.rsl_rl import RslRlOnPolicyRunnerCfg, RslRlVecEnvWrapper
imports_time_end = time.perf_counter_ns()
......@@ -113,14 +119,13 @@ benchmark = BaseIsaacBenchmark(
)
def main():
@hydra_task_config(args_cli.task, "rsl_rl_cfg_entry_point")
def main(env_cfg: ManagerBasedRLEnvCfg | DirectRLEnvCfg | DirectMARLEnvCfg, agent_cfg: RslRlOnPolicyRunnerCfg):
"""Train with RSL-RL agent."""
# parse configuration
benchmark.set_phase("loading", start_recording_frametime=False, start_recording_runtime=True)
env_cfg: ManagerBasedRLEnvCfg = parse_env_cfg(
args_cli.task, device=args_cli.device, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
)
agent_cfg: RslRlOnPolicyRunnerCfg = cli_args.parse_rsl_rl_cfg(args_cli.task, args_cli)
agent_cfg = cli_args.update_rsl_rl_cfg(agent_cfg, args_cli)
env_cfg.scene.num_envs = args_cli.num_envs if args_cli.num_envs is not None else env_cfg.scene.num_envs
# specify directory for logging experiments
log_root_path = os.path.join("logs", "rsl_rl", agent_cfg.experiment_name)
......
......@@ -7,8 +7,8 @@
import glob
import os
from omni.isaac.benchmark.services import BaseIsaacBenchmark
from omni.isaac.benchmark.services.metrics.measurements import DictMeasurement, ListMeasurement, SingleMeasurement
from isaacsim.benchmark.services import BaseIsaacBenchmark
from isaacsim.benchmark.services.metrics.measurements import DictMeasurement, ListMeasurement, SingleMeasurement
from tensorboard.backend.event_processing import event_accumulator
......
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