logger_base#
Source code: tianshou/utils/logger/logger_base.py
- class DataScope(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
StrEnum- TRAINING = 'training'#
- TEST = 'test'#
- UPDATE = 'update'#
- INFO = 'info'#
- class BaseLogger(training_interval: int = 1000, test_interval: int = 1, update_interval: int = 1000, info_interval: int = 1, save_interval: int | None = None, exclude_arrays: bool = True)[source]#
Bases:
ABCThe base class for any logger which is compatible with trainer.
- Parameters:
training_interval – the interval size (in env steps) after which log_training_data() will be called.
test_interval – the interval size (in env steps) after which log_test_data() will be called.
update_interval – the interval size (in env steps) after which log_update_data() will be called.
info_interval – the interval size (in env steps) after which the method log_info() will be called.
save_interval – the interval size (in env steps) after which the checkpoint and end of epoch related logs will be saved.
- abstract write(step_type: str, step: int, data: dict[str, int | Number | number | ndarray | float]) None[source]#
Specify how the writer is used to log data.
- Parameters:
step_type (str) – namespace which the data dict belongs to.
step – stands for the ordinate of the data dict.
data – the data to write with format
{key: value}.
- abstract prepare_dict_for_logging(log_data: dict) dict[str, int | Number | number | ndarray | float][source]#
Prepare the dict for logging by filtering out invalid data types.
If necessary, reformulate the dict to be compatible with the writer.
- Parameters:
log_data – the dict to be prepared for logging.
- Returns:
the prepared dict.
- log_training_data(log_data: dict, step: int) None[source]#
Use writer to log statistics generated during training.
- Parameters:
log_data – a dict containing the information returned by the collector during the train step.
step – stands for the timestep the collector result is logged.
- log_test_data(log_data: dict, step: int) None[source]#
Use writer to log statistics generated during evaluating.
:param log_data:a dict containing the information returned by the collector during the evaluation step. :param step: stands for the timestep the collector result is logged.
- log_update_data(log_data: dict, step: int) None[source]#
Use writer to log statistics generated during updating.
:param log_data:a dict containing the information returned during the policy update step. :param step: stands for the timestep the policy training data is logged.
- log_info_data(log_data: dict, step: int) None[source]#
Use writer to log global statistics.
- Parameters:
log_data – a dict containing information of data collected at the end of an epoch.
step – stands for the timestep the training info is logged.
- abstract save_data(epoch: int, env_step: int, update_step: int, save_checkpoint_fn: Callable[[int, int, int], str] | None = None) None[source]#
Use writer to log metadata when calling
save_checkpoint_fnin trainer.- Parameters:
epoch – the epoch in trainer.
env_step – the env_step in trainer.
update_step – the update step count in the trainer.
save_checkpoint_fn (function) – a hook defined by user, see trainer documentation for detail.
- abstract restore_data() tuple[int, int, int][source]#
Restore internal data if present and return the metadata from existing log for continuation of training.
If it finds nothing or an error occurs during the recover process, it will return the default parameters.
- Returns:
epoch, env_step, update_step.
- class LazyLogger[source]#
Bases:
BaseLoggerA logger that does nothing. Used as the placeholder in trainer.
- prepare_dict_for_logging(data: dict[str, int | Number | number | ndarray | float]) dict[str, int | Number | number | ndarray | float][source]#
Prepare the dict for logging by filtering out invalid data types.
If necessary, reformulate the dict to be compatible with the writer.
- Parameters:
log_data – the dict to be prepared for logging.
- Returns:
the prepared dict.
- write(step_type: str, step: int, data: dict[str, int | Number | number | ndarray | float]) None[source]#
The LazyLogger writes nothing.
- save_data(epoch: int, env_step: int, update_step: int, save_checkpoint_fn: Callable[[int, int, int], str] | None = None) None[source]#
Use writer to log metadata when calling
save_checkpoint_fnin trainer.- Parameters:
epoch – the epoch in trainer.
env_step – the env_step in trainer.
update_step – the update step count in the trainer.
save_checkpoint_fn (function) – a hook defined by user, see trainer documentation for detail.