Skip to content

Commit

Permalink
Merge pull request #101 from Project-Resilience/sdk
Browse files Browse the repository at this point in the history
Import abstract classes from SDK
  • Loading branch information
danyoungday authored Jul 29, 2024
2 parents 0b49c34 + 4c985ba commit 5aac5dd
Show file tree
Hide file tree
Showing 21 changed files with 35 additions and 149 deletions.
2 changes: 2 additions & 0 deletions use_cases/eluc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ the percentage of land that was changed. In other words decision makers have to:

*Note: Before running anything make sure to set your python path environment variable with: `export PYTHONPATH=$PWD` while in the eluc directory.*

Additionaly, the Project Resilience SDK is required to use the MVP. Currently it is not hosted on PyPi so it must be installed manually. To do so, clone the [Project Resilience SDK](https://github.com/Project-Resilience/sdk) and run pip install . in its root directory.

### Predictions

Given **context** and **actions** -> predict **outcomes**
Expand Down
3 changes: 2 additions & 1 deletion use_cases/eluc/app/components/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
from dash import html
import pandas as pd

from prsdk.predictors.predictor import Predictor

from app import constants as app_constants
from data import constants
from persistence.persistors.hf_persistor import HuggingFacePersistor
from persistence.serializers.neural_network_serializer import NeuralNetSerializer
from persistence.serializers.sklearn_serializer import SKLearnSerializer
from predictors.predictor import Predictor
from predictors.percent_change.percent_change_predictor import PercentChangePredictor


Expand Down
3 changes: 2 additions & 1 deletion use_cases/eluc/experiments/predictor_experiments.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
"from scipy.stats import ttest_1samp, ttest_ind\n",
"from sklearn.metrics import mean_absolute_error\n",
"\n",
"from prsdk.predictors.predictor import Predictor\n",
"\n",
"from data.eluc_data import ELUCData\n",
"from data import constants\n",
"from persistence.serializers.neural_network_serializer import NeuralNetSerializer\n",
"from persistence.serializers.sklearn_serializer import SKLearnSerializer\n",
"from predictors.predictor import Predictor\n",
"from predictors.neural_network.neural_net_predictor import NeuralNetPredictor\n",
"from predictors.sklearn_predictor.sklearn_predictor import LinearRegressionPredictor, RandomForestPredictor"
]
Expand Down
8 changes: 4 additions & 4 deletions use_cases/eluc/persistence/persistors/hf_persistor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -27,7 +27,7 @@ def persist(self, model, model_path: Path, repo_id: str, **persistence_args):
then uploads the model to a HuggingFace repo.
"""
# Save model and write readme
self.file_serializer.save(model, model_path)
self.serializer.save(model, model_path)
self.write_readme(model_path)

# Get token if it exists
Expand Down Expand Up @@ -58,7 +58,7 @@ def from_pretrained(self, path_or_url: str, **hf_args):
"""
path = Path(path_or_url)
if path.exists() and path.is_dir():
return self.file_serializer.load(path)
return self.serializer.load(path)
# TODO: Need a try except block to catch download errors
url_path = path_or_url.replace("/", "--")
local_dir = hf_args.get("local_dir", f"huggingface_models/{url_path}")
Expand All @@ -67,4 +67,4 @@ def from_pretrained(self, path_or_url: str, **hf_args):
hf_args["local_dir"] = local_dir
snapshot_download(repo_id=path_or_url, **hf_args)

return self.file_serializer.load(Path(local_dir))
return self.serializer.load(Path(local_dir))
31 changes: 0 additions & 31 deletions use_cases/eluc/persistence/persistors/persistor.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import joblib
import torch

from persistence.serializers.serializer import Serializer
from prsdk.persistence.serializers.serializer import Serializer

from predictors.neural_network.eluc_neural_net import ELUCNeuralNet
from predictors.neural_network.neural_net_predictor import NeuralNetPredictor

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

import torch

from prsdk.persistence.serializers.serializer import Serializer

from data.eluc_encoder import ELUCEncoder
from persistence.serializers.serializer import Serializer
from prescriptors.nsga2.candidate import Candidate
from prescriptors.nsga2.land_use_prescriptor import LandUsePrescriptor

Expand Down
27 changes: 0 additions & 27 deletions use_cases/eluc/persistence/serializers/serializer.py

This file was deleted.

3 changes: 2 additions & 1 deletion use_cases/eluc/persistence/serializers/sklearn_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import joblib

from persistence.serializers.serializer import Serializer
from prsdk.persistence.serializers.serializer import Serializer

from predictors.sklearn_predictor.sklearn_predictor import SKLearnPredictor


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"""
import pandas as pd

from prsdk.predictors.predictor import Predictor

from data import constants
from predictors.predictor import Predictor


class TemplatePredictor(Predictor):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter

from prsdk.predictors.predictor import Predictor

from data import constants
from data.torch_data import TorchDataset
from predictors.predictor import Predictor
from predictors.neural_network.eluc_neural_net import ELUCNeuralNet


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"""
import pandas as pd

from prsdk.predictors.predictor import Predictor

from data import constants
from predictors.predictor import Predictor


class PercentChangePredictor(Predictor):
Expand Down
49 changes: 0 additions & 49 deletions use_cases/eluc/predictors/predictor.py

This file was deleted.

3 changes: 2 additions & 1 deletion use_cases/eluc/predictors/scoring/scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

import pandas as pd

from prsdk.predictors.predictor import Predictor

import data.constants as constants
from data.eluc_data import ELUCData
from persistence.persistors.hf_persistor import HuggingFacePersistor
from predictors.predictor import Predictor
from predictors.scoring.validator import Validator


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import RandomForestRegressor

from prsdk.predictors.predictor import Predictor

from data import constants
from predictors.predictor import Predictor


class SKLearnPredictor(Predictor, ABC):
Expand Down
3 changes: 2 additions & 1 deletion use_cases/eluc/prescriptors/heuristics/heuristics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import pandas as pd

from prsdk.prescriptors.prescriptor import Prescriptor

from data import constants
from prescriptors.prescriptor import Prescriptor


class HeuristicPrescriptor(Prescriptor, ABC):
Expand Down
3 changes: 2 additions & 1 deletion use_cases/eluc/prescriptors/nsga2/land_use_prescriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import torch
from torch.utils.data import DataLoader

from prsdk.prescriptors.prescriptor import Prescriptor

from data import constants
from data.eluc_data import ELUCEncoder
from data.torch_data import TorchDataset
from prescriptors.nsga2.candidate import Candidate
from prescriptors.prescriptor import Prescriptor


class LandUsePrescriptor(Prescriptor):
Expand Down
3 changes: 2 additions & 1 deletion use_cases/eluc/prescriptors/nsga2/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import torch
from torch.utils.data import DataLoader

from prsdk.predictors.predictor import Predictor

from data import constants
from data.eluc_data import ELUCEncoder
from data.torch_data import TorchDataset
from predictors.predictor import Predictor
from prescriptors.nsga2 import nsga2_utils
from prescriptors.nsga2.candidate import Candidate
from prescriptors.nsga2.land_use_prescriptor import LandUsePrescriptor
Expand Down
23 changes: 0 additions & 23 deletions use_cases/eluc/prescriptors/prescriptor.py

This file was deleted.

4 changes: 2 additions & 2 deletions use_cases/eluc/prescriptors/prescriptor_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"""
import pandas as pd

from predictors.predictor import Predictor
from prescriptors.prescriptor import Prescriptor
from prsdk.predictors.predictor import Predictor
from prsdk.prescriptors.prescriptor import Prescriptor


class PrescriptorManager():
Expand Down
1 change: 1 addition & 0 deletions use_cases/eluc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ numpy==1.23.5
pandas==1.5.3
plotly==5.14.1
protobuf==3.20.3
-e git+https://github.com/Project-Resilience/sdk.git@368bcb03378d5456e98f5c839e264f8c117d5abb#egg=prsdk
pylint==2.17.4
regionmask==0.10.0
scikit-learn==1.2.2
Expand Down

0 comments on commit 5aac5dd

Please sign in to comment.