Skip to content

Commit

Permalink
Merge branch 'feature/requirements_refactoring' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
sarusso committed Dec 7, 2021
2 parents f6d5298 + a134df7 commit 189131c
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 25 deletions.
4 changes: 2 additions & 2 deletions containers/Ubuntu_18.04/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ RUN python3 get-pip.py #-c <(echo 'pip==20.2')
RUN apt-get install python-tk python3-tk python3-dev build-essential -y

# Install Python requirements
COPY requirements.txt /tmp
RUN pip3 install -r /tmp/requirements.txt
COPY requirements-tf2.6.txt /tmp/
RUN pip3 install -r /tmp/requirements-tf2.6.txt

# Install Jupyter and Sphinx for docs
RUN pip3 install notebook==5.7.10 Sphinx==3.5.2 sphinx-rtd-theme==0.5.1
Expand Down
32 changes: 32 additions & 0 deletions containers/Ubuntu_20.04/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM sarusso/tensorflow:2.7.0
MAINTAINER Stefano Alberto Russo <stefano.russo@gmail.com>

# Update apt cache
RUN apt-get update

# Install Python requirements
COPY requirements.txt /tmp
COPY requirements-arm.txt /tmp
RUN if [ "$(uname -i)" = "aarch64" ] ; then pip3 install -r /tmp/requirements-arm.txt; else pip3 install -r /tmp/requirements.txt; fi

# Install Jupyter and Sphinx for docs
RUN pip3 install notebook==5.7.10 Sphinx==3.5.2 sphinx-rtd-theme==0.5.1

# Add demo notebooks
RUN apt-get install git -y
RUN cd /opt && git clone https://github.com/sarusso/Timeseria-notebooks && cd /opt/Timeseria-notebooks && git checkout be7c123

RUN ln -s /opt/Timeseria-notebooks/notebooks /notebooks

# Copy entrypoint
COPY containers/Ubuntu_20.04/entrypoint.sh /

# Give right permissions
RUN chmod 755 /entrypoint.sh

# Set entrypoint
ENTRYPOINT ["/entrypoint.sh"]

# Add code
COPY ./ /opt/Timeseria

19 changes: 19 additions & 0 deletions containers/Ubuntu_20.04/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -e

# Move to project root
cd ../../

# Build Docker container
echo -e "\n==============================="
echo -e "| Building Docker container |"
echo -e "===============================\n"

if [[ "x$CACHE" == "xFalse" ]]; then
echo "Building without cache."
docker build --no-cache -f containers/Ubuntu_20.04/Dockerfile ./ -t timeseria
else
echo "Building with cache. Use CACHE=False to disable it."
docker build -f containers/Ubuntu_20.04/Dockerfile ./ -t timeseria

fi
20 changes: 20 additions & 0 deletions containers/Ubuntu_20.04/build_multiarch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -e

# Move to project root
cd ../../

# Build Docker container
echo -e "\n==============================="
echo -e "| Building Docker container |"
echo -e "===============================\n"

if [[ "x$CACHE" == "xFalse" ]]; then
echo "Building without cache."
docker buildx build --progress=plain --no-cache -f containers/Ubuntu_20.04/Dockerfile ./ --platform linux/amd64 -t timeseria-amd64 --load #--push
docker buildx build --progress=plain --no-cache -f containers/Ubuntu_20.04/Dockerfile ./ --platform linux/arm64/v8 -t timeseria-arm64v8 --load #--push
else
echo "Building with cache. Use CACHE=False to disable it."
docker buildx build --progress=plain -f containers/Ubuntu_20.04/Dockerfile ./ --platform linux/amd64 -t timeseria-amd64 --load #--push
docker buildx build --progress=plain -f containers/Ubuntu_20.04/Dockerfile ./ --platform linux/arm64/v8 -t timeseria-arm64v8 --load #--push
fi
44 changes: 44 additions & 0 deletions containers/Ubuntu_20.04/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# Exit on any error. More complex thing could be done in future
# (see https://stackoverflow.com/questions/4381618/exit-a-script-on-error)
set -e

if [[ "x$(uname -i)" == "xaarch64" ]] ; then
export LD_PRELOAD=/usr/local/lib/python3.8/dist-packages/scikit_learn.libs/libgomp-d22c30c5.so.1.0.0
fi

if [[ "x$@" == "x" ]] ; then

# Start Jupyter as default entrypoint
echo -e "Running Jupyter"

# Reduce verbosity and disable Python buffering
export PYTHONWARNINGS=ignore
export TF_CPP_MIN_LOG_LEVEL=3
export PYTHONUNBUFFERED=on
export EXTENDED_TESTING=False
export PYTHONPATH=\$PYTHONPATH:/opt/Timeseria

cd /opt/Timeseria && jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root --NotebookApp.token='' --NotebookApp.notebook_dir='/notebooks'

else
ENTRYPOINT_COMMAND=$@
echo -n "Executing Docker entrypoint command: "
echo $ENTRYPOINT_COMMAND
exec /bin/bash -c "$ENTRYPOINT_COMMAND"
fi














22 changes: 22 additions & 0 deletions containers/Ubuntu_20.04/push_multiarch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -e

USER="sarusso"
VERSION="v0.1.3"

echo "Tagging..."
docker tag timeseria-amd64 docker.io/$USER/timeseria-amd64:$VERSION
docker tag timeseria-arm64v8 docker.io/$USER/timeseria-arm64v8:$VERSION

echo "Pushing images"
docker push docker.io/$USER/timeseria-amd64:$VERSION
docker push docker.io/$USER/timeseria-arm64v8:$VERSION

echo "Creating manifest..."
docker manifest create \
docker.io/$USER/timeseria:$VERSION \
--amend docker.io/$USER/timeseria-amd64:$VERSION \
--amend docker.io/$USER/timeseria-arm64v8:$VERSION

echo "Pushing manifest"
docker manifest push docker.io/$USER/timeseria:$VERSION
19 changes: 19 additions & 0 deletions containers/Ubuntu_20.04/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -e

# Move to project root
cd ../../

# Build Docker container
echo -e "\n==============================="
echo -e "| Running Docker container |"
echo -e "===============================\n"

if [[ "x$LIVE" == "xTrue" ]]; then
echo "Running with live code changes"
docker run -p8888:8888 -v $PWD:/opt/Timeseria -v $PWD/notebooks:/notebooks -it timeseria
else
echo "Running without live code changes. Use LIVE=True to enable them."
docker run -p8888:8888 -it timeseria
fi

2 changes: 1 addition & 1 deletion docs/makedocs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e

# Move to container dir
cd ../containers/Ubuntu_18.04
cd ../containers/Ubuntu_20.04

if [[ "x$BUILD" != "xFalse" ]]; then
# Build
Expand Down
4 changes: 3 additions & 1 deletion jupyter.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/bash
set -e

# This script will build and run the Timeseria container for the arch in use (with Jupyter into it).

# Move to container dir
cd containers/Ubuntu_18.04
cd containers/Ubuntu_20.04

if [[ "x$BUILD" != "xFalse" ]]; then
# Build
Expand Down
19 changes: 19 additions & 0 deletions requirements-arm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Keras==2.7.0
tensorflow-aarch64==2.7.0
matplotlib==3.5.0
numpy==1.21.4
scikit-learn==1.0.1
pandas==1.3.4
chardet==3.0.4
convertdate==2.3.2
lunarcalendar==0.0.9
holidays==0.11.3.1
cython==0.29.17
requests==2.26.0
h5py==3.6.0
scipy==1.7.3

# Optional
#fbprophet==0.6 # Facebook's Prophet
#pmdarima==1.8 # AARIMA
#statsmodels==0.12.1 # ARIMA, SARIMAX
30 changes: 14 additions & 16 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
Keras==2.1.3
tensorflow==1.15.2
matplotlib==2.1.2
numpy==1.19.5
scikit-image==0.15.0
scikit-learn==0.22
pandas==0.23.4
Keras==2.7.0
tensorflow==2.7.0
matplotlib==3.5.0
numpy==1.21.4
scikit-learn==1.0.1
pandas==1.3.4
chardet==3.0.4
convertdate==2.1.2
convertdate==2.3.2
lunarcalendar==0.0.9
holidays==0.10.3
holidays==0.11.3.1
cython==0.29.17
pystan==2.19.1.1
plotly==4.9.0
requests==2.20.0
h5py==2.10.0
requests==2.26.0
h5py==3.6.0
scipy==1.7.3

# Optional
fbprophet==0.6 # Facebook's Prophet
pmdarima==1.8 # AARIMA
statsmodels==0.12.1 # ARIMA, SARIMAX
#fbprophet==0.6 # Facebook's Prophet
#pmdarima==1.8 # AARIMA
#statsmodels==0.12.1 # ARIMA, SARIMAX
4 changes: 3 additions & 1 deletion test.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/bash
set -e

# This script will build the Timeseria container for the arch in use and run the tests into it.

# Move to container dir
cd containers/Ubuntu_18.04
cd containers/Ubuntu_20.04

if [[ "x$BUILD" != "xFalse" ]]; then
# Build
Expand Down
20 changes: 16 additions & 4 deletions timeseria/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_ProphetReconstructor(self):
try:
import fbprophet
except ImportError:
print('Skipping Prophet tests as no module is installed')
print('Skipping Prophet tests as no fbprophet module installed')
return

# Get test data
Expand Down Expand Up @@ -302,7 +302,7 @@ def test_ProphetForecaster(self):
try:
import fbprophet
except ImportError:
print('Skipping Prophet tests as no module is installed')
print('Skipping Prophet tests as no fbprophet module installed')
return

forecaster = ProphetForecaster()
Expand Down Expand Up @@ -336,6 +336,12 @@ def test_ProphetForecaster(self):


def test_ARIMAForecaster(self):

try:
import statsmodels
except ImportError:
print('Skipping ARIMA tests as no statsmodels module installed')
return

# Basic ARIMA
forecaster = ARIMAForecaster(p=1,d=1,q=0)
Expand All @@ -359,8 +365,8 @@ def test_ARIMAForecaster(self):
forecaster = ARIMAForecaster(p=1,d=1,q=0)
forecaster.fit(self.sine_data_time_slot_series_day[0:800])
evaluation_results = forecaster.evaluate(self.sine_data_time_slot_series_day[800:1000])
self.assertAlmostEqual(evaluation_results['RMSE'], 2.7108009033754485)
self.assertAlmostEqual(evaluation_results['MAE'], 2.5248923274486983)
self.assertAlmostEqual(evaluation_results['RMSE'], 2.71, places=2)
self.assertAlmostEqual(evaluation_results['MAE'], 2.52, places=2 )

# Test on Points as well
data_time_point_series = CSVFileStorage(TEST_DATA_PATH + '/csv/temperature.csv').get(limit=200)
Expand All @@ -376,6 +382,12 @@ def test_ARIMAForecaster(self):


def test_AARIMAForecaster(self):

try:
import statsmodels
except ImportError:
print('Skipping AARIMA tests as no statsmodels module installed')
return

# Automatic ARIMA
forecaster = AARIMAForecaster()
Expand Down

0 comments on commit 189131c

Please sign in to comment.