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

Reduced the number of docker images by one pybamm:latest #3992

Merged
merged 12 commits into from
Apr 14, 2024
27 changes: 4 additions & 23 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ on:
- develop

jobs:
build_docker_images:
build_docker_image:
# This workflow is only of value to PyBaMM and would always be skipped in forks
if: github.repository_owner == 'pybamm-team'
name: Image (${{ matrix.build-args }})
name: Build image
runs-on: ubuntu-latest
strategy:
matrix:
build-args: ["No solvers", "JAX", "IDAKLU", "ALL"]
fail-fast: true
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved

steps:
- name: Checkout
Expand All @@ -33,27 +29,12 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Create tags for Docker images based on build-time arguments
id: tags
run: |
if [ "${{ matrix.build-args }}" = "No solvers" ]; then
echo "tag=latest" >> "$GITHUB_OUTPUT"
elif [ "${{ matrix.build-args }}" = "JAX" ]; then
echo "tag=jax" >> "$GITHUB_OUTPUT"
elif [ "${{ matrix.build-args }}" = "ODES" ]; then
echo "tag=odes" >> "$GITHUB_OUTPUT"
elif [ "${{ matrix.build-args }}" = "IDAKLU" ]; then
echo "tag=idaklu" >> "$GITHUB_OUTPUT"
elif [ "${{ matrix.build-args }}" = "ALL" ]; then
echo "tag=all" >> "$GITHUB_OUTPUT"
fi

- name: Build and push Docker image to Docker Hub (${{ matrix.build-args }})
- name: Build and push Docker image to Docker Hub
uses: docker/build-push-action@v5
with:
santacodes marked this conversation as resolved.
Show resolved Hide resolved
context: .
file: scripts/Dockerfile
tags: pybamm/pybamm:${{ steps.tags.outputs.tag }}
tags: pybamm/pybamm:latest
push: true
platforms: linux/amd64, linux/arm64

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

## Breaking changes

- Removed multiple Docker images. Here on, a single Docker image tagged `pybamm/pybamm:latest` will be provided with both solvers (`IDAKLU` and `JAX`) pre-installed. ([#3992](https://github.com/pybamm-team/PyBaMM/pull/3992))
- Removed support for Python 3.8 ([#3961](https://github.com/pybamm-team/PyBaMM/pull/3961))
- Renamed "ocp_soc_0_dimensional" to "ocp_soc_0" and "ocp_soc_100_dimensional" to "ocp_soc_100" ([#3942](https://github.com/pybamm-team/PyBaMM/pull/3942))
- The ODES solver was removed due to compatibility issues. Users should use IDAKLU, Casadi, or JAX instead. ([#3932](https://github.com/pybamm-team/PyBaMM/pull/3932))
Expand Down
97 changes: 6 additions & 91 deletions docs/source/user_guide/installation/install-from-docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,11 @@ 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:: JAX solver

.. code:: bash

docker pull pybamm/pybamm:jax

.. tab:: IDAKLU solver

.. code:: bash

docker pull pybamm/pybamm:idaklu

.. tab:: All solvers
.. code:: bash

.. code:: bash
docker pull pybamm/pybamm

docker pull pybamm/pybamm:all

Running the Docker container
----------------------------
Expand All @@ -51,35 +33,11 @@ Once you have pulled the Docker image, you can run a Docker container with the P

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
.. code:: bash

.. code:: bash
docker run -it pybamm/pybamm

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.

Expand Down Expand Up @@ -138,52 +96,9 @@ If you want to build the PyBaMM Docker image locally from the PyBaMM source code

conda activate pybamm

Building Docker images with optional arguments
----------------------------------------------

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.
- ``JAX``: For Jax solver.
- ``ALL``: For all the above solvers.

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

.. 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
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved
.. note::

exit
PyBaMM's Docker image comes with all available solvers by default. These solvers include ``IDAKLU`` IDAS solver provided by the SUNDIALS linked with SuiteSparse's KLU and the ``JAX`` solver.


Using Git inside a running Docker container
Expand Down
27 changes: 2 additions & 25 deletions scripts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,12 @@ RUN conda init --all
SHELL ["conda", "run", "-n", "pybamm", "/bin/bash", "-c"]
RUN conda install -y pip

ARG IDAKLU
ARG JAX
ARG ALL

RUN pip install --upgrade --user pip setuptools wheel wget
RUN pip install cmake

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

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

RUN if [ "$ALL" = "true" ]; then \
python scripts/install_KLU_Sundials.py && \
RUN python scripts/install_KLU_Sundials.py && \
rm -rf pybind11 && \
git clone https://github.com/pybind/pybind11.git && \
pip install --user -e ".[all,dev,docs,jax]"; \
fi

RUN if [ -z "$IDAKLU" ] \
&& [ -z "$JAX" ] \
&& [ -z "$ALL" ]; then \
pip install --user -e ".[all,dev,docs]"; \
fi
pip install --user -e ".[all,dev,docs,jax]";

ENTRYPOINT ["/bin/bash"]
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved
Loading