Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerize PyBaMM #3223

Merged
merged 47 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
520750a
Added Dockerfile
arjxn-py Mar 30, 2023
0521436
Merge branch 'pybamm-team:develop' into DockerizePybamm
arjxn-py May 6, 2023
b757ecc
Merge branch 'pybamm-team:develop' into DockerizePybamm
arjxn-py May 12, 2023
10edb94
Merge branch 'develop' into DockerizePybamm
arjxn-py Aug 2, 2023
94b3358
Update Dockerfile
arjxn-py Aug 2, 2023
ce86eb4
Install git only
arjxn-py Aug 2, 2023
8428308
Install build tools
arjxn-py Aug 2, 2023
c8965d2
Use repo to copy pybamm
arjxn-py Aug 4, 2023
90ae2a9
install odes if args passed
arjxn-py Aug 4, 2023
ed1fb10
install odes if `ODES = true`
arjxn-py Aug 4, 2023
f9d15d3
Install jax if `JAX=true`
arjxn-py Aug 4, 2023
be918c8
Update Dockerfile
arjxn-py Aug 7, 2023
d97a57b
Define `IDAKLU` arg
arjxn-py Aug 7, 2023
5f3f288
Merge branch 'DockerizePybamm' of https://github.com/arjxn-py/PyBaMM …
arjxn-py Aug 7, 2023
3ce9673
Modify for IDAKLU
arjxn-py Aug 8, 2023
96cc0b1
Using python3.9 for IDAKLU
arjxn-py Aug 12, 2023
63337e3
Try using venv
arjxn-py Aug 12, 2023
aa4b83f
Trying python3.11-dev
arjxn-py Aug 12, 2023
9991cbc
Squash previous 3 commits
arjxn-py Aug 12, 2023
83c7df0
Using `ubuntu:22.04` as base image
arjxn-py Aug 12, 2023
89c2ba7
Using `continuumio/miniconda3` as base
arjxn-py Aug 12, 2023
5d35c8e
Create a non-root user to avoid conflicts
arjxn-py Aug 12, 2023
b520197
Again add all ARGS
arjxn-py Aug 12, 2023
2fda58f
edit entrypoint
arjxn-py Aug 12, 2023
701e45f
Start documenting Docker
arjxn-py Aug 12, 2023
a226530
Add initial documentation for docker
arjxn-py Aug 12, 2023
3eca42d
Add `nox` to `[dev]`
arjxn-py Aug 12, 2023
6e481b4
Update Dockerfile
arjxn-py Aug 12, 2023
1a3107e
Squash merge
arjxn-py Aug 12, 2023
769bf40
Merge branch 'develop' into DockerizePybamm
arjxn-py Aug 12, 2023
a285352
style: pre-commit fixes
pre-commit-ci[bot] Aug 12, 2023
589912f
Add build image from source instructions
arjxn-py Aug 15, 2023
70e05aa
Add optional arg to doc
arjxn-py Aug 16, 2023
2c0f1cc
Apply suggestions from code review
arjxn-py Aug 19, 2023
8fd0f3f
Move Dockerfile to `scripts/`
arjxn-py Aug 22, 2023
c1d41e0
Apply suggestions from code review
arjxn-py Aug 23, 2023
0e54d8f
Add instructions to use vscode with docker
arjxn-py Aug 23, 2023
64506fe
Merge branch 'DockerizePybamm' of https://github.com/arjxn-py/PyBaMM …
arjxn-py Aug 23, 2023
d885cbe
Make tabs for different solvers
arjxn-py Aug 23, 2023
5ea9b8a
Trigger docs build
arjxn-py Aug 23, 2023
3b0d4fa
Formatting
Saransh-cpp Aug 23, 2023
37e6f38
Format again
Saransh-cpp Aug 23, 2023
0d2a61a
Make `ALL` arg
arjxn-py Aug 24, 2023
abb51e5
Modify docs for `ALL` arg
arjxn-py Aug 24, 2023
ba88308
Apply suggestions from code review
arjxn-py Aug 24, 2023
a058467
Arrange local build of solvers into tabs & Squash
arjxn-py Aug 24, 2023
c0d7abf
Apply suggestions from code review
Saransh-cpp Aug 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Dockerfile
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
FROM continuumio/miniconda3:latest

WORKDIR /

# Install the necessary dependencies
RUN apt-get update && apt-get -y upgrade
RUN apt-get install -y libopenblas-dev gcc gfortran graphviz git make g++ build-essential cmake
RUN rm -rf /var/lib/apt/lists/*

RUN useradd -m -s /bin/bash pybamm
USER pybamm

WORKDIR /home/pybamm/

# Clone project files from Git repository
RUN git clone https://github.com/pybamm-team/PyBaMM.git

WORKDIR /home/pybamm/PyBaMM

ENV CMAKE_C_COMPILER=/usr/bin/gcc
ENV CMAKE_CXX_COMPILER=/usr/bin/g++
ENV CMAKE_MAKE_PROGRAM=/usr/bin/make
ENV SUNDIALS_INST=/home/pybamm/.local
ENV LD_LIBRARY_PATH=/home/pybamm/.local/lib:

ARG IDAKLU
ARG ODES
ARG JAX
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved

RUN conda create -n pybamm python=3.9
RUN conda init --all
SHELL ["conda", "run", "-n", "pybamm", "/bin/bash", "-c"]
RUN conda install -y pip

RUN if [ "$IDAKLU" = "true" ]; then \
pip install --upgrade --user pip setuptools wheel wget && \
pip install cmake==3.22 && \
python scripts/install_KLU_Sundials.py && \
git clone https://github.com/pybind/pybind11.git && \
pip install --user -e ".[all,dev]"; \
fi

RUN if [ "$ODES" = "true" ]; then \
pip install cmake==3.22 && \
pip install --upgrade --user pip wget && \
python scripts/install_KLU_Sundials.py && \
pip install --user -e ".[all,odes,dev]"; \
fi

RUN if [ "$JAX" = "true" ]; then \
pip install --user -e ".[jax,all,dev]";\
fi

RUN pip install --user -e ".[all]"

ENTRYPOINT ["/bin/bash"]
1 change: 1 addition & 0 deletions docs/source/user_guide/installation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,4 @@ Installing a specific version? Installing from source? Check the advanced instal
windows
windows-wsl
install-from-source
install-from-docker
129 changes: 129 additions & 0 deletions docs/source/user_guide/installation/install-from-docker.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
Install using Docker (developer install)
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved
=========================================

.. contents::

This page describes the build and installation of PyBaMM from the source code, available on GitHub. Note that this is **not the recommended approach for most users** and should be reserved to people wanting to participate in the development of PyBaMM, or people who really need to use bleeding-edge feature(s) not yet available in the latest released version. If you do not fall in the two previous categories, you would be better off installing PyBaMM using pip or conda.

Prerequisites
-------------
Before you begin, make sure you have Docker installed on your system. You can download and install Docker from the official `Docker website <https://www.docker.com/get-started/>`_.
Ensure Docker installation by running :

.. code:: bash

docker --version

Pulling the Docker Image
Saransh-cpp marked this conversation as resolved.
Show resolved Hide resolved
------------------------
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved
Use the following command to pull the PyBaMM Docker image from Docker Hub:

.. code:: bash

docker pull pybamm/pybamm:latest

Running the Docker Container
Saransh-cpp marked this conversation as resolved.
Show resolved Hide resolved
----------------------------

Once you have pulled the Docker image, you can run a Docker container with the PyBaMM environment:

1. In your terminal, use the following command to start a Docker container from the pulled image:

.. code-block:: bash

docker run -it pybamm/pybamm:latest

2. You will now be inside the Docker container's shell. You can use PyBaMM and its dependencies as if you were in a virtual environment.

3. You can execute PyBaMM-related commands, run tests develop & contribute from the container.

Exiting the Docker Container
Saransh-cpp marked this conversation as resolved.
Show resolved Hide resolved
---------------------------
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved

To exit the Docker container's shell, you can simply type:

.. code-block:: bash

exit

This will return you to your host machine's terminal.

Building Docker Image Locally from Source
Saransh-cpp marked this conversation as resolved.
Show resolved Hide resolved
------------------------------------------
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved

If you want to build the PyBaMM Docker image locally from the PyBaMM source code, follow these steps:

1. Clone the PyBaMM GitHub repository to your local machine if you haven't already:

.. code-block:: bash

git clone https://github.com/pybamm-team/PyBaMM.git

2. Change into the PyBaMM directory:

.. code-block:: bash

cd PyBaMM

3. Build the Docker image using the following command:

.. code-block:: bash

docker build -t pybamm .

4. Once the image is built, you can run a Docker container using:

.. code-block:: bash

docker run -it pybamm

Building Docker Images with Optional Args
Saransh-cpp marked this conversation as resolved.
Show resolved Hide resolved
-----------------------------------------

When building the PyBaMM Docker images locally, you have the option to include specific solvers by using optional arguments. These solvers include:

- IDAKLU: For IDA solver provided by the SUNDIALS plus KLU.
- ODES: For scikits.odes solver for ODE & DAE problems.
- JAX: For Jax solver.
Saransh-cpp marked this conversation as resolved.
Show resolved Hide resolved

To build the Docker images with optional arguments, you can follow these steps for each solver:

Build Docker Image with IDAKLU Solver
Saransh-cpp marked this conversation as resolved.
Show resolved Hide resolved
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1. Follow the same steps as above to clone the PyBaMM repository and navigate to the source code directory.

3. Build the Docker image for IDAKLU using the following command:

.. code-block:: bash

docker build -t pybamm:idaklu --build-arg IDAKLU=true .

Build Docker Image with ODES Solver
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Saransh-cpp marked this conversation as resolved.
Show resolved Hide resolved

1. Follow the same steps as above to clone the PyBaMM repository and navigate to the source code directory.

2. Build the Docker image for ODES using the following command:

.. code-block:: bash

docker build -t pybamm:odes --build-arg ODES=true .

Build Docker Image with JAX Solver
Saransh-cpp marked this conversation as resolved.
Show resolved Hide resolved
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1. Follow the same steps as above to clone the PyBaMM repository and navigate to the source code directory.

2. Build the Docker image for JAX using the following command:

.. code-block:: bash

docker build -t pybamm:jax --build-arg JAX=true .


After building the Docker images with the desired solvers, use the ``docker run`` command followed by the desired image name. For example, to run a container from the image built with IDAKLU solver:

.. code-block:: bash

docker run -it pybamm:idaklu
brosaplanella marked this conversation as resolved.
Show resolved Hide resolved
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ def compile_KLU():
],
"dev": [
"pre-commit", # For code style checking
"ruff", # For code style auto-formatting
"ruff", # For code style auto-formatting
"nox", # For running testing sessions
],
"pandas": [
"pandas>=0.24",
Expand Down
Loading