Skip to content

Commit

Permalink
Add development docker
Browse files Browse the repository at this point in the history
  • Loading branch information
befelix committed Sep 26, 2017
1 parent fd9776f commit 3d488df
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 24 deletions.
41 changes: 41 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM continuumio/miniconda3

# Install build essentials and clean up
RUN apt-get update --quiet \
&& apt-get install -y --no-install-recommends --quiet build-essential \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Update conda, install packages, and clean up
RUN conda update conda --yes --quiet \
&& conda install python=3.5 pip numpy scipy pandas --yes --quiet \
&& conda clean --yes --all \
&& hash -r

# Get the requirements files (seperate from the main body)
COPY requirements.txt requirements_dev.txt /reqs/

# Install requirements and clean up
RUN pip --no-cache-dir install -r /reqs/requirements.txt \
&& pip --no-cache-dir install -r /reqs/requirements_dev.txt \
&& pip install jupyter jupyterlab \
&& rm -rf /root/.cache \
&& rm -rf /reqs

# Manually install GPflow and clean up
RUN git clone --depth=1 --branch=0.4.0 https://github.com/GPflow/GPflow.git \
&& cd GPflow \
&& python setup.py install \
&& rm -rf /GPflow

# Output scrubber for jupyter
ADD scripts/jupyter_output.py /

RUN jupyter notebook --generate-config \
&& cat /jupyter_output.py >> /root/.jupyter/jupyter_notebook_config.py \
&& rm /jupyter_output.py

WORKDIR /code

CMD python setup.py develop \
&& jupyter lab --ip="0.0.0.0" --no-browser --allow-root
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

doc: ## Build documentation (docs/_build/html/index.html)
doc: ## Build documentation (docs/_build/html/index.html)
cd docs && $(MAKE) html

coverage: ## Construct coverage (htmlcov/index.html)
Expand All @@ -16,6 +16,10 @@ test: docker ## Test the docker images
docker run safe_learning_py2 make test-local
docker run safe_learning_py3 make test-local

dev: ## Mount current code as volume and run jupyterlab for development
docker build -f Dockerfile.dev -t safe_learning_dev .
docker run -p 8888:8888 -v $(shell pwd):/code safe_learning_dev

docker: ## Build the docker images
docker build -f Dockerfile.python2 -t safe_learning_py2 .
docker build -f Dockerfile.python3 -t safe_learning_py3 .
Expand Down
36 changes: 13 additions & 23 deletions examples/1d_discrete.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"from __future__ import division, print_function\n",
"\n",
"import tensorflow as tf\n",
"import GPflow\n",
"import gpflow\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from future.builtins import *\n",
Expand Down Expand Up @@ -72,8 +70,8 @@
"# Mean dynamics\n",
"mean_function = safe_learning.LinearSystem((0.25, 0.), name='mean_dynamics')\n",
"\n",
"kernel = (GPflow.kernels.Matern32(1, lengthscales=1, variance=0.4**2, active_dims=[0])\n",
" * GPflow.kernels.Linear(1, active_dims=[0]))\n",
"kernel = (gpflow.kernels.Matern32(1, lengthscales=1, variance=0.4**2, active_dims=[0])\n",
" * gpflow.kernels.Linear(1, active_dims=[0]))\n",
"\n",
"gp = safe_learning.GPRCached(np.empty((0, 2), dtype=safe_learning.config.np_dtype),\n",
" np.empty((0, 1), dtype=safe_learning.config.np_dtype),\n",
Expand Down Expand Up @@ -122,9 +120,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# lyapunov_function = safe_learning.QuadraticFunction(np.array([[1]]))\n",
Expand Down Expand Up @@ -178,9 +174,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"lyapunov.initial_safe_set = np.abs(lyapunov.discretization.all_points.squeeze()) < 0.2"
Expand All @@ -197,9 +191,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"grid = lyapunov.discretization.all_points\n",
Expand Down Expand Up @@ -239,9 +231,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# Update the GP model a couple of times\n",
Expand Down Expand Up @@ -301,21 +291,21 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
"pygments_lexer": "ipython3",
"version": "3.5.4"
}
},
"nbformat": 4,
Expand Down
16 changes: 16 additions & 0 deletions scripts/jupyter_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def scrub_output_pre_save(model, **kwargs):
"""scrub output before saving notebooks"""
# only run on notebooks
if model['type'] != 'notebook':
return
# only run on nbformat v4
if model['content']['nbformat'] != 4:
return

for cell in model['content']['cells']:
if cell['cell_type'] != 'code':
continue
cell['outputs'] = []
cell['execution_count'] = None

c.FileContentsManager.pre_save_hook = scrub_output_pre_save

0 comments on commit 3d488df

Please sign in to comment.