plkit.utils
Utility functions for plkit
capture_stderr()— Capture the stderr</>capture_stdout()— Capture the stdout</>check_config(config,item,how,msg)— Check configuration items</>collapse_suggest_config(config)(dict) — Use the default value of OptunaSuggest for config items. So that the configs can be used in the case that optuna is opted out.</>log_config(config,title,items_per_row)— Log the configurations in a table in terminal</>normalize_tvt_ratio(tvt_ratio)(int or float, list of int or float, list of int or float), optional — Normalize the train-val-test data ratio into a format of (.7, [.1, .1], [.05, .05]).</>output_to_logging(stdout_level,stderr_level)— Capture the stdout or stderr to logging</>plkit_seed_everything(config)— Try to seed everything and set deterministic to True if seed in config has been set</>warning_to_logging()— Patch the warning message formatting to only show the message</>
plkit.utils.check_config(config, item, how=<function <lambda> at 0x7f7e732ea040>, msg='Configuration item {key} is required.')
Check configuration items
config(dict) — The configuration dictionaryitem(str) — The configuration key to checkhow(callable) — How to check. Return False to fail the check.msg(str) — The message to show in the exception.{key}is available to refer to the key checked.
PlkitConfigException— When the check fails
plkit.utils.collapse_suggest_config(config)
Use the default value of OptunaSuggest for config items. So that the configs can be used in the case that optuna is opted out.
config(dict) — The configuration dictionary
The collapsed configuration
plkit.utils.normalize_tvt_ratio(tvt_ratio)
Normalize the train-val-test data ratio into a format of (.7, [.1, .1], [.05, .05]).
For config.data_tvt, the first element is required. If val or test ratios
are not provided, it will be filled with None
All numbers could be absolute numbers (>1) or ratios (<=1)
tvt_ratio(Union(int, float, iterable of int or float, nonetype)) — The train-val-test ratio
The normalized ratios
PlkitConfigException— When the passed-in tvt_ratio is in malformat
plkit.utils.warning_to_logging()
Patch the warning message formatting to only show the message
plkit.utils.capture_stdout()
Capture the stdout
plkit.utils.capture_stderr()
Capture the stderr
plkit.utils.output_to_logging(stdout_level='info', stderr_level='error')
Capture the stdout or stderr to logging
plkit.utils.log_config(config, title='Configurations', items_per_row=1)
Log the configurations in a table in terminal
config(dict) — The configuration dictionarytitle(str) — The title of the tableitems_per_row(int) — The number of items to print per row
plkit.utils.plkit_seed_everything(config)
Try to seed everything and set deterministic to True if seed in config has been set
config(FrozenDiot) — The configurations