Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions scripts/benchmarks/benchmark_rsl_rl.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
from isaaclab.utils.dict import print_dict
from isaaclab.utils.io import dump_yaml

from isaaclab_rl.rsl_rl import RslRlOnPolicyRunnerCfg, RslRlVecEnvWrapper
from isaaclab_rl.rsl_rl import RslRlOnPolicyRunnerCfg, RslRlVecEnvWrapper, handle_deprecated_rsl_rl_cfg

import isaaclab_tasks # noqa: F401
from isaaclab_tasks.utils import get_checkpoint_path
Expand Down Expand Up @@ -197,6 +197,9 @@ def main(env_cfg: ManagerBasedRLEnvCfg | DirectRLEnvCfg | DirectMARLEnvCfg, agen
task_startup_time_end = time.perf_counter_ns()

# create runner from rsl-rl
import importlib.metadata
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Local import should be at module level

import importlib.metadata is placed inside main(), which is unconventional and inconsistent with how train.py handles the same import (import importlib.metadata as metadata at module scope). While Python caches modules so correctness is unaffected, placing standard-library imports at the top of the file is the idiomatic Python practice and makes dependencies easier to see at a glance.

Move this import to the top-level import block and remove the inline one.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

installed_version = importlib.metadata.version("rsl-rl-lib")
agent_cfg = handle_deprecated_rsl_rl_cfg(agent_cfg, installed_version)
runner = OnPolicyRunner(env, agent_cfg.to_dict(), log_dir=log_dir, device=agent_cfg.device)
# write git state to logs
runner.add_git_repo_to_log(__file__)
Expand Down Expand Up @@ -229,13 +232,13 @@ def main(env_cfg: ManagerBasedRLEnvCfg | DirectRLEnvCfg | DirectMARLEnvCfg, agen
# prepare RL timing dict
collection_fps = (
1
/ (np.array(log_data["Perf/collection time"]))
/ (np.array(log_data["Perf/collection_time"]))
* env.unwrapped.num_envs
* agent_cfg.num_steps_per_env
* world_size
)
rl_training_times = {
"Collection Time": (np.array(log_data["Perf/collection time"]) / 1000).tolist(),
"Collection Time": (np.array(log_data["Perf/collection_time"]) / 1000).tolist(),
"Learning Time": (np.array(log_data["Perf/learning_time"]) / 1000).tolist(),
"Collection FPS": collection_fps.tolist(),
"Total FPS": log_data["Perf/total_fps"] * world_size,
Expand Down