hive.utils.loggers module
- class hive.utils.loggers.Logger(timescales=None)[source]
Bases:
ABC
,Registrable
Abstract class for logging in hive.
Constructor for base Logger class. Every Logger must call this constructor in its own constructor
- Parameters
timescales (str | list(str)) – The different timescales at which logger needs to log. If only logging at one timescale, it is acceptable to only pass a string.
- register_timescale(timescale)[source]
Register a new timescale with the logger.
- Parameters
timescale (str) – Timescale to register.
- abstract save(dir_name)[source]
Saves the current state of the log files.
- Parameters
dir_name (str) – Name of the directory to save the log files.
- class hive.utils.loggers.ScheduledLogger(timescales=None, logger_schedules=None)[source]
Bases:
Logger
Abstract class that manages a schedule for logging.
The update_step method should be called for each step in the loop to update the logger’s schedule. The should_log method can be used to check whether the logger should log anything.
This schedule is not strictly enforced! It is still possible to log something even if should_log returns false. These functions are just for the purpose of convenience.
Any timescales not assigned schedule from logger_schedules will be assigned a ConstantSchedule(True).
- Parameters
timescales (str|list[str]) – The different timescales at which logger needs to log. If only logging at one timescale, it is acceptable to only pass a string.
logger_schedules (Schedule|list|dict) – Schedules used to keep track of when to log. If a single schedule, it is copied for each timescale. If a list of schedules, the schedules are matched up in order with the list of timescales provided. If a dictionary, the keys should be the timescale and the values should be the schedule.
- update_step(timescale)[source]
Update the step and schedule for a given timescale.
- Parameters
timescale (str) – A registered timescale.
- should_log(timescale)[source]
Check if you should log for a given timescale.
- Parameters
timescale (str) – A registered timescale.
- class hive.utils.loggers.NullLogger(timescales=None, logger_schedules=None)[source]
Bases:
ScheduledLogger
A null logger that does not log anything.
Used if you don’t want to log anything, but still want to use parts of the framework that ask for a logger.
Any timescales not assigned schedule from logger_schedules will be assigned a ConstantSchedule(True).
- Parameters
timescales (str|list[str]) – The different timescales at which logger needs to log. If only logging at one timescale, it is acceptable to only pass a string.
logger_schedules (Schedule|list|dict) – Schedules used to keep track of when to log. If a single schedule, it is copied for each timescale. If a list of schedules, the schedules are matched up in order with the list of timescales provided. If a dictionary, the keys should be the timescale and the values should be the schedule.
- class hive.utils.loggers.WandbLogger(timescales=None, logger_schedules=None, project=None, name=None, dir=None, mode=None, id=None, resume=None, start_method=None, **kwargs)[source]
Bases:
ScheduledLogger
A Wandb logger.
This logger can be used to log to wandb. It assumes that wandb is configured locally on your system. Multiple timescales/loggers can be implemented by instantiating multiple loggers with different logger_names. These should still have the same project and run names.
Check the wandb documentation for more details on the parameters.
- Parameters
timescales (str|list[str]) – The different timescales at which logger needs to log. If only logging at one timescale, it is acceptable to only pass a string.
logger_schedules (Schedule|list|dict) – Schedules used to keep track of when to log. If a single schedule, it is copied for each timescale. If a list of schedules, the schedules are matched up in order with the list of timescales provided. If a dictionary, the keys should be the timescale and the values should be the schedule.
project (str) – Name of the project. Wandb’s dash groups all runs with the same project name together.
name (str) – Name of the run. Used to identify the run on the wandb dash.
dir (str) – Local directory where wandb saves logs.
mode (str) – The mode of logging. Can be “online”, “offline” or “disabled”. In offline mode, writes all data to disk for later syncing to a server, while in disabled mode, it makes all calls to wandb api’s noop’s, while maintaining core functionality.
id (str, optional) – A unique ID for this run, used for resuming. It must be unique in the project, and if you delete a run you can’t reuse the ID.
resume (bool, str, optional) – Sets the resuming behavior. Options are the same as mentioned in Wandb’s doc.
start_method (str) – The start method to use for wandb’s process. See https://docs.wandb.ai/guides/track/launch#init-start-error.
**kwargs – You can pass any other arguments to wandb’s init method as keyword arguments. Note, these arguments can’t be overriden from the command line.
- class hive.utils.loggers.ChompLogger(timescales=None, logger_schedules=None)[source]
Bases:
ScheduledLogger
This logger uses the Chomp data structure to store all logged values which are then directly saved to disk.
Any timescales not assigned schedule from logger_schedules will be assigned a ConstantSchedule(True).
- Parameters
timescales (str|list[str]) – The different timescales at which logger needs to log. If only logging at one timescale, it is acceptable to only pass a string.
logger_schedules (Schedule|list|dict) – Schedules used to keep track of when to log. If a single schedule, it is copied for each timescale. If a list of schedules, the schedules are matched up in order with the list of timescales provided. If a dictionary, the keys should be the timescale and the values should be the schedule.
- class hive.utils.loggers.CompositeLogger(logger_list)[source]
Bases:
Logger
This Logger aggregates multiple loggers together.
This logger is for convenience and allows for logging using multiple loggers without having to keep track of several loggers. When timescales are updated, this logger updates the timescale for each one of its component loggers. When logging, logs to each of its component loggers as long as the logger is not a ScheduledLogger that should not be logging for the timescale.
Constructor for base Logger class. Every Logger must call this constructor in its own constructor
- Parameters
timescales (str | list(str)) – The different timescales at which logger needs to log. If only logging at one timescale, it is acceptable to only pass a string.
- register_timescale(timescale, schedule=None)[source]
Register a new timescale with the logger.
- Parameters
timescale (str) – Timescale to register.
- update_step(timescale)[source]
Update the step and schedule for a given timescale for every ScheduledLogger.
- Parameters
timescale (str) – A registered timescale.
- should_log(timescale)[source]
Check if you should log for a given timescale. If any logger in the list is scheduled to log, returns True.
- Parameters
timescale (str) – A registered timescale.