Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow for mlflow added #74

Closed
wants to merge 4 commits into from
Closed
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
8 changes: 6 additions & 2 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install --upgrade --upgrade-strategy eager -r dev-requirements.txt -e .
- name: Test with pytest
- name: Unit test with pytest
run: |
pytest sklearn_genetic/ --verbose --color=yes --assert=plain --cov-fail-under=95 --cov-config=.coveragerc --cov=./ -p no:warnings
pytest sklearn_genetic/tests/unit --verbose --color=yes --assert=plain --cov-fail-under=89 --cov-config=.coveragerc --cov=./ -p no:warnings
- name: MLflow test with pytest
if: matrix.os == 'ubuntu-latest'
run: |
pytest sklearn_genetic/tests/mlflow --verbose --color=yes --assert=plain --cov-fail-under=6 --cov-config=.coveragerc --cov=./ -p no:warnings
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v1
with:
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ numpydoc
nbsphinx
tensorflow>=2.0.0
tqdm>=4.61.1
testcontainers
7 changes: 7 additions & 0 deletions sklearn_genetic/tests/mlflow/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.9-slim-bullseye

RUN pip install --no-cache mlflow psycopg2-binary

EXPOSE 5000

CMD ["mlflow", "ui", "--host", "0.0.0.0", "--backend-store-uri", "postgresql+psycopg2://postgres@postgres:5432/mlflow", "--default-artifact-root", "./mlruns"]
Empty file.
20 changes: 20 additions & 0 deletions sklearn_genetic/tests/mlflow/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os
import pytest
import mlflow
import logging
from testcontainers.compose import DockerCompose


@pytest.fixture(scope="module", autouse=True)
def setup_mlflow():
path = os.path.abspath(os.path.dirname(__file__))
with DockerCompose(
path, compose_file_name=["docker-compose.yml"], pull=True
) as compose:
host = compose.get_service_host("mlflow", 5000)
if host == "0.0.0.0":
host = "localhost"
port = compose.get_service_port("mlflow", 5000)
logging.info(f"MLflow started @http://{host}:{port}")
mlflow.set_tracking_uri(f"http://{host}:{port}")
yield
19 changes: 19 additions & 0 deletions sklearn_genetic/tests/mlflow/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3'

services:
mlflow:
build:
context: ""
dockerfile: Dockerfile
ports:
- "5000"
depends_on:
- postgres

postgres:
image: postgres:13.1-alpine
environment:
POSTGRES_DB: mlflow
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import pytest
import shutil
import os
import requests

import mlflow
from mlflow.tracking import MlflowClient
from mlflow.entities import ViewType
from sklearn.datasets import load_digits
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.model_selection import StratifiedKFold

from ..genetic_search import GASearchCV
Expand Down Expand Up @@ -141,11 +139,3 @@ def test_mlflow_after_run(mlflow_resources, mlflow_run):
assert 2 <= int(params["max_depth"]) <= 20
assert 2 <= int(params["max_leaf_nodes"]) <= 30
assert client.get_metric_history(run_id, "score")[0].key == "score"


def test_cleanup():
"""
Ensure resources are cleaned up.
"""
shutil.rmtree("mlruns")
assert "mlruns" not in os.listdir(os.getcwd())
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
from sklearn.tree import DecisionTreeRegressor

from .. import GASearchCV
from ..plots import plot_fitness_evolution, plot_search_space, plot_parallel_coordinates
from ..plots import (
plot_fitness_evolution,
plot_search_space,
plot_parallel_coordinates,
)
from ..space import Integer, Categorical, Continuous


Expand Down