-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dockerfile produce functioning container for both Julia and CmdStan
The Dockerfile now produces a separate conda environment were all packages are installed. Furthermore, the compiled stan model is deleted, thus they need to be recompiled inside the container. This was required for the model to work. The Python dependencies are installed to match the exact versions of the environment used to produce the results from the article. These depencies are decribed in the article/requirements.txt. The error propagation notebook now starts with a block that detects if it is run inside the docker container, if so it set the cmdstan path. The Julia setup has been shrink significantly, now it no longer updates the packages, but uses the versions specified in the project.toml file. Unfortunately, the Julia packages is not installed during image build, but this is instead done in the julia_run_all.jl file.
- Loading branch information
Showing
8 changed files
with
1,931 additions
and
1,567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,65 @@ | ||
# Start from a core stack version | ||
# This Dockerfile is used to build the image in which the results | ||
# of the paper can be reproduced. The image is based on the | ||
# Jupyter Data Science Notebook image from Jupyter Docker Stack and | ||
# extends the image with CmdStan, and the Julia environment. | ||
# Furthermore the image uses the exact versions of the libraries, | ||
# that were used to produce the results in the paper. | ||
# We want to thank the Jupyter Docker Stack Recepies as we got a | ||
# lot inspiration from the following recipe: | ||
# https://jupyter-docker-stacks.readthedocs.io/en/latest/using/recipes.html#add-a-custom-conda-environment-and-jupyter-kernel | ||
|
||
# Start from a core stack version, locked the version to ensure reproducibility | ||
FROM quay.io/jupyter/datascience-notebook:2024-05-20 | ||
|
||
ENV CMDSTAN_VERSION=2.31.0 | ||
# Set versions of core software | ||
ENV CMDSTAN_VERSION=2.33.0 | ||
ENV CMDSTANPY_VERSION=1.1.0 | ||
# Name your environment and choose the Python version | ||
ARG env_name=venv_pseudobatch | ||
ARG py_ver=3.10.8 | ||
|
||
# Copy all files from directory to docker image | ||
COPY --chown=${NB_UID}:${NB_GID} . . | ||
|
||
# Install in the default python3 environment | ||
# Install cmdstanpy | ||
RUN pip install --no-cache-dir "cmdstanpy==1.0.4" | ||
# remove the precompile files for pseudobatch error_propagation | ||
RUN rm -f \ | ||
pseudobatch/error_propagation/stan/error_propagation \ | ||
pseudobatch/error_propagation/stan/error_propagation.exe \ | ||
pseudobatch/error_propagation/stan/error_propagation.hpp | ||
|
||
# You can add additional libraries required for notebooks here | ||
RUN mamba create --yes -p "${CONDA_DIR}/envs/${env_name}" \ | ||
python=${py_ver} \ | ||
'ipykernel' \ | ||
'jupyterlab' && \ | ||
mamba clean --all -f -y | ||
|
||
# Install cmdstan | ||
RUN python -m cmdstanpy.install_cmdstan --version "${CMDSTAN_VERSION}" --cores 2 | ||
# Install cmdstanpy and cmdstan inside the environment | ||
RUN mamba run -p "${CONDA_DIR}/envs/${env_name}" mamba install --yes -c conda-forge cmdstanpy=="${CMDSTANPY_VERSION}" cmdstan=="${CMDSTAN_VERSION}" && \ | ||
mamba clean --all -f -y && \ | ||
fix-permissions "${CONDA_DIR}" && \ | ||
fix-permissions "/home/${NB_USER}" | ||
|
||
RUN pip install --no-cache-dir -e ".[error_propagation]" && \ | ||
# Create Python kernel and link it to jupyter | ||
RUN "${CONDA_DIR}/envs/${env_name}/bin/python" -m ipykernel install --user --name="${env_name}" && \ | ||
fix-permissions "${CONDA_DIR}" && \ | ||
fix-permissions "/home/${NB_USER}" | ||
|
||
RUN julia --project=julia-env -e 'using Pkg; pkg"activate"; pkg"precompile"' && \ | ||
# Installing the pseudobatch from local source using pip | ||
RUN "${CONDA_DIR}/envs/${env_name}/bin/pip" install --no-cache-dir -e \ | ||
'.[error_propagation]' | ||
|
||
# Install specific requirements to match versions used when producing the paper | ||
RUN "${CONDA_DIR}/envs/${env_name}/bin/pip" install --no-cache-dir -r article/requirements.txt | ||
|
||
# This changes the custom Python kernel so that the custom environment will | ||
# be activated for the respective Jupyter Notebook and Jupyter Console | ||
# hadolint ignore=DL3059 | ||
RUN /opt/setup-scripts/activate_notebook_custom_env.py "${env_name}" | ||
|
||
USER ${NB_UID} | ||
|
||
# Setup Julia environment for simulations | ||
RUN julia --project=julia-env -e 'using Pkg; Pkg.activate(); Pkg.instantiate()' && \ | ||
chmod -R go+rx "${CONDA_DIR}/share/jupyter" && \ | ||
fix-permissions "${JULIA_PKGDIR}" "${CONDA_DIR}/share/jupyter" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.