Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# misc
.ruff_cache
.DS_Store
.vscode

Expand Down
13 changes: 13 additions & 0 deletions demos/kubeflow-pipelines/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ML Pipeline Orchestration with Kubeflow Pipelines

[Kubeflow Pipelines (KFP)](https://kubeflow-pipelines.readthedocs.io) is a ...

This demo shows ..

## Demo Objectives

* TODO...

## Running the Demo

This demo is contained...
51 changes: 51 additions & 0 deletions demos/kubeflow-pipelines/components.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Patterrns for developing reusable KFP pipeline components."""
import shutil
from pathlib import Path
from unittest.mock import Mock

import numpy as np
from kfp import dsl, local

_BASE_IMAGE = "python3.10"
_REQUIREMENTS = Path("requirements.txt").read_text().splitlines()


@dsl.component(base_image=_BASE_IMAGE, packages_to_install=_REQUIREMENTS)
def make_data(n_rows: int, n_cols: int, data: dsl.Output[dsl.Dataset]) -> None:
"""Synthetic dataset generation pipeline component. """
from numpy import save
from numpy.random import default_rng

rng = default_rng(42)
data_arr = rng.standard_normal((n_rows, n_cols))
save(data.path, data_arr)


def test_make_data_component():
output_dataset_file = "foo.npy"
mock_dataset = Mock()
mock_dataset.path = output_dataset_file
try:
make_data.execute(n_rows=3, n_cols=2, data=mock_dataset)
output_dataset = np.load(output_dataset_file)
assert output_dataset.shape == (3, 2)
except Exception:
assert False
finally:
data_filepath = Path(output_dataset_file)
if data_filepath.exists():
data_filepath.unlink()


def test_make_data_component_integration():
kfp_root_dir = "./kfp_outputs"
local.init(runner=local.SubprocessRunner(use_venv=True), pipeline_root=kfp_root_dir)
try:
task = make_data(n_rows=3, n_cols=2)
output_dataset = np.load(f"{task.outputs['data'].path}.npy")
assert output_dataset.shape == (3, 2)
except Exception:
assert False
finally:
shutil.rmtree(kfp_root_dir, ignore_errors=True)

7 changes: 7 additions & 0 deletions demos/kubeflow-pipelines/docs/demo_requirements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Demo Requirements

This demo depends on the following Python packages:

```text title="demos/kubeflow-pipelines/requirements.txt"
--8<-- "demos/kubeflow-pipelines/requirements.txt"
```
3 changes: 3 additions & 0 deletions demos/kubeflow-pipelines/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kfp==2.5.*
numpy==1.26.*
pytest==8.0.*