Traits

pydantic model mlopus.mlflow.MlflowApiMixin[source]

Bases: BaseModel

Mixin for pydantic classes that hold a reference to a Mlflow API instance.

The API is instantiated by the utility mlopus.mlflow.get_api() on object initialization.

Example:

class Foo(MlflowMixinApi):
    pass

foo = Foo(
    mlflow_api={"plugin": "...", "conf": {...}}  # kwargs for `mlopus.mlflow.get_api()`
)

foo.mlflow_api  # BaseMlflowApi
field mlflow_api: BaseMlflowApi = None

Instance of BaseMlflowApi or a dict of keyword arguments for mlopus.mlflow.get_api().

using(mlflow_api)[source]

Get a copy of this object that uses the specified MLflow API.

Return type:

MlflowApiMixin

pydantic model mlopus.mlflow.MlflowRunMixin[source]

Bases: BaseModel

Mixin for pydantic classes that hold a reference to a MlflowRunManager.

field run_manager: Optional[MlflowRunManager] [Required] (alias 'mlflow')

Instance or dict to be parsed into instance of MlflowRunManager

pydantic model mlopus.mlflow.MlflowRunManager[source]

Bases: MlflowApiMixin

A pydantic object that holds a reference to an ongoing MLflow Run.

  1. If run.id is given, that run is resumed.

  2. Otherwise, an ongoing run is searched for in exp.name containing run.tags

  3. If none can be found, a new run is started in exp.name containing run.tags

Example:

config = {
    "api": {...},  # kwargs for `mlopus.mlflow.get_api()`
    "exp": {"name": ...},
    "run": {"name": ..., "tags": ..., "id": ...},
}

foo_1 = MlflowRunManager(**config)
foo_2 = MlflowRunManager(**config)

# Objects with same config share the same managed run
assert foo_1.run.id == foo_2.run.id

# Accessing the cached property `run` triggers the resume/search/creation of the run.
field exp: ExpConf [Optional]

Experiment specification (created if doesn’t exist). Used to find or create the run.

field mlflow_api: BaseMlflowApi [Required] (alias 'api')

Instance of BaseMlflowApi or a dict of keyword arguments for mlopus.mlflow.get_api().

field run_conf: RunConf [Optional] (alias 'run')

Run specification, used for resuming, finding or creating the run.

property run: RunApi

API handle for the ongoing MLflow Run.