OmniSafe Logger#
|
Implementation of the Logger. |
Logger#
Documentation
- class omnisafe.common.logger.Logger(output_dir, exp_name, output_fname='progress.csv', seed=0, use_tensorboard=True, use_wandb=False, config=None, models=None)[source]#
Implementation of the Logger.
A logger to record the training process. It can record the training process to a file and print it to the console. It can also record the training process to tensorboard.
The logger can record the following data:
---------------------------------------------- | Name | Value | ---------------------------------------------- | Train/Epoch | 25 | | Metrics/EpCost | 24.56 | | Metrics/EpLen | 1000 | | Metrics/EpRet | 13.24 | | Metrics/EpStd | 0.12 | ----------------------------------------------
- Parameters:
output_dir (str) – The output directory.
exp_name (str) – The experiment name.
output_fname (str, optional) – The output file name. Defaults to ‘progress.csv’.
seed (int, optional) – The random seed. Defaults to 0.
use_tensorboard (bool, optional) – Whether to use tensorboard. Defaults to True.
use_wandb (bool, optional) – Whether to use wandb. Defaults to False.
config (Config or None, optional) – The config. Defaults to None.
models (list[torch.nn.Module] or None, optional) – The models. Defaults to None.
Initialize an instance of
Logger
.- _update_current_row()[source]#
Update the current row.
Update the current row with the data stored in the logger.
- Return type:
None
- property current_epoch: int#
Return the current epoch.
- dump_tabular()[source]#
Dump the tabular data to the console and the file.
The dumped data will be separated by the following steps: :rtype:
None
If the key is registered with window_length, the data will be averaged in the window.
Write the data to the csv file.
Write the data to the tensorboard.
Update the progress logger.
- get_stats(key, min_and_max=False)[source]#
Get the statistics of the key.
- Parameters:
key (str) – The key to be registered.
min_and_max (bool, optional) – Whether to record the min and max value of the key. Defaults to False.
- Returns:
The mean value of the key or (mean, min, max, std)
- Return type:
tuple
[float
,...
]
- log(msg, color='green', bold=False)[source]#
Log the message to the console and the file.
- Parameters:
msg (str) – The message to be logged.
color (str, optional) – The color of the message. Defaults to ‘green’.
bold (bool, optional) – Whether the message is bold. Defaults to False.
- Return type:
None
- property log_dir: str#
Return the log directory.
- register_key(key, window_length=None, min_and_max=False, delta=False)[source]#
Register a key to the logger.
The logger can record the following data:
---------------------------------------------------- | Name | Value | ---------------------------------------------------- | Train/Epoch | 25 | | Metrics/EpCost/Min | 22.38 | | Metrics/EpCost/Max | 25.48 | | Metrics/EpCost/Mean | 23.93 | ----------------------------------------------------
- Parameters:
key (str) – The name of the key.
window_length (int or None, optional) – The length of the window. Defaults to None.
min_and_max (bool, optional) – Whether to record the min and max value. Defaults to False.
delta (bool, optional) – Whether to record the delta value. Defaults to False.
- Return type:
None
- save_config(config)[source]#
Save the configuration to the log directory.
- Parameters:
config (Config) – The configuration to be saved.
- Return type:
None
- setup_torch_saver(what_to_save)[source]#
Setup the torch saver.
- Parameters:
what_to_save (dict[str, Any]) – The dict of the things to be saved.
- Return type:
None
- store(data=None, /, **kwargs)[source]#
Store the data to the logger.
Note
The data stored in
data
will be updated bykwargs
.- Parameters:
data (dict[str, float | np.ndarray | torch.Tensor] or None, optional) – The data to be stored. Defaults to None.
- Keyword Arguments:
kwargs (int, float, np.ndarray, or torch.Tensor) – The data to be stored.
- Return type:
None