malet.utils#
Exceptions#
Common base class for all non-exit exceptions. |
Classes#
A base class or mixin that enables context managers to work as decorators. |
Functions#
|
Creates a directory at the specified path. If the directory already exists, |
|
Convert a number to engineering notation with a specified precision. |
|
|
|
|
|
Casts string back to standard python types |
|
Add new metrics to metric_log |
|
Raise an Exception in the Thread with id tid. Perform cleanup if |
|
|
|
Decomposes a list of paths into a common prefix and remaining suffixes. |
|
Constructs the experiment directory path for a W&B sweep. |
Module Contents#
- malet.utils.create_dir(dir, overwrite=False)[source]#
Creates a directory at the specified path. If the directory already exists, it can optionally overwrite its contents.
- Parameters:
dir (str) – The path of the directory to create.
overwrite (bool, optional) – If True and the directory exists, all its contents will be removed. Defaults to False.
- malet.utils.to_eng_str(num, long_than=4, precision=3)[source]#
Convert a number to engineering notation with a specified precision.
- Parameters:
num (float) – The number to convert.
long_than (int, optional) – The minimum length of the number string. Defaults to 4.
precision (int, optional) – The number of decimal places to include. Defaults to 3.
- Returns:
The number in engineering notation.
- Return type:
str
- malet.utils.df2richtable(df, title=None, max_row_len=None, highlight_columns: list | None = None, max_col_width=None, col_center=None, max_seq_value_len=None, list_centers: dict | None = None, highlight_list_centers=False, alternating_row_colors=False, use_eng_str=False)[source]#
- class malet.utils.QueuedFileLock(lock_file: str, timeout: float = 10)[source]#
Bases:
contextlib.ContextDecoratorA base class or mixin that enables context managers to work as decorators.
- lock_file#
- timeout = 10#
- id = 0#
- acquire_count = 0#
- property is_locked#
- exception malet.utils.FuncTimeoutError[source]#
Bases:
ExceptionCommon base class for all non-exit exceptions.
- malet.utils.async_raise(tid, exctype=Exception)[source]#
Raise an Exception in the Thread with id tid. Perform cleanup if needed. Based on Killable Threads By Tomer Filiba from http://tomerfiliba.com/recipes/Thread2/ license: public domain.
- malet.utils.path_common_decomposition(paths)[source]#
Decomposes a list of paths into a common prefix and remaining suffixes.
- Parameters:
paths – List of file/directory path strings.
- Returns:
- A pair of (common_prefix, non_common_suffixes) where
common_prefix is a list of shared path components and non_common_suffixes is a list of remaining path strings.
- Return type:
tuple
- malet.utils.get_wandb_sweep_exp_dir(base_dir, entity, project, sweep_id)[source]#
Constructs the experiment directory path for a W&B sweep.
- Parameters:
base_dir – Base directory for experiment storage.
entity – W&B entity name (unused in path construction).
project – W&B project name.
sweep_id – W&B sweep identifier.
- Returns:
Path in the form
base_dir/project/sweep_id.- Return type:
str