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 all 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
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
202 changes: 202 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,202 @@
Install from source (Docker)
============================

.. 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
------------------------
Use the following command to pull the PyBaMM Docker image from Docker Hub:

.. tab:: No optional solver

.. code:: bash

docker pull pybamm/pybamm:latest

.. tab:: Scikits.odes solver

.. code:: bash

docker pull pybamm/pybamm:odes

.. tab:: JAX solver

.. code:: bash

docker pull pybamm/pybamm:jax

.. tab:: IDAKLU solver

.. code:: bash

docker pull pybamm/pybamm:idaklu

.. tab:: All solvers

.. code:: bash

docker pull pybamm/pybamm:all

Running the Docker container
----------------------------

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:

.. tab:: Basic

.. code:: bash

docker run -it pybamm/pybamm:latest

.. tab:: ODES Solver

.. code:: bash

docker run -it pybamm/pybamm:odes

.. tab:: JAX Solver

.. code:: bash

docker run -it pybamm/pybamm:jax

.. tab:: IDAKLU Solver

.. code:: bash

docker run -it pybamm/pybamm:idaklu

.. tab:: All Solver
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved

.. code:: bash

docker run -it pybamm/pybamm:all

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
----------------------------

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
-----------------------------------------

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 -f scripts/Dockerfile .

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

.. code-block:: bash

docker run -it pybamm

5. Activate PyBaMM development environment inside docker container using:

.. code-block:: bash

conda activate pybamm

Building Docker images with optional args
-----------------------------------------

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.
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved
- ``ALL``: For all the above solvers.

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

.. tab:: Scikits.odes solver

.. code-block:: bash

docker build -t pybamm:odes -f scripts/Dockerfile --build-arg ODES=true .

.. tab:: JAX solver

.. code-block:: bash

docker build -t pybamm:jax -f scripts/Dockerfile --build-arg JAX=true .

.. tab:: IDAKLU solver

.. code-block:: bash

docker build -t pybamm:idaklu -f scripts/Dockerfile --build-arg IDAKLU=true .

.. tab:: All solvers

.. code-block:: bash

docker build -t pybamm:all -f scripts/Dockerfile --build-arg ALL=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 all optional solvers:

.. code-block:: bash

docker run -it pybamm:all

Activate PyBaMM development environment inside docker container using:

.. code-block:: bash

conda activate pybamm

If you want to exit the Docker container's shell, you can simply type:

.. code-block:: bash

exit

Using Visual Studio Code Inside a Running Docker Container
----------------------------------------------------------

You can easily use Visual Studio Code inside a running Docker container by attaching it directly. This provides a seamless development environment within the container. Here's how:

1. Install the "Docker" extension from Microsoft in your local Visual Studio Code if it's not already installed.
2. Pull and run the Docker image containing PyBaMM development environment.
3. In your local Visual Studio Code, open the "Docker" extension by clicking on the Docker icon in the sidebar.
4. Under the "Containers" section, you'll see a list of running containers. Right-click the running PyBaMM container.
5. Select "Attach Visual Studio Code" from the context menu.
6. Visual Studio Code will now connect to the container, and a new VS Code window will open up, running inside the container. You can now edit, debug, and work on your code using VS Code as if you were working directly on your local machine.
65 changes: 65 additions & 0 deletions scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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
ARG ALL

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 if [ "$ALL" = "true" ]; then \
pip install cmake==3.22 && \
pip install --upgrade --user pip setuptools wheel wget && \
python scripts/install_KLU_Sundials.py && \
git clone https://github.com/pybind/pybind11.git && \
pip install --user -e ".[all,dev,jax,odes]"; \
fi

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

ENTRYPOINT ["/bin/bash"]
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