Loggers#
Overview#
The loggers/ module contains the Logger class, which is responsible for:
Recording textual logs to disk
Saving intermediate experiment results (e.g., rewards, steps)
Plotting reward curves and evaluation metrics
Computing statistical summaries (mean, IQM)
Structuring output directories per run
This ensures that each experiment is reproducible and its outcomes are easy to inspect and analyze visually or numerically.
Logger#
- class objectrl.loggers.logger.Logger(result_path: Path, env_name: str, model_name: str, seed: int, config: MainConfig | None = None)[source]#
Bases:
objectLogger class for experiment tracking, result storage, and evaluation plotting.
- Parameters:
result_path (str) – Base directory where results will be stored.
env_name (str) – Name of the environment being used.
model_name (str) – Name of the model being trained.
seed (int) – Random seed for reproducibility.
config (MainConfig, optional) – Configuration object containing experiment parameters.
- path#
Path to the directory where logs and plots are saved.
- Type:
Path
- eval_results#
Stores evaluation rewards for different training steps.
- Type:
dict
- logger#
Python logger instance configured to write to a file.
- Type:
logging.Logger
- __init__(result_path: Path, env_name: str, model_name: str, seed: int, config: MainConfig | None = None)[source]#
- create_logger() Logger[source]#
Sets up a file-based logger.
- Parameters:
None
- Returns:
Configured logger object for recording logs.
- Return type:
logging.Logger
- log(message: str) None[source]#
Logs an informational message.
- Parameters:
message (str) – The message to be logged.
- Returns:
None
- critical(message: str) None[source]#
Logs a critical message (used for evaluation results).
- Parameters:
message (str) – The critical message to be logged.
- Returns:
None
- episode_summary(episode: int, steps: int, info: dict) None[source]#
Logs a summary of a completed episode.
- Parameters:
episode (int) – Episode index.
steps (int) – Step count at episode end.
info (dict) – Dictionary containing reward and step information.
- Returns:
None
- plot_rewards(rewards: ndarray, steps: ndarray) None[source]#
Generates and saves a plot of normalized per-episode rewards.
- Parameters:
rewards (numpy.ndarray) – Array of rewards per episode.
steps (numpy.ndarray) – Array of steps per episode.
- Returns:
None
- save(info: dict, episode: int, n_step: int) None[source]#
Saves episode and step reward information and generates training curve plots.
- Parameters:
info (dict) – Dictionary containing episode and step rewards.
episode (int) – Current episode index.
n_step (int) – Current training step index.
- Returns:
None
- static IQM_reward_calculator(rewards: Tensor) floating[source]#
Computes the Interquartile Mean (IQM) of rewards.
- Parameters:
rewards (torch.Tensor) – Tensor of evaluation rewards.
- Returns:
The IQM of the rewards.
- Return type:
float
Initialization#
The Logger is initialized using explicit arguments: result_path, env_name, model_name, and seed. It constructs a unique timestamped folder using this metadata and stores:
Logs (
log.log)Evaluation results (
eval_results.npy)Visualizations (
learning-curve.png,eval-curve.png)Rewards and metrics (
episode_rewards.npy,step_rewards.npy)
from objectrl.loggers.logger import Logger
from pathlib import Path
logger = Logger(
result_path="../_logs",
env_name="cheetah",
model_name="sac",
seed=0,
config=config # Optional: logs config details if provided
)
Note
The config argument is optional. If provided, its content is logged for reproducibility under log.log.
Logging Messages#
You can log messages via:
logger.log(message)for standard info logslogger.critical(message)for critical highlights (e.g., evaluation results)logger(message)— uses__call__as shorthand forlogger.log(...)
Saving and Plotting Results#
During training, the logger tracks episode-level and step-level rewards. These are saved and plotted automatically at intervals.
logger.save(info, episode, step)
logger.plot_rewards(rewards, steps)
The saved files include:
episode_rewards.npy: episode-level rewardsstep_rewards.npy: raw reward values per steplearning-curve.png: training reward curve
Evaluation Logging#
During evaluation, rewards across multiple episodes are saved and summarized using:
Mean reward
Interquartile Mean (IQM) — a robust average that ignores extreme outliers
logger.save_eval_results(current_step, reward_tensor)
This also plots an eval-curve.png showing mean ± standard deviation over training steps.
Reward Statistics#
The IQM_reward_calculator statically computes the Interquartile Mean (middle 50%) of a set of rewards. This is often preferred in RL benchmarking to reduce the effect of outliers.
iqm = Logger.IQM_reward_calculator(rewards)
Directory Structure#
Each experiment creates an output folder under:
{result_path}/{env.name}/{model.name}/seed_{seed}/{timestamp}/
Example:
_logs/cheetah/sac/seed_01/2025-05-26_14-30-15/
This folder includes:
Logs:
log.logTraining plot:
learning-curve.pngEvaluation plot:
eval-curve.pngNumPy metrics:
episode_rewards.npy,step_rewards.npy,eval_results.npy