From c8e8d050362ca070b049c722c08a76e8d5b8e6be Mon Sep 17 00:00:00 2001 From: Daniel Young Date: Tue, 30 Jul 2024 16:47:16 -0700 Subject: [PATCH 1/3] Changed all imports to be relative. Moved prsdk out of src folder --- {src/prsdk => prsdk}/__init__.py | 0 {src/prsdk => prsdk}/data/torch_data.py | 0 .../persistence/persistors/hf_persistor.py | 2 +- .../persistence/persistors/persistor.py | 2 +- .../serializers/neural_network_serializer.py | 6 +++--- .../persistence/serializers/serializer.py | 0 .../serializers/sklearn_serializer.py | 4 ++-- .../neural_network/neural_net_predictor.py | 6 +++--- .../neural_network/torch_neural_net.py | 0 {src/prsdk => prsdk}/predictors/predictor.py | 0 .../linear_regression_predictor.py | 2 +- .../random_forest_predictor.py | 2 +- .../sklearn_predictors/sklearn_predictor.py | 2 +- .../prsdk => prsdk}/prescriptors/prescriptor.py | 0 tests/persistence/test_hf_persistence.py | 6 +++--- .../persistence/test_predictor_serialization.py | 10 +++++----- tests/predictors/test_neural_net.py | 2 +- tests/test_dummy.py | 17 ----------------- 18 files changed, 22 insertions(+), 39 deletions(-) rename {src/prsdk => prsdk}/__init__.py (100%) rename {src/prsdk => prsdk}/data/torch_data.py (100%) rename {src/prsdk => prsdk}/persistence/persistors/hf_persistor.py (97%) rename {src/prsdk => prsdk}/persistence/persistors/persistor.py (95%) rename {src/prsdk => prsdk}/persistence/serializers/neural_network_serializer.py (93%) rename {src/prsdk => prsdk}/persistence/serializers/serializer.py (100%) rename {src/prsdk => prsdk}/persistence/serializers/sklearn_serializer.py (91%) rename {src/prsdk => prsdk}/predictors/neural_network/neural_net_predictor.py (98%) rename {src/prsdk => prsdk}/predictors/neural_network/torch_neural_net.py (100%) rename {src/prsdk => prsdk}/predictors/predictor.py (100%) rename {src/prsdk => prsdk}/predictors/sklearn_predictors/linear_regression_predictor.py (90%) rename {src/prsdk => prsdk}/predictors/sklearn_predictors/random_forest_predictor.py (89%) rename {src/prsdk => prsdk}/predictors/sklearn_predictors/sklearn_predictor.py (97%) rename {src/prsdk => prsdk}/prescriptors/prescriptor.py (100%) delete mode 100644 tests/test_dummy.py diff --git a/src/prsdk/__init__.py b/prsdk/__init__.py similarity index 100% rename from src/prsdk/__init__.py rename to prsdk/__init__.py diff --git a/src/prsdk/data/torch_data.py b/prsdk/data/torch_data.py similarity index 100% rename from src/prsdk/data/torch_data.py rename to prsdk/data/torch_data.py diff --git a/src/prsdk/persistence/persistors/hf_persistor.py b/prsdk/persistence/persistors/hf_persistor.py similarity index 97% rename from src/prsdk/persistence/persistors/hf_persistor.py rename to prsdk/persistence/persistors/hf_persistor.py index 2ea3994..06354bf 100644 --- a/src/prsdk/persistence/persistors/hf_persistor.py +++ b/prsdk/persistence/persistors/hf_persistor.py @@ -5,7 +5,7 @@ from huggingface_hub import HfApi, snapshot_download -from persistence.persistors.persistor import Persistor +from prsdk.persistence.persistors.persistor import Persistor class HuggingFacePersistor(Persistor): diff --git a/src/prsdk/persistence/persistors/persistor.py b/prsdk/persistence/persistors/persistor.py similarity index 95% rename from src/prsdk/persistence/persistors/persistor.py rename to prsdk/persistence/persistors/persistor.py index c4eb0e8..6fd79fb 100644 --- a/src/prsdk/persistence/persistors/persistor.py +++ b/prsdk/persistence/persistors/persistor.py @@ -6,7 +6,7 @@ from abc import ABC, abstractmethod -from persistence.serializers.serializer import Serializer +from prsdk.persistence.serializers.serializer import Serializer class Persistor(ABC): diff --git a/src/prsdk/persistence/serializers/neural_network_serializer.py b/prsdk/persistence/serializers/neural_network_serializer.py similarity index 93% rename from src/prsdk/persistence/serializers/neural_network_serializer.py rename to prsdk/persistence/serializers/neural_network_serializer.py index 8ac0af9..5951734 100644 --- a/src/prsdk/persistence/serializers/neural_network_serializer.py +++ b/prsdk/persistence/serializers/neural_network_serializer.py @@ -7,9 +7,9 @@ import joblib import torch -from persistence.serializers.serializer import Serializer -from predictors.neural_network.torch_neural_net import TorchNeuralNet -from predictors.neural_network.neural_net_predictor import NeuralNetPredictor +from prsdk.persistence.serializers.serializer import Serializer +from prsdk.predictors.neural_network.torch_neural_net import TorchNeuralNet +from prsdk.predictors.neural_network.neural_net_predictor import NeuralNetPredictor class NeuralNetSerializer(Serializer): diff --git a/src/prsdk/persistence/serializers/serializer.py b/prsdk/persistence/serializers/serializer.py similarity index 100% rename from src/prsdk/persistence/serializers/serializer.py rename to prsdk/persistence/serializers/serializer.py diff --git a/src/prsdk/persistence/serializers/sklearn_serializer.py b/prsdk/persistence/serializers/sklearn_serializer.py similarity index 91% rename from src/prsdk/persistence/serializers/sklearn_serializer.py rename to prsdk/persistence/serializers/sklearn_serializer.py index 1ad01d8..5becc17 100644 --- a/src/prsdk/persistence/serializers/sklearn_serializer.py +++ b/prsdk/persistence/serializers/sklearn_serializer.py @@ -6,8 +6,8 @@ import joblib -from persistence.serializers.serializer import Serializer -from predictors.sklearn_predictors.sklearn_predictor import SKLearnPredictor +from prsdk.persistence.serializers.serializer import Serializer +from prsdk.predictors.sklearn_predictors.sklearn_predictor import SKLearnPredictor class SKLearnSerializer(Serializer): diff --git a/src/prsdk/predictors/neural_network/neural_net_predictor.py b/prsdk/predictors/neural_network/neural_net_predictor.py similarity index 98% rename from src/prsdk/predictors/neural_network/neural_net_predictor.py rename to prsdk/predictors/neural_network/neural_net_predictor.py index 159336f..530c61e 100644 --- a/src/prsdk/predictors/neural_network/neural_net_predictor.py +++ b/prsdk/predictors/neural_network/neural_net_predictor.py @@ -14,9 +14,9 @@ from torch.utils.data import DataLoader from torch.utils.tensorboard import SummaryWriter -from data.torch_data import TorchDataset -from predictors.predictor import Predictor -from predictors.neural_network.torch_neural_net import TorchNeuralNet +from prsdk.data.torch_data import TorchDataset +from prsdk.predictors.predictor import Predictor +from prsdk.predictors.neural_network.torch_neural_net import TorchNeuralNet # pylint: disable=too-many-instance-attributes diff --git a/src/prsdk/predictors/neural_network/torch_neural_net.py b/prsdk/predictors/neural_network/torch_neural_net.py similarity index 100% rename from src/prsdk/predictors/neural_network/torch_neural_net.py rename to prsdk/predictors/neural_network/torch_neural_net.py diff --git a/src/prsdk/predictors/predictor.py b/prsdk/predictors/predictor.py similarity index 100% rename from src/prsdk/predictors/predictor.py rename to prsdk/predictors/predictor.py diff --git a/src/prsdk/predictors/sklearn_predictors/linear_regression_predictor.py b/prsdk/predictors/sklearn_predictors/linear_regression_predictor.py similarity index 90% rename from src/prsdk/predictors/sklearn_predictors/linear_regression_predictor.py rename to prsdk/predictors/sklearn_predictors/linear_regression_predictor.py index 7ae1e8b..a15869b 100644 --- a/src/prsdk/predictors/sklearn_predictors/linear_regression_predictor.py +++ b/prsdk/predictors/sklearn_predictors/linear_regression_predictor.py @@ -3,7 +3,7 @@ """ from sklearn.linear_model import LinearRegression -from predictors.sklearn_predictors.sklearn_predictor import SKLearnPredictor +from prsdk.predictors.sklearn_predictors.sklearn_predictor import SKLearnPredictor class LinearRegressionPredictor(SKLearnPredictor): diff --git a/src/prsdk/predictors/sklearn_predictors/random_forest_predictor.py b/prsdk/predictors/sklearn_predictors/random_forest_predictor.py similarity index 89% rename from src/prsdk/predictors/sklearn_predictors/random_forest_predictor.py rename to prsdk/predictors/sklearn_predictors/random_forest_predictor.py index 6ffdb2a..84de3ba 100644 --- a/src/prsdk/predictors/sklearn_predictors/random_forest_predictor.py +++ b/prsdk/predictors/sklearn_predictors/random_forest_predictor.py @@ -3,7 +3,7 @@ """ from sklearn.ensemble import RandomForestRegressor -from predictors.sklearn_predictors.sklearn_predictor import SKLearnPredictor +from prsdk.predictors.sklearn_predictors.sklearn_predictor import SKLearnPredictor class RandomForestPredictor(SKLearnPredictor): diff --git a/src/prsdk/predictors/sklearn_predictors/sklearn_predictor.py b/prsdk/predictors/sklearn_predictors/sklearn_predictor.py similarity index 97% rename from src/prsdk/predictors/sklearn_predictors/sklearn_predictor.py rename to prsdk/predictors/sklearn_predictors/sklearn_predictor.py index 142252e..fae031a 100644 --- a/src/prsdk/predictors/sklearn_predictors/sklearn_predictor.py +++ b/prsdk/predictors/sklearn_predictors/sklearn_predictor.py @@ -6,7 +6,7 @@ import pandas as pd -from predictors.predictor import Predictor +from prsdk.predictors.predictor import Predictor class SKLearnPredictor(Predictor, ABC): diff --git a/src/prsdk/prescriptors/prescriptor.py b/prsdk/prescriptors/prescriptor.py similarity index 100% rename from src/prsdk/prescriptors/prescriptor.py rename to prsdk/prescriptors/prescriptor.py diff --git a/tests/persistence/test_hf_persistence.py b/tests/persistence/test_hf_persistence.py index 9d700b5..fcaeb1b 100644 --- a/tests/persistence/test_hf_persistence.py +++ b/tests/persistence/test_hf_persistence.py @@ -8,9 +8,9 @@ import numpy as np import pandas as pd -from persistence.persistors.hf_persistor import HuggingFacePersistor -from persistence.serializers.neural_network_serializer import NeuralNetSerializer -from predictors.neural_network.neural_net_predictor import NeuralNetPredictor +from prsdk.persistence.persistors.hf_persistor import HuggingFacePersistor +from prsdk.persistence.serializers.neural_network_serializer import NeuralNetSerializer +from prsdk.predictors.neural_network.neural_net_predictor import NeuralNetPredictor class TestHuggingFacePersistence(unittest.TestCase): diff --git a/tests/persistence/test_predictor_serialization.py b/tests/persistence/test_predictor_serialization.py index 0cd4513..76270c9 100644 --- a/tests/persistence/test_predictor_serialization.py +++ b/tests/persistence/test_predictor_serialization.py @@ -7,11 +7,11 @@ import pandas as pd -from persistence.serializers.neural_network_serializer import NeuralNetSerializer -from persistence.serializers.sklearn_serializer import SKLearnSerializer -from predictors.neural_network.neural_net_predictor import NeuralNetPredictor -from predictors.sklearn_predictors.linear_regression_predictor import LinearRegressionPredictor -from predictors.sklearn_predictors.random_forest_predictor import RandomForestPredictor +from prsdk.persistence.serializers.neural_network_serializer import NeuralNetSerializer +from prsdk.persistence.serializers.sklearn_serializer import SKLearnSerializer +from prsdk.predictors.neural_network.neural_net_predictor import NeuralNetPredictor +from prsdk.predictors.sklearn_predictors.linear_regression_predictor import LinearRegressionPredictor +from prsdk.predictors.sklearn_predictors.random_forest_predictor import RandomForestPredictor class TestPredictorSerialization(unittest.TestCase): diff --git a/tests/predictors/test_neural_net.py b/tests/predictors/test_neural_net.py index ead24d3..e3df1ad 100644 --- a/tests/predictors/test_neural_net.py +++ b/tests/predictors/test_neural_net.py @@ -5,7 +5,7 @@ import pandas as pd -from predictors.neural_network.neural_net_predictor import NeuralNetPredictor +from prsdk.predictors.neural_network.neural_net_predictor import NeuralNetPredictor class TestNeuralNet(unittest.TestCase): diff --git a/tests/test_dummy.py b/tests/test_dummy.py deleted file mode 100644 index 4b8c8c5..0000000 --- a/tests/test_dummy.py +++ /dev/null @@ -1,17 +0,0 @@ -""" -Dummy test to test Github actions. -""" -import unittest - - -class TestDummy(unittest.TestCase): - """ - A fake test that always returns true. - """ - def test_dummy(self): - """ - A test that always returns true. - """ - # pylint: disable=redundant-unittest-assert - self.assertTrue(True) - # pylint: enable=redundant-unittest-assert From bef63512f28c6c1a7de98f9f502077b0872568cb Mon Sep 17 00:00:00 2001 From: Daniel Young Date: Tue, 30 Jul 2024 17:04:26 -0700 Subject: [PATCH 2/3] Updated workflow to match new project structure --- .github/workflows/sdk.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sdk.yml b/.github/workflows/sdk.yml index 6dee78a..4cf012e 100644 --- a/.github/workflows/sdk.yml +++ b/.github/workflows/sdk.yml @@ -17,17 +17,15 @@ jobs: uses: actions/setup-python@v3 with: python-version: "3.10" - - name: Set PYTHONPATH - run: echo "PYTHONPATH=$PWD/src/prsdk" >> $GITHUB_ENV - name: Install dependencies run: | python -m pip install --upgrade pip pip install pylint if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint with PyLint - run: pylint ./src/prsdk + run: pylint ./prsdk - name: Lint with Flake8 - run: flake8 ./src/prsdk + run: flake8 ./prsdk - name: Run unit tests run: python -m unittest From c0e5300e56f5fce2f6cf55c328c83e7055e541be Mon Sep 17 00:00:00 2001 From: Daniel Young Date: Tue, 30 Jul 2024 17:04:47 -0700 Subject: [PATCH 3/3] Changed device of torch dataset in predict method to avoid potential error --- prsdk/predictors/neural_network/neural_net_predictor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prsdk/predictors/neural_network/neural_net_predictor.py b/prsdk/predictors/neural_network/neural_net_predictor.py index 530c61e..dcb6796 100644 --- a/prsdk/predictors/neural_network/neural_net_predictor.py +++ b/prsdk/predictors/neural_network/neural_net_predictor.py @@ -189,7 +189,7 @@ def predict(self, context_actions_df: pd.DataFrame) -> pd.DataFrame: :return: DataFrame of predictions properly labeled and indexed. """ X_test_scaled = self.scaler.transform(context_actions_df[self.features]) - test_ds = TorchDataset(X_test_scaled, np.zeros(len(X_test_scaled))) + test_ds = TorchDataset(X_test_scaled, np.zeros(len(X_test_scaled)), device=self.device) test_dl = DataLoader(test_ds, self.batch_size, shuffle=False) pred_list = [] with torch.no_grad():