stable_learning_control.utils.log_utils.helpers

Several logging related helper functions.

Module Contents

Functions

colorize(string, color[, bold, highlight])

Colorize a string.

log_to_std_out(msg[, color, bold, highlight, type])

Print a colorized message to stdout.

setup_logger_kwargs(exp_name[, seed, ...])

Sets up the output_dir for a logger and returns a dict for logger kwargs.

dict_to_mdtable(d[, key, val])

Convert a dictionary to a markdown table.

Attributes

LOG_TYPES

stable_learning_control.utils.log_utils.helpers.LOG_TYPES[source]
stable_learning_control.utils.log_utils.helpers.colorize(string, color, bold=False, highlight=False)[source]

Colorize a string.

See also

This function wraps the gym.utils.colorize() function to make sure that it also works with empty color strings.

Parameters:
  • string (str) – The string you want to colorize.

  • color (str) – The color you want to use.

  • bold (bool, optional) – Whether you want the text to be bold. Defaults to False.

  • highlight (bool, optional) – Whether you want to highlight the text. Defaults to False.

Returns:

Colorized string.

Return type:

str

stable_learning_control.utils.log_utils.helpers.log_to_std_out(msg, color='', bold=False, highlight=False, type=None, *args, **kwargs)[source]

Print a colorized message to stdout.

Parameters:
  • msg (str) – Message you want to log.

  • color (str, optional) – Color you want the message to have. Defaults to "".

  • bold (bool, optional) – Whether you want the text to be bold text has to be bold.

  • highlight (bool, optional) – Whether you want to highlight the text. Defaults to False.

  • type (str, optional) – The log message type. Options are: info, warning and error. Defaults to None.

  • *args – All args to pass to the print function.

  • **kwargs – All kwargs to pass to the print function.

stable_learning_control.utils.log_utils.helpers.setup_logger_kwargs(exp_name, seed=None, save_checkpoints=False, use_tensorboard=False, tb_log_freq='low', use_wandb=False, wandb_job_type=DEFAULT_WANDB_JOB_TYPE, wandb_project=DEFAULT_WANDB_PROJECT, wandb_group=None, wandb_run_name=None, quiet=False, verbose_fmt=DEFAULT_STD_OUT_TYPE, verbose_vars=[], data_dir=None, datestamp=False)[source]

Sets up the output_dir for a logger and returns a dict for logger kwargs.

If no seed is given and datestamp is false,

output_dir = data_dir/exp_name

If a seed is given and datestamp is false,

output_dir = data_dir/exp_name/exp_name_s[seed]

If datestamp is true, amend to

output_dir = data_dir/YY-MM-DD_exp_name/YY-MM-DD_HH-MM-SS_exp_name_s[seed]

You can force datestamp=True by setting FORCE_DATESTAMP=True in stable_learning_control/user_config.py.

Parameters:
  • exp_name (str) – Name for experiment.

  • seed (int, optional) – Seed for random number generators used by experiment.

  • save_checkpoints (bool, optional) – Save checkpoints during training. Defaults to False.

  • use_tensorboard (bool, optional) – Whether you want to use TensorBoard. Defaults to True.

  • tb_log_freq (str, optional) – The TensorBoard log frequency. Options are low (Recommended: logs at every epoch) and high (logs at every SGD update ” batch). Defaults to low since this is less resource intensive.

  • use_wandb (bool, optional) – Whether you want to use Weights & Biases. Defaults to False.

  • wandb_job_type (str, optional) – The Weights & Biases job type. Defaults to None.

  • wandb_project (str, optional) – The name of the Weights & Biases project you want to log to. Defaults to None.

  • wandb_group (str, optional) – The name of the Weights & Biases group you want to assign the run to. Defaults to None.

  • wandb_run_name (str, optional) – The name of the Weights & Biases run. Defaults to None which means that the run name is automatically generated.

  • quiet (bool, optional) – Whether you want to suppress logging of the diagnostics to the stdout. Defaults to False.

  • verbose_fmt (str, optional) – The format in which the diagnostics are displayed to the terminal. Options are table which supplies them as a table and line which prints them in one line. Defaults to line.

  • verbose_vars (list, optional) – A list of variables you want to log to the stdout. By default all variables are logged.

  • data_dir (str, optional) – Path to folder where results should be saved. Default is the DEFAULT_DATA_DIR in stable_learning_control/user_config.py. Defaults to None.

  • datestamp (bool, optional) – Whether to include a date and timestamp in the name of the save directory. Defaults to False.

Returns:

logger_kwargs

A dict containing output_dir and exp_name.

Return type:

dict

stable_learning_control.utils.log_utils.helpers.dict_to_mdtable(d, key='Name', val='Value')[source]

Convert a dictionary to a markdown table.

Parameters:
  • d (dict) – The dictionary you want to convert.

  • key (str, optional) – The name of the key column. Defaults to "Name".

  • val (str, optional) – The name of the value column. Defaults to "Value".

Returns:

The markdown table.

Return type:

str