Session

class mlopus.kedro.MlopusKedroSession(session_id, package_name=None, project_path=None, save_on_close=False, conf_source=None)[source]

Bases: KedroSession

Patch of KedroSession.

Enabling the patch

# <your_package>/settings.py
from mlopus.kedro import MlopusKedroSession
from kedro.framework.session import KedroSession

KedroSession.create = MlopusKedroSession.create

Resolving env vars and session store details in config files

# conf/<env>/parameters.yml
my_env_var: "${env:MY_ENV_VAR,default}"  # resolve env var
package_version: "${session:pkg.version}"  # resolve session store details

Lazy-evaluated pipelines with direct config access

In the following example, the function prepare_images will be called to build the pipeline from the config only when the respective pipeline is chosen for execution.

If the node function SetImageContrast is a Pydantic BaseModel or has any other form of schema validation, the mapped configuration will be validated before the pipeline runs.

# <your_package>/pipeline_registry.py
from mlopus.kedro import pipeline_factory

def register_pipelines():
    return {"e2e": prepare_images}

@pipeline_factory
def prepare_images(config):
    return Pipeline([
        node(
            name="set_contrast",
            inputs="original_images",
            outputs="modified_images",
            func=SetImageContrast(config["parameters"]["contrast"]),
        ),
    ])

Lazy-evaluated hooks with direct config access

# <your_package>/settings.py
from mlopus.kedro import hook_factory

@hook_factory
def upload_logs(config):
    return UploadLogs(bucket=config["globals"]["logs_bucket"])

HOOKS = [upload_logs]