Subject: [PATCH 21/21] gnu: Add mlflow.

From: Marius Bakke <[email-masked]>
Date: Fri, 30 Aug 2019 16:25:39 +0200

* gnu/packages/machine-learning.scm (mlflow): New public variable.
---
 gnu/packages/machine-learning.scm | 122 +++++++++++++++++++++++++++++-
 1 file changed, 121 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm
index e48c91a2cf..19b1c7482b 100644
--- a/gnu/packages/machine-learning.scm
+++ b/gnu/packages/machine-learning.scm
@@ -1,7 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2015, 2016, 2017, 2018, 2019 Ricardo Wurmus <[email-masked]>
 ;;; Copyright © 2016 Efraim Flashner <[email-masked]>
-;;; Copyright © 2016, 2017 Marius Bakke <[email-masked]>
+;;; Copyright © 2016, 2017, 2019 Marius Bakke <[email-masked]>
 ;;; Copyright © 2016 Hartmut Goebel <[email-masked]>
 ;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <[email-masked]>
 ;;; Copyright © 2018 Kei Kebreau <[email-masked]>
@@ -52,6 +52,7 @@
   #:use-module (gnu packages cran)
   #:use-module (gnu packages databases)
   #:use-module (gnu packages dejagnu)
+  #:use-module (gnu packages docker)
   #:use-module (gnu packages gcc)
   #:use-module (gnu packages glib)
   #:use-module (gnu packages graphviz)
@@ -73,7 +74,9 @@
   #:use-module (gnu packages statistics)
   #:use-module (gnu packages sqlite)
   #:use-module (gnu packages swig)
+  #:use-module (gnu packages time)
   #:use-module (gnu packages tls)
+  #:use-module (gnu packages version-control)
   #:use-module (gnu packages web)
   #:use-module (gnu packages xml)
   #:use-module (gnu packages xorg)
@@ -354,6 +357,123 @@ networks) based on simulation of (stochastic) flow in graphs.")
 algorithm.")
     (license license:gpl3)))
 
+(define-public mlflow
+  (package
+    (name "mlflow")
+    (version "1.2.0")
+    (source (origin
+              ;; The PyPI release lacks tests, so we take the git repository.
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/mlflow/mlflow")
+                    (commit (string-append "v" version))))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "0rn3anjkm0i6phyvh7xsrvxbhqp5dhvqf74kaa69q5hgy4y2y0py"))))
+    (build-system python-build-system)
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-before 'check 'adjust-tests
+           (lambda _
+             ;; TODO: It would be great to disable the individual test cases
+             ;; instead of deleting whole files, e.g. with
+             ;; (setenv "PYTEST_ADDOPTS" "-k not foo and not bar").
+             (for-each delete-file
+                       '(;; These tests require packages not yet available
+                         ;; in Guix.
+                         "tests/azureml/test_image_creation.py"
+                         "tests/h2o/test_h2o_model_export.py"
+                         "tests/onnx/test_onnx_model_export.py"
+                         "tests/projects/test_docker_projects.py"
+                         "tests/projects/test_kubernetes.py"
+                         "tests/projects/test_projects.py"
+                         "tests/pyfunc/test_spark.py"
+                         "tests/pytorch/test_pytorch_model_export.py"
+                         "tests/spark/test_spark_model_export.py"
+                         "tests/store/test_azure_blob_artifact_repo.py"
+                         "tests/store/test_gcs_artifact_repo.py"
+                         "tests/store/test_sftp_artifact_repo.py"
+                         "tests/tracking/test_tracking.py"
+
+                         ;; TODO: These require installing 'mlflow_test_plugin'.
+                         "tests/server/test_handlers.py"
+                         "tests/store/test_artifact_repository_registry.py"
+                         "tests/tracking/test_utils.py"
+                         "tests/tracking/context/test_registry.py"
+
+                         ;; This requires a running Docker daemon.
+                         "tests/models/test_cli.py"
+
+                         ;; These require a standalone version of 'conda'.
+                         "tests/pyfunc/test_scoring_server.py"
+                         "tests/pyfunc/test_model_export_with_class_and_artifacts.py"
+
+                         ;; These tests need internet access.
+                         "tests/projects/test_projects_cli.py"
+                         "tests/tensorflow_autolog/test_tensorflow_autolog.py"))
+
+             ;; The test script stores non-zero exit codes in an "$err" variable
+             ;; and checks it at the end of the run.  We need to allow exit code 5
+             ;; from pytest, meaning "no tests were collected", because the above
+             ;; deletions empties some of the directories given to pytest.
+             (substitute* "travis/run-large-python-tests.sh"
+               (("trap 'err=1' ERR")
+                "trap '[[ \"$?\" != \"5\" ]] && err=1' ERR"))
+
+             #t))
+         (delete 'check)
+         (add-after 'install 'check
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (add-installed-pythonpath inputs outputs)
+             (setenv "PATH"
+                     (string-append (assoc-ref outputs "out")
+                                    "/bin:" (getenv "PATH")))
+             (invoke "./travis/run-large-python-tests.sh"))))))
+    (native-inputs
+     `( ;; For tests.
+       ("python-keras" ,python-keras)
+       ("python-moto" ,python-moto)
+       ("python-pyarrow" ,python-pyarrow)
+       ("python-pytest" ,python-pytest)
+       ("tensorflow" ,tensorflow)))
+    (propagated-inputs
+     `(("python-alembic" ,python-alembic)
+       ("python-boto3" ,python-boto3)
+       ("python-click" ,python-click)
+       ("python-cloudpickle" ,python-cloudpickle)
+       ("python-databricks-cli" ,python-databricks-cli)
+       ("python-dateutil" ,python-dateutil)
+       ("python-docker" ,python-docker-py)
+       ("python-entrypoints" ,python-entrypoints)
+       ("python-flask" ,python-flask)
+       ("python-gitpython" ,python-gitpython)
+       ("python-gorilla" ,python-gorilla)
+       ("python-gunicorn" ,python-gunicorn)
+       ("python-numpy" ,python-numpy)
+       ("python-pandas" ,python-pandas)
+       ("python-protobuf" ,python-protobuf-next)
+       ("python-pyyaml" ,python-pyyaml)
+       ("python-querystring-parser" ,python-querystring-parser)
+       ("python-requests" ,python-requests)
+       ("python-scikit-learn" ,python-scikit-learn)
+       ("python-simplejson" ,python-simplejson)
+       ("python-six" ,python-six)
+       ("python-sqlalchemy" ,python-sqlalchemy)
+       ("python-sqlparse" ,python-sqlparse)
+       ("python-waitress" ,python-waitress)))
+    (home-page "https://mlflow.org/")
+    (synopsis "Manage machine learning workflows")
+    (description
+     "MLflow is a platform to streamline machine learning development,
+including tracking experiments, packaging code into reproducible runs, and
+sharing and deploying models.  MLflow offers a set of lightweight APIs that
+can used with any existing machine learning application or library (TensorFlow,
+PyTorch, XGBoost, etc), wherever you currently run ML code (e.g. in notebooks,
+standalone applications or the cloud).")
+    (license license:asl2.0)))
+
 (define-public randomjungle
   (package
     (name "randomjungle")
-- 
2.22.1