malet.utils#

Exceptions#

FuncTimeoutError

Common base class for all non-exit exceptions.

Classes#

QueuedFileLock

A base class or mixin that enables context managers to work as decorators.

Functions#

create_dir(dir[, overwrite])

Creates a directory at the specified path. If the directory already exists,

to_eng_str(num[, long_than, precision])

Convert a number to engineering notation with a specified precision.

df2richtable(df[, title, max_row_len, ...])

list2tuple(l)

str2value(value_str)

Casts string back to standard python types

append_metrics([metric_log])

Add new metrics to metric_log

async_raise(tid[, exctype])

Raise an Exception in the Thread with id tid. Perform cleanup if

settimeout_func(func[, timeout])

path_common_decomposition(paths)

Decomposes a list of paths into a common prefix and remaining suffixes.

get_wandb_sweep_exp_dir(base_dir, entity, project, ...)

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]#
malet.utils.list2tuple(l)[source]#
malet.utils.str2value(value_str)[source]#

Casts string back to standard python types

malet.utils.append_metrics(metric_log=None, **new_metrics)[source]#

Add new metrics to metric_log

class malet.utils.QueuedFileLock(lock_file: str, timeout: float = 10)[source]#

Bases: contextlib.ContextDecorator

A base class or mixin that enables context managers to work as decorators.

lock_file#
timeout = 10#
id = 0#
acquire_count = 0#
property is_locked#
acquire(timeout: float | None = None, poll_interval: float = 0.05)[source]#
release(force=False)[source]#
exception malet.utils.FuncTimeoutError[source]#

Bases: Exception

Common 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.settimeout_func(func, timeout=3 * 24 * 60 * 60)[source]#
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