Cadet in JupyterLab with Docker

Hi there,
I’ve been trying to get cadet to run in my Jupyterlab via a docker image. Alas due to the requirement of the install path of cadet I have problems getting it to run. The install worked, but I’m not sure how to specify the path. Has anyone successfully installed cadet via docker? Could anyone help me out or share the docker image?
Cheers, Anja

Hi Anja,

running CADET inside docker is possible, but the call from Python outside Docker to CADET inside docker isn’t wrapped yet. It’s on my todo list, but not super high up because so far other solutions seemed better to me. :sweat_smile:

Option 1 is to run everything in a Docker container. So put the JupyterLab in the container, install CADET inside the container and then Python in the container will find CADET directly by path and you can use the interface as is.

Option 2 is to install CADET via conda/mamba/binary-copy the way you installed JupyterLab, but I guess that’s not an option, otherwise you probably wouldn’t ask about Docker :slight_smile:

So, if neither of these work for you we can look into wrapping the call to a Docker container from within Python. It’ll be significantly slower than both other options for two reasons: it will require spawning a container every time you call CADET* and it can not use the CAPI which we just added with CADET v5.0.1 and CADET-Python v1.0.1 which seem to reduce simulation times by 10% to 42-fold.

*thinking about it, we might be able to have a persistent container that just waits for calls, but that might cause more problems. and it might be an antipattern.

2 Likes

Hi Anja,

the thought didn’t leave my head (also I’m procrastinating creating a presentation), so I made a CADET-Python-docker-adapter. If you need info on how to install a custom version of CADET-Python you can check out our guide. This should get you started with CADET-Python. I’ve also created a branch for CADET-Process, but that one’s not tested and it’s getting late here.

Hi Ronald,
thank you very much for the detailes answer. I’m assuming Option 1 is what you have running in Jülich? That’s what I tried, but I wasn’t sure how to specify the cadet path since it’s not local…

That’s my docker image

FROM registry.access.redhat.com/ubi8/python-38

ARG NEXUS_HOST
ARG NEXUS_INDEX

USER root


RUN mkdir -p /opt/app-root/src/work

COPY requirements.txt /opt/app-root/src
COPY opc_server /opt/app-root/src/work/opc_server
COPY ps_projects /opt/app-root/src/work/ps_projects

WORKDIR /opt/app-root/src

ENV PYTHONPATH=$PYTHONPATH:/opt/app-root/src \
    NPM_CONFIG_PREFIX=/opt/app-root \
    NODE_OPTIONS=--max-old-space-size=4096

USER 1001

RUN pip install --upgrade pip && \ 
    pip install -r requirements.txt 

USER root

COPY run.sh /opt/app-root/run.sh
COPY jupyter_notebook_config.json /opt/app-root/src/.jupyter/jupyter_notebook_config.json


RUN chown -R 1001 /opt/app-root/src && \
    chgrp -R 0 /opt/app-root/src && \
    chmod -R g=u /opt/app-root/src && \
    chmod +x /opt/app-root/run.sh && \
    chmod g+w /etc/passwd && \
    chmod -R g+w /opt/app-root/src

USER 1001

EXPOSE 8080

ENTRYPOINT [ "/opt/app-root/run.sh" ]

CMD [ "jupyter", "lab","--debug" ]

Hi Anja,

One question back: where do you install CADET in your Docker image? Because I don’t see either a call to conda/mamba/micromamba to install it from conda-forge, nor the code to compile it from source. Do you copy it over during one of the three COPY calls?

  • requirements.txt makes sense (but only installs pip-packages, CADET-Core is only on conda-forge)
  • ps_projects is probably your python projects(?)
  • opc_server I can’t guess.

For reference, here are two Dockerfiles I use:

Here is the Dockerfile for the jupyter.cadet-web:

FROM jupyter/scipy-notebook:hub-4.0.2

RUN rm -rf ${HOME}/work

# CADET needs to be installed in the base environment for it to be found automatically within the jupyter lab
RUN mamba install -c conda-forge jupyterlab jupyterlab-git jupytext jupyterlab-myst jupyter-resource-usage ipywidgets ipykernel cadet==5.0.0
RUN pip install environment_kernels nbgitpuller

#####################
# CADET LATEST KERNEL
#####################

# name your environment and choose the python version
ARG cadet_env=CADET
ARG cadet_py_ver=3.11

# you can add additional libraries you want mamba to install by listing them below the first line and ending with "&& \"
RUN mamba create --yes -p "${CONDA_DIR}/envs/${cadet_env}" python=${cadet_py_ver} \
    'ipython' \
    'ipykernel' \
    'nb_conda_kernels' \
    'ipympl' 'imageio' 'openpyxl' 'scipy' \
    'botorch==0.11.3' 'ax-platform==0.4.1' \
    'cadet==5.0.0' -c conda-forge && \
    mamba clean --all -f -y


# alternatively, you can comment out the lines above and uncomment those below
# if you'd prefer to use a YAML file present in the docker build context

# COPY --chown=${NB_UID}:${NB_GID} environment.yml "/home/${NB_USER}/tmp/"
# RUN cd "/home/${NB_USER}/tmp/" && \
#     mamba env create -p "${CONDA_DIR}/envs/${planalyze_env}" -f environment.yml && \
#     mamba clean --all -f -y

# create Python kernel and link it to jupyter
# NOTE: Contrary to popular instruction, we do not install it as --user since we use containers and our home directory is a docker volume.

USER root
RUN "${CONDA_DIR}/envs/${cadet_env}/bin/python" -m ipykernel install --name="${cadet_env}" --display-name="${cadet_env}" && \
    fix-permissions "${CONDA_DIR}" && \
    fix-permissions "/home/${NB_USER}"
	
RUN "${CONDA_DIR}/envs/${cadet_env}/bin/pip" install --quiet --no-cache-dir 'opencv-python' 'customtkinter'

# As of 2024-Oct-29, CADET-Process has changes in the dev branch that we need for the workshop, so we install the current dev commit 8d6b8161e87ed089edb59167f36cb928365d01cb

RUN "${CONDA_DIR}/envs/${cadet_env}/bin/pip" install --quiet --no-cache-dir 'git+https://github.com/fau-advanced-separations/CADET-Process.git@8d6b8161e87ed089edb59167f36cb928365$

If you need a custom-build CADET in your Docker container, you can use this Dockerfile as a template:

ARG MAMBA_VERSION=1.5.8
FROM mambaorg/micromamba:${MAMBA_VERSION}-noble AS base

# Prevents Python from writing pyc files.
ENV PYTHONDONTWRITEBYTECODE=1

# Keeps Python from buffering stdout and stderr to avoid situations where
# the application crashes without emitting any logs due to buffering.
ENV PYTHONUNBUFFERED=1

WORKDIR /cadet

USER root

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update

RUN apt-get -y install build-essential cmake libhdf5-dev libsuperlu-dev intel-mkl git git-lfs libeigen3-dev && apt-get clean

RUN git clone https://github.com/cadet/CADET-core CADET

RUN mkdir -p CADET/build 

WORKDIR CADET/build

SHELL ["/bin/bash", "-c"]

ENV MKLROOT=/opt/intel/mkl

RUN cmake -DCMAKE_INSTALL_PREFIX="../install" -DBLA_VENDOR=Intel10_64lp_seq ../

RUN make -j $(lscpu | grep 'CPU(s)' | head -n 1 | cut -d ':' -f2 | tr -d ' ') install

USER $MAMBA_USER

RUN ../install/bin/cadet-cli --version && ../install/bin/createLWE && ../install/bin/cadet-cli LWE.h5

COPY --chown=$MAMBA_USER:$MAMBA_USER environment.yml /tmp/environment.yml

RUN micromamba install -y -n base -f /tmp/environment.yml && \
    micromamba clean --all --yes

But I haven’t tested that one together with jupyter lab, yet.

Hi Ronald,
the python-38 doesn’t include conda/ mamba, I installed cadet via the requirements file with pip, and Jenkins said:

Collecting cadet (from -r requirements.txt (line 17))
  Downloading CADET-0.10-py3-none-any.whl.metadata (1.8 kB)
Successfully installed CADET-Process-0.7.3 CADET-Python-0.14.1 cadet-0.10

But I actually planned on creating a separate docker with jupyter for cadet, so I can install it via conda/mamba and don’t have to use crutches…
You’re right, opc server and the projects folder are folders with projects from myself and colleagues
Thank you very much for your help!

Aaah, there we go. This one’s on us. The pip-package cadet-0.10 is not actually CADET-Core, but an old version of CADET-Python that we are currently debating how to re-structure. I know it’s terribly misleading to have a “cadet” package that isn’t cadet, but it has historic reasons and we’re in the process of improving it. Sorry about that. So yes, that is why you did not have CADET installed.

Good luck with the new Jupyter+CADET Docker image. I hope the Dockerfiles I shared will be of help. If you need further help please let us know.

1 Like