Skip to content

Commit

Permalink
Adds loggers and git state logging for RSL-RL workflow (#42)
Browse files Browse the repository at this point in the history
# Description

Previously, we did not add the Orbit repo to the RSL-RL git repositories
list. This resulted in the git state of the runs not being logged when
using RSL-RL. This MR allows RSL-RL to log the git state of the orbit
repository.

If the argument `--run_name` is passed with the command line interface,
it overrides the default `run_name` in the agent cfg.

Additionally, the MR adds support for different logging types. These
changes were suggested in #36.

If the argument `--logger` is passed with the command line interface, it
overrides the default `logger` in the agent cfg to be one of
tensorboard, wandb or neptune.

## Type of change

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

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./orbit.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
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Co-authored-by: Mayank Mittal <[email protected]>
  • Loading branch information
arbhardwaj98 and Mayankm96 authored Dec 11, 2023
1 parent 7011b3b commit 34f0108
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
**/output/*
**/outputs/*
**/videos/*
**/wandb/*
**/.neptune/*
docker/artifacts/
*.tmp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from __future__ import annotations

from dataclasses import MISSING
from typing_extensions import Literal

from omni.isaac.orbit.utils import configclass

Expand Down Expand Up @@ -93,14 +94,46 @@ class RslRlOnPolicyRunnerCfg:
empirical_normalization: bool = MISSING
"""Whether to use empirical normalization."""

policy: RslRlPpoActorCriticCfg = MISSING
"""The policy configuration."""

algorithm: RslRlPpoAlgorithmCfg = MISSING
"""The algorithm configuration."""

##
# Checkpointing parameters
##

save_interval: int = MISSING
"""The number of iterations between saves."""

experiment_name: str = MISSING
"""The experiment name."""

run_name: str = ""
"""The run name. Default is empty string."""
"""The run name. Default is empty string.
The name of the run directory is typically the time-stamp at execution. If the run name is not empty,
then it is appended to the run directory's name, i.e. the logging directory's name will become
``{time-stamp}_{run_name}``.
"""

##
# Logging parameters
##

logger: Literal["tensorboard", "neptune", "wandb"] = "tensorboard"
"""The logger to use. Default is tensorboard."""

neptune_project: str = "orbit"
"""The neptune project name. Default is "orbit"."""

wandb_project: str = "orbit"
"""The wandb project name. Default is "orbit"."""

##
# Loading parameters
##

resume: bool = False
"""Whether to resume. Default is False."""
Expand All @@ -116,9 +149,3 @@ class RslRlOnPolicyRunnerCfg:
If regex expression, the latest (alphabetical order) matching file will be loaded.
"""

policy: RslRlPpoActorCriticCfg = MISSING
"""The policy configuration."""

algorithm: RslRlPpoAlgorithmCfg = MISSING
"""The algorithm configuration."""
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ def __repr__(self):
Properties -- Gym.Wrapper
"""

@property
def cfg(self) -> object:
"""Returns the configuration class instance of the environment."""
return self.unwrapped.cfg

@property
def render_mode(self) -> str | None:
"""Returns the :attr:`Env` :attr:`render_mode`."""
Expand Down
14 changes: 14 additions & 0 deletions source/standalone/workflows/rsl_rl/cli_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def add_rsl_rl_args(parser: argparse.ArgumentParser):
arg_group.add_argument("--resume", type=bool, default=None, help="Whether to resume from a checkpoint.")
arg_group.add_argument("--load_run", type=str, default=None, help="Name of the run folder to resume from.")
arg_group.add_argument("--checkpoint", type=str, default=None, help="Checkpoint file to resume from.")
arg_group.add_argument(
"--logger", type=str, default=None, choices={"wandb", "tensorboard", "neptune"}, help="Logger module to use."
)
arg_group.add_argument(
"--log_project_name", type=str, default=None, help="Name of the logging project when using wandb or neptune."
)


def parse_rsl_rl_cfg(task_name: str, args_cli: argparse.Namespace) -> RslRlOnPolicyRunnerCfg:
Expand All @@ -52,5 +58,13 @@ def parse_rsl_rl_cfg(task_name: str, args_cli: argparse.Namespace) -> RslRlOnPol
rslrl_cfg.load_run = args_cli.load_run
if args_cli.checkpoint is not None:
rslrl_cfg.load_checkpoint = args_cli.checkpoint
if args_cli.run_name is not None:
rslrl_cfg.run_name = args_cli.run_name
if args_cli.logger is not None:
rslrl_cfg.logger = args_cli.logger
# set the project name for wandb and neptune
if rslrl_cfg.logger in {"wandb", "neptune"} and args_cli.log_project_name:
rslrl_cfg.wandb_project = args_cli.log_project_name
rslrl_cfg.neptune_project = args_cli.log_project_name

return rslrl_cfg
5 changes: 4 additions & 1 deletion source/standalone/workflows/rsl_rl/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.")
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("--run_name", type=str, default=None, help="Name of the run.")
parser.add_argument("--seed", type=int, default=None, help="Seed used for the environment")
# append RSL-RL cli arguments
cli_args.add_rsl_rl_args(parser)
Expand Down Expand Up @@ -81,7 +82,7 @@ def main():
log_root_path = os.path.join("logs", "rsl_rl", agent_cfg.experiment_name)
log_root_path = os.path.abspath(log_root_path)
print(f"[INFO] Logging experiment in directory: {log_root_path}")
# specify directory for logging runs
# specify directory for logging runs: {time-stamp}_{run_name}
log_dir = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
if agent_cfg.run_name:
log_dir += f"_{agent_cfg.run_name}"
Expand All @@ -105,6 +106,8 @@ def main():

# create runner from rsl-rl
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__)
# save resume path before creating a new log_dir
if agent_cfg.resume:
# get path to previous checkpoint
Expand Down

0 comments on commit 34f0108

Please sign in to comment.