Skip to content

Commit

Permalink
Merge pull request #85 from DLHub-Argonne/fix_skl
Browse files Browse the repository at this point in the history
Fixes for Scikit-Learn
  • Loading branch information
WardLT committed Aug 24, 2020
2 parents 77d165d + cea1227 commit 6f561fa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 87 deletions.
27 changes: 6 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,20 @@ jobs:
env: KERAS_VERSION=2.1.3
- name: Keras 2.2.3
env: KERAS_VERSION=2.2.2
- name: Older Scikit-Learn
env: SKLEARN_VERSION=0.19.1
before_install:
- openssl aes-256-cbc -K $encrypted_ac5a6dd41c09_key -iv $encrypted_ac5a6dd41c09_iv
-in test-files/DLHub_Client_tokens.json.enc -out test-files/DLHub_Client_tokens.json
-d
- mkdir -p ~/.dlhub/credentials
- cp test-files/DLHub_Client_tokens.json ~/.dlhub/credentials
install:

# Update the build environment
- pip install --upgrade pip setuptools wheel

# Install mandatory packages
- pip install -e .
- pip install coveralls flake8

# Install the packages required for tests
- pip install -r test-requirements.txt
- pip install -r example-requirements.txt

# Adding keras, an optional dependency
- if [ ! -z "$KERAS_VERSION" ]; then
- pip install keras==$KERAS_VERSION
- fi

# Print out the current build environment
- pip list
- source ./travis/install.sh
- pip list
script:
- flake8 .
- travis_wait 50 nosetests --with-coverage --cover-package=dlhub_sdk
- flake8 .
- travis_wait 50 nosetests --with-coverage --cover-package=dlhub_sdk
deploy:
provider: pypi
user: wardlt
Expand Down
86 changes: 20 additions & 66 deletions dlhub_sdk/models/servables/tests/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
import math
import os


_year = str(datetime.now().year)


class TestPythonModels(unittest.TestCase):

maxDiff = 4096

def test_pickle(self):
Expand Down Expand Up @@ -47,71 +45,27 @@ def test_pickle(self):

# Check the model output
output = model.to_dict()
correct_output = {
'datacite': {
'creators': [],
'titles': [{
'title': 'Python example'
}],
'publisher': 'DLHub',
'resourceType': {
'resourceTypeGeneral': 'InteractiveResource'
},
'identifier': {
'identifier': '10.YET/UNASSIGNED',
'identifierType': 'DOI'
},
'publicationYear': _year,
"descriptions": [],
"fundingReferences": [],
"relatedIdentifiers": [],
"alternateIdentifiers": [],
"rightsList": []
},
'dlhub': {
'version': __version__,
'domains': [],
'visible_to': ['public'],
'name': 'class_method',
'type': 'servable',
'files': {
'pickle': pickle_path
},
'dependencies': {
'python': {
'scikit-learn': skl_version,
'numpy': numpy_version,
'sklearn': '0.0'
}
}
},
'servable': {
'type': 'Python class method',
'shim': 'python.PythonClassMethodServable',
'methods': {
'run': {
'input': {
'type': 'ndarray',
'description': 'Features for each entry',
'shape': [None, 4]
},
'output': {
'type': 'ndarray',
'description': 'Predicted probabilities of being each iris species',
'shape': [None, 3]
},
'parameters': {
'fake': 'kwarg'
},
'method_details': {
'class_name': 'sklearn.svm.classes.SVC',
'method_name': 'predict_proba'
},
}
}
}
assert output['dlhub']['files'] == {'pickle': pickle_path}
assert output['dlhub']['dependencies']['python'] == {
'scikit-learn': skl_version,
'numpy': numpy_version,
'sklearn': '0.0'
}
self.assertEqual(output, correct_output)
assert output['servable']['shim'] == 'python.PythonClassMethodServable'
assert 'run' in output['servable']['methods']
assert output['servable']['methods']['run']['input'] == {
'type': 'ndarray',
'description': 'Features for each entry',
'shape': [None, 4]
}
assert output['servable']['methods']['run']['output'] == {
'type': 'ndarray',
'description': 'Predicted probabilities of being each iris species',
'shape': [None, 3]
}
assert output['servable']['methods']['run']['method_details']['class_name'].endswith('.SVC')
assert output['servable']['methods']['run']['method_details']['method_name'] == 'predict_proba'

self.assertEqual([pickle_path], model.list_files())
validate_against_dlhub_schema(output, 'servable')

Expand Down
22 changes: 22 additions & 0 deletions travis/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Update the build environment
pip install --upgrade pip setuptools wheel

# Install mandatory packages
pip install -e .
pip install coveralls flake8

# Install the packages required for tests
pip install -r test-requirements.txt
pip install -r example-requirements.txt

# Adding keras, an optional dependency
if [ ! -z "$KERAS_VERSION" ]; then
pip install keras==$KERAS_VERSION
fi

# Manually-specifying the version of scikit-learn
if [ ! -z "$SKLEARN_VERSION" ]; then
pip install scikit-learn==$SKLEARN_VERSION
fi

0 comments on commit 6f561fa

Please sign in to comment.