scaffold.ctx_manager
Attributes
Classes
Context manager for configuring the logging system. |
|
An abstract base class for context managers. |
|
Context manager for configuring wandb, starting and exiting a wandb run. |
Functions
|
Combine multiple context managers into a stack, since contexts should be exited in reverse order |
Module Contents
- class scaffold.ctx_manager.LoggingContext(log_config: omegaconf.DictConfig = DEFAULT_CONFIGURATION, verbose: bool | str | Sequence[str] = False)
Bases:
contextlib.AbstractContextManagerContext manager for configuring the logging system. It wraps the hydra’s logging configuration and allows to specify verbosity level per module, see hydra documentation for more details: https://hydra.cc/docs/tutorials/basic/running_your_app/logging/
Example usage:
cfg = LoggingContext.DEFAULT_CONFIGURATION with LoggingContext(cfg) as log_context: logging.info("This message should be logged with the specified configuration.") logging.info("This error should be logged with default configuration.")
Initialize the configuration of the logging context.
- __enter__()
Configure the logging system with the specified settings on entering the context.
- __exit__(exc_type, exc_val, exc_tb)
Exit the context (and ideally restore previous logging configuration).
- DEFAULT_CONFIGURATION: omegaconf.DictConfig
- SILENT_CONFIGURATION: omegaconf.DictConfig
- log_config
- verbose = False
- class scaffold.ctx_manager.TimerContext(module_name: str = None)
Bases:
contextlib.AbstractContextManagerAn abstract base class for context managers.
Initialize the timer context manager.
- Parameters:
module_name (str) – Optional name of the module to be displayed in the log message.
- __enter__()
Enter the timer context and start the timer
- __exit__(exc_type, exc_val, exc_tb)
Exit the timer context and log the time taken for execution
- module_name = None
- start_time = None
- class scaffold.ctx_manager.WandBContext(user: str | None = None, base_url: str = None, entity: str = 'mxm', run_id: str | None = None, resume: bool = False, run_config: omegaconf.DictConfig | None = None, **kwargs)
Bases:
contextlib.AbstractContextManagerContext manager for configuring wandb, starting and exiting a wandb run.
Example usage:
with WandBContext(project="chameleon", entity="mg515") as wandb_ctx: # Do something with the WandB context wandb.log({"metric": 0.5})
WandB Context that connects to our WandB instance, creates a WandB run and logs config to WandB instance.
- Parameters:
user – Optional cloud username to retrieve wandb login secrets. See Also:
scaffold.wandb.helpers.wandb_environment_setup()base_url – Base URL of WandB instance.
entity – Name of the WandB entity.
run_id – Flyte or WandB run ID.
resume – Whether to resume previous run specified by run_id.
run_config – Config passed to wandb init.
**kwargs – Additional kwargs passed to wandb init. See https://docs.wandb.ai/ref/python/init.
- __enter__()
Enters the context manager and starts a new WandB run.
- __exit__(exc_type: type | None, exc_val: Exception | None, exc_tb: Any | None) bool | None
Raise any exception triggered within the runtime context.
- entity = 'mxm'
- kwargs
- run = None
- run_config
- run_id
- scaffold.ctx_manager.combined_context(*contexts: List[contextlib.AbstractContextManager])
Combine multiple context managers into a stack, since contexts should be exited in reverse order in which they are entered. If an exception occurred, this order matters, as any context manager could suppress the exception, at which point the remaining managers will not even get notified
Example use case:
with combined_context(LoggingContext(), WandBContext()) as (logger, wandb): ...
- scaffold.ctx_manager.DEFAULT_LOGGING: dict
- scaffold.ctx_manager.DISABLED_LOGGING: dict
- scaffold.ctx_manager.NONE_LOGGING: dict
- scaffold.ctx_manager.STDOUT_AND_LOGFILE_LOGGING: dict
- scaffold.ctx_manager.STDOUT_LOGGING: dict
- scaffold.ctx_manager.logger