Skip to content

Commit

Permalink
Updates benchmarking scripts for Isaac Sim 4.5 and hydra (isaac-sim#143)
Browse files Browse the repository at this point in the history
# Description

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.

## Type of change

<!-- 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)

## 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
- [ ] 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
-->
  • Loading branch information
kellyguo11 authored and Dhoeller19 committed Oct 18, 2024
1 parent e9e2f3b commit 92fd5d3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ 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)
agent_cfg = None
if agent_cfg_entry_point:
agent_cfg = load_cfg_from_registry(task_name, agent_cfg_entry_point)
# 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()
Expand Down Expand Up @@ -83,7 +85,7 @@ def hydra_main(hydra_env_cfg: DictConfig, env_cfg=env_cfg, agent_cfg=agent_cfg):
hydra_env_cfg = replace_strings_with_slices(hydra_env_cfg)
# update the configs with the Hydra command line arguments
env_cfg.from_dict(hydra_env_cfg["env"])
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"])
Expand Down
24 changes: 13 additions & 11 deletions source/standalone/benchmarks/benchmark_non_rl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""Launch Isaac Sim Simulator first."""

import argparse
import sys
import time

from omni.isaac.lab.app import AppLauncher
Expand All @@ -17,9 +18,6 @@
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")
Expand All @@ -38,11 +36,14 @@
# 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
Expand Down Expand Up @@ -78,10 +79,11 @@
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()

Expand All @@ -101,13 +103,13 @@
)


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
Expand Down
34 changes: 17 additions & 17 deletions source/standalone/benchmarks/benchmark_rlgames.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""Launch Isaac Sim Simulator first."""

import argparse
import sys
import time

from omni.isaac.lab.app import AppLauncher
Expand All @@ -17,9 +18,6 @@
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")
Expand All @@ -38,11 +36,14 @@
# 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
Expand All @@ -64,18 +65,20 @@
import gymnasium as gym
import math
import os
import random
import torch
from datetime import datetime

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()
Expand Down Expand Up @@ -115,17 +118,18 @@
)


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
Expand All @@ -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)
Expand Down
27 changes: 16 additions & 11 deletions source/standalone/benchmarks/benchmark_rsl_rl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""Launch Isaac Sim Simulator first."""

import argparse
import sys
import time

from omni.isaac.lab.app import AppLauncher
Expand All @@ -24,9 +25,6 @@
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")
Expand All @@ -44,7 +42,14 @@
# 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()

Expand All @@ -64,12 +69,13 @@

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()
Expand Down Expand Up @@ -113,14 +119,13 @@
)


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)
Expand Down
4 changes: 2 additions & 2 deletions source/standalone/benchmarks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 92fd5d3

Please sign in to comment.