logml.common

Functions

catch_exception(exception_class)

Wrapper for class methods.

check_random_state(random_state, global_config)

Checks that random state exists or generated from main state.

get_method(method_name, cls_dict, cls_bases, ...)

Lookup utility that helps to find methods by name within inheritance chains.

import_submodules(module[, level, modules_only])

Import all submodules of a module, recursively.

Classes

BaseEligibleRegistrator(*args, **kwargs)

Provides registry functionality for different classes.

BaseRunner(cfg, global_params[, logger])

Wraps execution of a portion of logml pipeline for STRATUM/PROBLEM pair.

ModelingTask(value)

Defines supported modeling tasks.

OutputStructure(global_params[, strata_id, ...])

Defines LogML output structure.

RandomGen([seed, a, b])

Singleton

Simple singleton class.

StrEnum(value)

An enumeration.

logml.common.import_submodules(module: module, level: int = 1, modules_only: bool = True) List[str]

Import all submodules of a module, recursively.

Parameters
  • modules_only – If set to True, only modules are imported. If False, packages are imported as well.

  • module – Module/package which sub-modules should be imported.

  • level

    Limit import depth. Set to zero or negative to import all level. For example the following structure is present: .. code-block:

    module_a        # root package
        a1
        a2
        tests       # package
            t1
            t2
    

    After import_submodules(module_a, level=1), only a1 and a2 would be imported. If you set level to 2, then a1, a2, t1, t2 are imported. If additionally modules_only is set to False, then also module_a.tests package is imported as well.

Returns

List of actually imported sub-modules.

logml.common.get_method(method_name, cls_dict, cls_bases, entity_name)

Lookup utility that helps to find methods by name within inheritance chains.

class logml.common.StrEnum(value)

Bases: str, enum.Enum

An enumeration.

logml.common.catch_exception(exception_class: Union[Exception, Type[Exception]])

Wrapper for class methods. Catches raised exceptions and wraps them into a given exception_class.

class logml.common.ModelingTask(value)

Bases: str, enum.Enum

Defines supported modeling tasks.

CLF = 'classification'
REG = 'regression'
SURV = 'survival'
class logml.common.Singleton

Bases: type

Simple singleton class.

class logml.common.BaseEligibleRegistrator(*args, **kwargs)

Bases: object

Provides registry functionality for different classes.

LABEL_ATTRIBUTE = 'LABEL'
classmethod register(class_f)

Registers a given class by its LABEL property.

get(entity_id: str)

Returns an entity by its id.

contains(entity_id: str) bool

Checks whether a given entity is registered.

select_unknown_entities(entities: List[str]) List[str]

For a given list of entities returns all unrecognized entities.

list_items() List[Tuple[str, Type]]

Returns a list of registered items (label + object).

list_labels() List[str]

Returns a list of registered labels.

list_values() List[object]

Returns a list of registered objects.

query(flt: Callable[[str, Type], bool]) List[str]

Filters list of registered items according to callable. filter signature is f(label, model_class) -> bool Return list of labels matching filter.

class logml.common.OutputStructure(global_params: dict, strata_id: str = '', setup_id: str = '', reset=False)

Bases: object

Defines LogML output structure.

LOGS: str = 'logs'
ANALYSIS_MD: str = 'analysis_metadata'
property root_path: pathlib.Path

Returns root folder for the experiment.

get_target_subfolder(*args) pathlib.Path

Composes a target artifacts subfolder and makes sure it exists.

class logml.common.BaseRunner(cfg, global_params: dict, logger: Optional[logging.Logger] = None)

Bases: object

Wraps execution of a portion of logml pipeline for STRATUM/PROBLEM pair.

run()

Interface method.

class logml.common.RandomGen(seed=None, a=None, b=None)

Bases: object

randint(a=None, b=None) int
logml.common.check_random_state(random_state, global_config)

Checks that random state exists or generated from main state.