lit_sb3.utils.logger
source module lit_sb3.utils.logger
Classes
-
Video — Video data class storing the video frames and the frame per seconds.
-
Figure — Figure data class storing a matplotlib figure and whether to close the figure after logging it.
-
Image — Image data class storing an image and data format.
-
HParam — Hyperparameter data class storing hyperparameters and metrics in dictionaries.
-
FormatUnsupportedError — Custom error to display informative message when.
-
KVWriter — Key Value writer.
-
SeqWriter — sequence writer.
-
HumanOutputFormat — A human-readable output format producing ASCII tables of key-value pairs.
-
JSONOutputFormat — Log to a file, in the JSON format.
-
CSVOutputFormat — Log to a file, in a CSV format.
-
TensorBoardOutputFormat — Dumps key/value pairs into TensorBoard's numeric format.
-
Logger — The logger class.
Functions
-
filter_excluded_keys — Filters the keys specified by
key_excludefor the specified format. -
make_output_format — Return a logger for the requested format.
-
configure — Configure the current logger.
-
read_json — Read a json file using pandas.
-
read_csv — Read a csv file using pandas.
source class Video(frames: torch.Tensor, fps: float)
Video data class storing the video frames and the frame per seconds.
Parameters
-
frames : torch.Tensor — frames to create the video from
-
fps : float — frames per second
source class Figure(figure: matplotlib.figure.Figure, close: bool)
Figure data class storing a matplotlib figure and whether to close the figure after logging it.
Parameters
-
figure : matplotlib.figure.Figure — figure to log
-
close : bool — if true, close the figure after logging it
source class Image(image: torch.Tensor | np.ndarray | str, dataformats: str)
Image data class storing an image and data format.
Parameters
-
image : torch.Tensor | np.ndarray | str — image to log
-
dataformats : str — Image data format specification of the form NCHW, NHWC, CHW, HWC, HW, WH, etc. More info in add_image method doc at https://pytorch.org/docs/stable/tensorboard.html Gym envs normally use 'HWC' (channel last)
source class HParam(hparam_dict: Mapping[str, bool | str | float | None], metric_dict: Mapping[str, float])
Hyperparameter data class storing hyperparameters and metrics in dictionaries.
Parameters
-
hparam_dict : Mapping[str, bool | str | float | None] — key-value pairs of hyperparameters to log
-
metric_dict : Mapping[str, float] — key-value pairs of metrics to log A non-empty metrics dict is required to display hyperparameters in the corresponding Tensorboard section.
source class FormatUnsupportedError(unsupported_formats: Sequence[str], value_description: str)
Bases : NotImplementedError
Custom error to display informative message when.
a value is not supported by some formats.
Parameters
-
unsupported_formats : Sequence[str] — A sequence of unsupported formats, for instance
["stdout"]. -
value_description : str — Description of the value that cannot be logged by this format.
source method KVWriter.write(key_values: dict[str, Any], key_excluded: dict[str, tuple[str, ...] | None], step: int = 0) → None
Write a dictionary to file.
Parameters
-
key_values : dict[str, Any] — Dictionary of key-value pairs to write.
-
key_excluded : dict[str, tuple[str, ...] | None] — Dictionary mapping keys to output format exclusions.
-
step : int — Current step number.
Raises
-
NotImplementedError
source method KVWriter.close() → None
Close owned resources.
Raises
-
NotImplementedError
source method SeqWriter.write_sequence(sequence: list[str]) → None
write_sequence an array to file.
Parameters
-
sequence : list[str]
-
sequence : list[str] — Sequence of values to write.
Raises
-
NotImplementedError
source class HumanOutputFormat(filename_or_file: str | TextIO, max_length: int = 36)
A human-readable output format producing ASCII tables of key-value pairs.
Set attribute max_length to change the maximum length of keys and values
to write to output (or specify it when calling __init__).
Parameters
-
filename_or_file : str | TextIO — the file to write the log to
-
max_length : int — the maximum length of keys and values to write to output. Outputs longer than this will be truncated. An error will be raised if multiple keys are truncated to the same value. The maximum output width will be
2*max_length + 7. The default of 36 produces output no longer than 79 characters wide.
Methods
-
close — Closes the file.
source method HumanOutputFormat.write(key_values: dict[str, Any], key_excluded: dict[str, tuple[str, ...] | None], step: int = 0) → None
Raises
-
ValueError
source method HumanOutputFormat.write_sequence(sequence: list[str]) → None
source method HumanOutputFormat.close() → None
Closes the file.
source filter_excluded_keys(key_values: dict[str, Any], key_excluded: dict[str, tuple[str, ...] | None], _format: str) → dict[str, Any]
Filters the keys specified by key_exclude for the specified format.
Parameters
-
key_values : dict[str, Any] — log dictionary to be filtered
-
key_excluded : dict[str, tuple[str, ...] | None] — keys to be excluded per format
-
_format : str — format for which this filter is run
Returns
-
dict[str, Any] — dict without the excluded keys
source class JSONOutputFormat(filename: str)
Bases : KVWriter
Log to a file, in the JSON format.
Parameters
-
filename : str — the file to write the log to
Methods
source method JSONOutputFormat.write(key_values: dict[str, Any], key_excluded: dict[str, tuple[str, ...] | None], step: int = 0) → None
Raises
source method JSONOutputFormat.close() → None
Closes the file.
source class CSVOutputFormat(filename: str)
Bases : KVWriter
Log to a file, in a CSV format.
Parameters
-
filename : str — the file to write the log to
Methods
source method CSVOutputFormat.write(key_values: dict[str, Any], key_excluded: dict[str, tuple[str, ...] | None], step: int = 0) → None
Raises
source method CSVOutputFormat.close() → None
Closes the file.
source class TensorBoardOutputFormat(folder: str)
Bases : KVWriter
Dumps key/value pairs into TensorBoard's numeric format.
Parameters
-
folder : str — the folder to write the log to
Methods
source method TensorBoardOutputFormat.write(key_values: dict[str, Any], key_excluded: dict[str, tuple[str, ...] | None], step: int = 0) → None
source method TensorBoardOutputFormat.close() → None
Closes the file.
source make_output_format(_format: str, log_dir: str, log_suffix: str = '') → KVWriter
Return a logger for the requested format.
Parameters
-
_format : str — the requested format to log to ('stdout', 'log', 'json' or 'csv' or 'tensorboard')
-
log_dir : str — the logging directory
-
log_suffix : str — the suffix for the log file
Returns
-
KVWriter — the logger
Raises
-
ValueError
source class Logger(folder: str | None, output_formats: list[KVWriter])
The logger class.
Parameters
-
folder : str | None — the logging location
-
output_formats : list[KVWriter] — the list of output formats
Methods
-
to_tuple — Helper function to convert str to tuple of str.
-
record — Log a value of some diagnostic.
-
record_mean — The same as record(), but if called many times, values averaged.
-
dump — Write all of the diagnostics from the current iteration.
-
log — Write the sequence of args, with no separators,.
-
debug — Write the sequence of args, with no separators,.
-
info — Write the sequence of args, with no separators,.
-
warn — Write the sequence of args, with no separators,.
-
error — Write the sequence of args, with no separators,.
-
set_level — Set logging threshold on current logger.
-
get_dir — Get directory that log files are being written to.
-
close — Closes the file.
source staticmethod Logger.to_tuple(string_or_tuple: str | tuple[str, ...] | None) → tuple[str, ...]
Helper function to convert str to tuple of str.
source method Logger.record(key: str, value: Any, exclude: str | tuple[str, ...] | None = None) → None
Log a value of some diagnostic.
Call this once for each diagnostic quantity, each iteration If called many times, last value will be used.
Parameters
-
key : str — save to log this key
-
value : Any — save to log this value
-
exclude : str | tuple[str, ...] | None — outputs to be excluded
source method Logger.record_mean(key: str, value: float | None, exclude: str | tuple[str, ...] | None = None) → None
The same as record(), but if called many times, values averaged.
Parameters
-
key : str — save to log this key
-
value : float | None — save to log this value
-
exclude : str | tuple[str, ...] | None — outputs to be excluded
source method Logger.dump(step: int = 0) → None
Write all of the diagnostics from the current iteration.
source method Logger.log(*args, level: int = INFO) → None
Write the sequence of args, with no separators,.
to the console and output files (if you've configured an output file).
level: int. (see logger.py docs) If the global logger level is higher than the level argument here, don't print to stdout.
Parameters
-
args — log the arguments
-
level : int — the logging level (can be DEBUG=10, INFO=20, WARN=30, ERROR=40, DISABLED=50)
source method Logger.debug(*args) → None
Write the sequence of args, with no separators,.
to the console and output files (if you've configured an output file). Using the DEBUG level.
Parameters
-
args — log the arguments
source method Logger.info(*args) → None
Write the sequence of args, with no separators,.
to the console and output files (if you've configured an output file). Using the INFO level.
Parameters
-
args — log the arguments
source method Logger.warn(*args) → None
Write the sequence of args, with no separators,.
to the console and output files (if you've configured an output file). Using the WARN level.
Parameters
-
args — log the arguments
source method Logger.error(*args) → None
Write the sequence of args, with no separators,.
to the console and output files (if you've configured an output file). Using the ERROR level.
Parameters
-
args — log the arguments
source method Logger.set_level(level: int) → None
Set logging threshold on current logger.
Parameters
-
level : int — the logging level (can be DEBUG=10, INFO=20, WARN=30, ERROR=40, DISABLED=50)
source method Logger.get_dir() → str | None
Get directory that log files are being written to.
will be None if there is no output directory (i.e., if you didn't call start).
Returns
-
str | None — the logging directory
source method Logger.close() → None
Closes the file.
source configure(folder: str | None = None, format_strings: list[str] | None = None) → Logger
Configure the current logger.
Parameters
-
folder : str | None — the save location (if None, $SB3_LOGDIR, if still None, tempdir/SB3-[date & time])
-
format_strings : list[str] | None — the output logging format (if None, $SB3_LOG_FORMAT, if still None, ['stdout', 'log', 'csv'])
Returns
-
Logger — The logger object.
source read_json(filename: str) → pandas.DataFrame
Read a json file using pandas.
Parameters
-
filename : str — the file path to read
Returns
-
pandas.DataFrame — the data in the json
source read_csv(filename: str) → pandas.DataFrame
Read a csv file using pandas.
Parameters
-
filename : str — the file path to read
Returns
-
pandas.DataFrame — the data in the csv