mml.core.scripts.utils

class LearningPhase[source]

Bases: StrEnum

An enumeration.

TEST = 'test'
TRAIN = 'train'
VAL = 'val'
__new__(value)
static all_phases() List[LearningPhase][source]
class Singleton[source]

Bases: object

The actual Singleton class to inherit from. Make sure to have Singleton as the leftmost base class.

classmethod clear_instance() None[source]

Clears the cached instance of the singleton. Be aware, that this does not affect references to the “old” instance, but any further call of “instance” or Class() will create a new instance, that will be returned from any further call.

Returns:

classmethod exists() bool[source]
classmethod instance(*args: Any, **kwargs: Any) TSingleton[source]

Convenience function that does the same as Class(), but makes the singleton property more readable in code.

Parameters:
  • args – any init args, be aware that these are ignored if there already exists an instance

  • kwargs – any init kwargs, be aware that these are ignored if there already exists an instance

Returns:

either a new instance (first call) or a reference to the already existing instance

ask_confirmation(message: str = '') bool[source]

Lets user confirm a message.

Parameters:

message – The message to be confirmed

Returns:

bool indicating whether the message has been confirmed

Return type:

bool

class catch_time[source]

Bases: object

Timing utility context manager. Usage:

access time via timer.pretty_time afterward, e.g. for logging.

load_env() None[source]

Loads the mml.env variables. Make sure to have renamed and adapted example.env beforehand. If an environment variable MML_ENV_PATH is given this file is preferred, else the default path inside the mml package is used.

Returns:

None

load_mml_plugins() None[source]

This function allows to load mml plugins. These are other installed packages that provide a ‘mml.plugins’ entry point. See https://packaging.python.org/en/latest/guides/creating-and-discovering-plugins/#using-package-metadata for details on this mechanism.

class multi_threaded_p_tqdm[source]

Bases: object

Switches the internally used pool type of p_tqdm package from ProcessPool to ThreadPool.

class throttle_logging[source]

Bases: object

Logging utility context manager. Usage:

afterwards logging continues as before. The context manager checks if the root logger is in DEBUG mode and prevents throttling in that case.

__init__(level: int = 20, package: str | None = None)[source]