Skip to content

Commit

Permalink
Merge pull request #11 from aai-institute/fix-and-improve-control
Browse files Browse the repository at this point in the history
Fix and improve Control content
  • Loading branch information
AnesBenmerzoug committed Nov 2, 2023
2 parents d27f27f + e0d4291 commit a37e49e
Show file tree
Hide file tree
Showing 13 changed files with 1,580 additions and 825 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
!config.yml
!requirements*.txt
!pyproject.toml
!poetry.lock
!pyproject-full.toml
!entrypoint.sh
!README.md
Expand Down
96 changes: 66 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,82 @@
FROM jupyter/minimal-notebook:python-3.11
#-------------- Base Image -------------------
FROM jupyter/minimal-notebook:python-3.11 as BASE

ENV POETRY_VERSION=1.6.1
ARG CODE_DIR=/tmp/code
ARG POETRY_VERSION=1.6.1

ENV DEBIAN_FRONTEND=noninteractive \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1 \
POETRY_VERSION=$POETRY_VERSION \
POETRY_HOME="/opt/poetry" \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
CODE_DIR=$CODE_DIR

ENV PATH="${POETRY_HOME}/bin:$PATH"

USER root

RUN curl -sSL https://install.python-poetry.org | python -

USER ${NB_UID}

WORKDIR $CODE_DIR

COPY --chown=${NB_UID}:${NB_GID} poetry.lock pyproject.toml .

RUN poetry install --no-interaction --no-ansi --no-root --only main
RUN poetry install --no-interaction --no-ansi --no-root --with add1
RUN poetry install --no-interaction --no-ansi --no-root --with add2
RUN poetry install --no-interaction --no-ansi --no-root --with control
RUN poetry install --no-interaction --no-ansi --no-root --with offline

COPY --chown=${NB_UID}:${NB_GID} src/ src/
COPY --chown=${NB_UID}:${NB_GID} README.md .

RUN poetry build


#-------------- Main Image -------------------
FROM jupyter/minimal-notebook:python-3.11 as MAIN

ARG CODE_DIR=/tmp/code

ENV DEBIAN_FRONTEND=noninteractive\
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1 \
CODE_DIR=$CODE_DIR

ENV PATH="${CODE_DIR}/.venv/bin:$PATH"

USER root
RUN apt-get update && apt-get upgrade -y

# pandoc needed for docs, see https://nbsphinx.readthedocs.io/en/0.7.1/installation.html?highlight=pandoc#pandoc
# gh-pages action uses rsync
# gcc, gfortran and libopenblas-dev are needed for slycot, which in turn is needed by the python-control package
# build-essential required for scikit-build
# opengl and ffmpeg needed for rendering envs
RUN apt-get -y --no-install-recommends install pandoc git-lfs rsync build-essential gcc gfortran libopenblas-dev ffmpeg
RUN apt-get -y install x11-xserver-utils
RUN apt-get update \
&& apt-get -y --no-install-recommends install pandoc git-lfs rsync ffmpeg x11-xserver-utils \
&& rm -rf /var/lib/apt/lists/*

USER ${NB_UID}

WORKDIR ${CODE_DIR}

# Copy virtual environment from base image
COPY --from=BASE ${CODE_DIR}/.venv ${CODE_DIR}/.venv
# Copy built package from base image
COPY --from=BASE ${CODE_DIR}/dist ${CODE_DIR}/dist

# Jhub does not support notebook 7 yet, all hell breaks loose if we don't pin it
RUN pip install "notebook<7"
# This goes directly into main jupyter, not poetry env
COPY --chown=${NB_UID}:${NB_GID} build_scripts ./build_scripts
RUN bash build_scripts/install_presentation_requirements.sh


# Install poetry according to
# https://python-poetry.org/docs/#installing-manually
RUN pip install -U setuptools "poetry==$POETRY_VERSION"

WORKDIR /tmp

# Start of HACK: the home directory is overwritten by a mount when a jhub server is started off this image
# Thus, we create a jovyan-owned directory to which we copy the code and then move it to the home dir as part
# of the entrypoint
ENV CODE_DIR=/tmp/code

RUN mkdir $CODE_DIR

COPY --chown=${NB_UID}:${NB_GID} entrypoint.sh $CODE_DIR

RUN chmod +x "${CODE_DIR}/"entrypoint.sh
Expand All @@ -53,13 +94,8 @@ COPY --chown=${NB_UID}:${NB_GID} . $CODE_DIR
# complete code base, including the poetry.lock file
WORKDIR $CODE_DIR

RUN poetry config virtualenvs.in-project true
RUN poetry install --no-interaction --no-ansi
RUN poetry install --no-interaction --no-ansi --with add1
RUN poetry install --no-interaction --no-ansi --with add2
RUN poetry install --no-interaction --no-ansi --with control
RUN poetry install --no-interaction --no-ansi --with offline
# use poetry for package mgmt.
RUN poetry run ipython kernel install --name "tfl-training-rl" --user
# DIRTY HACK
RUN pip install -U "notebook<7" ipykernel
RUN pip install --no-cache-dir dist/*.whl

RUN ipython kernel install --name "tfl-training-rl" --user

RUN jupyter trust notebooks
83 changes: 47 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TransferLab Training: Safe and Efficient RL
# TransferLab Training: Control and Safe and Efficient RL

Welcome to the TransferLab training: Safe and Efficient RL.
Welcome to the TransferLab trainings: Control, Safe and Efficient RL.
This is the readme for the participants of the training.

## During the training
Expand All @@ -17,48 +17,59 @@ You have received this file as part of the training materials.
There are multiple ways of viewing/executing the content.

1. If you just want to view the rendered notebooks,
open `html/index.html` in your browser.
open `html/index.html` in your browser.
2. If you want to execute the notebooks, you will either need to
install the dependencies or use docker.
For running without docker, create a conda environment (with python 3.9),
e.g., with `conda create -n training_rl python=3.9`.
Then, install the dependencies and the package with
```shell
bash build_scripts/install_presentation_requirements.sh
pip install -e .
```

3. If you want to use docker instead, you can build the image locally.
First, set the variable `PARTICIPANT_BUCKET_READ_SECRET` to the secret found in
`config.yaml`, and then build the image with
```shell
docker build --build-arg PARTICIPANT_BUCKET_READ_SECRET=$PARTICIPANT_BUCKET_READ_SECRET -t training_rl .
```
You can then start the container e.g., with
```shell
docker run -it -p 8888:8888 training_rl jupyter notebook
```
4. The data will be downloaded on the fly when you run the notebooks.
5. Finally, for creating source code documentation, you can run
```shell
bash build_scripts/build_docs.sh
```
and then open `docs/build/html/index.html` in your browser.
This will also rebuild the jupyter-book based notebook documentation
that was originally found in the `html` directory.
install the dependencies or use docker.
For running without docker, create a [poetry](https://python-poetry.org/) environment (with python 3.11),
e.g., with `poetry shell`.

6. In case you experience some issues with the rendering when using docker
make sure to add the docker user to xhost. So run on your local machine:
Then, install the dependencies and the package with

```shell
poetry install --with=add1,add2,control,offline
bash build_scripts/install_presentation_requirements.sh
```

3. If you want to use docker instead,
you can build the image locally using:

```shell
docker build -t tfl-training-rl:local .
```

xhost +SI:localuser:docker_user
You can then start the container e.g., with

```shell
docker run -it -p 8888:8888 tfl-training-rl:local jupyter notebook --ip=0.0.0.0
```

and run docker like:
4. Finally, for creating source code documentation, you can run

```shell
bash build_scripts/build_docs.sh
```

and then open `docs/build/html/index.html` in your browser.
This will also rebuild the jupyter-book based notebook documentation
that was originally found in the `html` directory.

6. In case you experience some issues with the rendering when using docker
make sure to add the docker user to xhost. So run on your local machine:

docker run -p 8888:8888 -it --env DISPLAY=$DISPLAY --net=host --privileged --volume /tmp/.X11-unix:/tmp/.X11-unix training_rl bash
```shell
xhost +SI:localuser:docker_user
```

and run docker using:


```shell
docker run -it --rm --privileged --net=host \
--env DISPLAY --volume /tmp/.X11-unix:/tmp/.X11-unix \
tfl-training-rl:local jupyter notebook --ip=0.0.0.0
```

Note that there is some non-trivial logic in the entrypoint that may collide
> **Note** There is some non-trivial logic in the entrypoint that may collide
with mounting volumes to paths directly inside
`/home/jovyan/training_rl`. If you want to do that,
the easiest way is to override the entrypoint or to mount somewhere else
Expand Down
2 changes: 1 addition & 1 deletion build_scripts/install_presentation_requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ BUILD_DIR=$(dirname "$0")

(
cd "${BUILD_DIR}/.." || (echo "Unknown error, could not find directory ${BUILD_DIR}" && exit 255)
pip install jupyter_contrib_nbextensions
pip install --no-cache-dir jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
jupyter nbextensions_configurator enable --user
jupyter nbextension enable equation-numbering/main
Expand Down
3 changes: 3 additions & 0 deletions notebooks/_static/images/20_control_theory_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions notebooks/_static/images/30_optimal_control_methods.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a37e49e

Please sign in to comment.