From cd255de728640089099c058e79ac88420322b667 Mon Sep 17 00:00:00 2001 From: ZoeLeibowitz Date: Fri, 24 Oct 2025 11:01:02 +0100 Subject: [PATCH 1/4] ci: Edit Dockerfile.petsc, add docker-petsc.yml and clean up pytest-petsc.yml --- .github/workflows/docker-petsc.yml | 46 ++++++++++++++++++++++++++++++ .github/workflows/pytest-petsc.yml | 14 ++++----- docker/Dockerfile.cpu | 5 ++-- docker/Dockerfile.petsc | 33 ++++++++++++++------- pyproject.toml | 1 + requirements-petsc.txt | 1 + requirements.txt | 1 - 7 files changed, 79 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/docker-petsc.yml create mode 100644 requirements-petsc.txt diff --git a/.github/workflows/docker-petsc.yml b/.github/workflows/docker-petsc.yml new file mode 100644 index 0000000000..234e57ad44 --- /dev/null +++ b/.github/workflows/docker-petsc.yml @@ -0,0 +1,46 @@ +name: Publish devito-petsc docker image + +permissions: + contents: read + +on: + push: + branches: + - petsc # Push events on petsc branch + +jobs: + build-and-push: + name: Build and push devito-petsc image + runs-on: ubuntu-latest + env: + # Use buildkit + DOCKER_BUILDKIT: "1" + + steps: + - name: Checkout devito + uses: actions/checkout@v5 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build & push petsc image + uses: docker/build-push-action@v6 + with: + context: . + file: docker/Dockerfile.petsc + push: true + tags: | + devitocodes/devito-petsc:latest + platforms: linux/amd64 + + - name: Remove dangling layers + run: docker system prune -f \ No newline at end of file diff --git a/.github/workflows/pytest-petsc.yml b/.github/workflows/pytest-petsc.yml index 5851c69594..ab66de4cc0 100644 --- a/.github/workflows/pytest-petsc.yml +++ b/.github/workflows/pytest-petsc.yml @@ -18,7 +18,7 @@ on: jobs: pytest: - name: ${{ matrix.name }}-${{ matrix.set }} + name: ${{ matrix.name }} runs-on: "${{ matrix.os }}" env: @@ -30,17 +30,13 @@ jobs: # Prevent all build to stop if a single one fails fail-fast: false + # To be extended matrix: - name: [ - pytest-docker-py39-gcc-noomp - ] include: - - name: pytest-docker-py39-gcc-noomp - python-version: '3.9' + - name: pytest-petsc os: ubuntu-latest arch: "gcc" language: "C" - sympy: "1.12" steps: - name: Checkout devito @@ -54,11 +50,11 @@ jobs: - name: Build docker image run: | - docker build -f docker/Dockerfile.devito --build-arg base=zoeleibowitz/petsc_image:latest --tag zoeleibowitz/petsc_devito_image:latest . + docker build -f docker/Dockerfile.petsc --tag devito_petsc_image:test . - name: Set run prefix run: | - echo "RUN_CMD=docker run --rm -t -e CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} --name testrun zoeleibowitz/petsc_devito_image:latest" >> $GITHUB_ENV + echo "RUN_CMD=docker run --rm -t -e CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} --name testrun devito_petsc_image:test" >> $GITHUB_ENV id: set-run - name: Set tests diff --git a/docker/Dockerfile.cpu b/docker/Dockerfile.cpu index 8f036badb9..0383176b43 100644 --- a/docker/Dockerfile.cpu +++ b/docker/Dockerfile.cpu @@ -17,7 +17,9 @@ RUN apt-get update && \ # Install for basic base not containing it RUN apt-get install -y wget flex libnuma-dev hwloc curl cmake git \ - autoconf libtool build-essential procps software-properties-common + autoconf libtool build-essential procps software-properties-common \ + pkgconf gfortran libopenblas-serial-dev + # Install gcc RUN if [ -n "$gcc" ]; then \ @@ -43,7 +45,6 @@ RUN cd /tmp && mkdir openmpi && \ cd openmpi && ./autogen.pl && \ mkdir build && cd build && \ ../configure --prefix=/opt/openmpi/ \ - --disable-mpi-fortran \ --enable-mca-no-build=btl-uct --enable-mpi1-compatibility && \ make -j ${nproc} && \ make install && \ diff --git a/docker/Dockerfile.petsc b/docker/Dockerfile.petsc index 056c860688..6a89260f8f 100644 --- a/docker/Dockerfile.petsc +++ b/docker/Dockerfile.petsc @@ -2,21 +2,16 @@ # Dockerfile.petsc: Installs PETSc ############################################################## -# Base image with compilers -# TODO: to be updated, but made some additions to Dockerfile.cpu so need to -# use the one from my dockerhub -ARG base=zoeleibowitz/bases:cpu-gcc +ARG base=devitocodes/devito:cpu-dev FROM $base -RUN apt-get update && apt-get install -y \ - git gfortran pkgconf libopenblas-serial-dev && \ - python3 -m venv /venv && \ - /venv/bin/pip install --no-cache-dir --upgrade pip && \ - /venv/bin/pip install --no-cache-dir --no-binary numpy numpy && \ +USER root + +RUN python3 -m venv /venv && \ mkdir -p /opt/petsc && \ cd /opt/petsc && \ - git clone -b v3.23.0 https://gitlab.com/petsc/petsc.git petsc && \ + git clone -b v3.24.0 https://gitlab.com/petsc/petsc.git petsc && \ cd petsc && \ ./configure --with-fortran-bindings=0 --with-mpi-dir=/opt/openmpi \ --with-openblas-include=$(pkg-config --variable=includedir openblas) \ @@ -24,5 +19,23 @@ RUN apt-get update && apt-get install -y \ PETSC_ARCH=devito_build && \ make all +# Remove existing devito +RUN rm -rf /app/devito/.git + +# Copy Devito from petsc branch +ADD . /app/devito + +# Remove git files +RUN rm -rf /app/devito/.git + +# Mpi4py +RUN eval "$MPI4PY_FLAGS /venv/bin/pip install --no-cache-dir --verbose -r /app/devito/requirements-mpi.txt" + +# Install Devito with petsc requirements +RUN /venv/bin/pip install --no-cache-dir -e /app/devito[extras,tests,petsc] && rm -rf ~/.cache/pip + ENV PETSC_DIR="/opt/petsc/petsc" ENV PETSC_ARCH="devito_build" + +# Switch back to non-root user +USER app diff --git a/pyproject.toml b/pyproject.toml index afa0c02704..91d11df593 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,6 +61,7 @@ mpi = { file = ["requirements-mpi.txt"] } nvidia = { file = ["requirements-nvidia.txt"] } tests = { file = ["requirements-testing.txt"] } extras = { file = ["requirements-optional.txt"] } +petsc = { file = ["requirements-petsc.txt"] } [tool.setuptools.packages.find] where = ["."] diff --git a/requirements-petsc.txt b/requirements-petsc.txt new file mode 100644 index 0000000000..c0d8c425ca --- /dev/null +++ b/requirements-petsc.txt @@ -0,0 +1 @@ +petsctools<=2025.1 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index de28551502..4c9e70b018 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,3 @@ codepy>=2019.1,<2025 multidict<6.3 anytree>=2.4.3,<=2.13.0 packaging<25.1 -petsctools<=2025.1 From 0f2f6646f964414d6f2f735d9a256c725bffd17e Mon Sep 17 00:00:00 2001 From: ZoeLeibowitz Date: Tue, 28 Oct 2025 18:56:28 +0000 Subject: [PATCH 2/4] misc: Add try except except to petsctools import with get_petscvariables --- devito/petsc/config.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/devito/petsc/config.py b/devito/petsc/config.py index e2fe3ed443..e743b0bba4 100644 --- a/devito/petsc/config.py +++ b/devito/petsc/config.py @@ -2,7 +2,13 @@ import ctypes from pathlib import Path -from petsctools import get_petscvariables, MissingPetscException +try: + from petsctools import get_petscvariables, MissingPetscException + petsc_variables = get_petscvariables() +except ImportError: + petsc_variables = {} +except MissingPetscException: + petsc_variables = {} from devito.tools import memoized_func @@ -46,12 +52,6 @@ def core_metadata(): } -try: - petsc_variables = get_petscvariables() -except MissingPetscException: - petsc_variables = {} - - def get_petsc_type_mappings(): try: petsc_precision = petsc_variables['PETSC_PRECISION'] From 95d402d2a757accfd30fb9a4f34e013b242dbe04 Mon Sep 17 00:00:00 2001 From: ZoeLeibowitz Date: Wed, 29 Oct 2025 13:26:18 +0000 Subject: [PATCH 3/4] docker/ci: Update petsc image and wf --- .github/workflows/docker-petsc.yml | 1 + docker/Dockerfile.petsc | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-petsc.yml b/.github/workflows/docker-petsc.yml index 234e57ad44..00d87874f5 100644 --- a/.github/workflows/docker-petsc.yml +++ b/.github/workflows/docker-petsc.yml @@ -40,6 +40,7 @@ jobs: push: true tags: | devitocodes/devito-petsc:latest + build-args: base=devitocodes/devito:gcc-dev-amd64 platforms: linux/amd64 - name: Remove dangling layers diff --git a/docker/Dockerfile.petsc b/docker/Dockerfile.petsc index 6a89260f8f..ced663019c 100644 --- a/docker/Dockerfile.petsc +++ b/docker/Dockerfile.petsc @@ -2,7 +2,7 @@ # Dockerfile.petsc: Installs PETSc ############################################################## -ARG base=devitocodes/devito:cpu-dev +ARG base=devitocodes/devito:gcc-dev-amd64 FROM $base From 17cc296252e1bb50492b54b12e466b3c44d5f15f Mon Sep 17 00:00:00 2001 From: ZoeLeibowitz Date: Thu, 30 Oct 2025 10:59:04 +0000 Subject: [PATCH 4/4] workflows: Trigger docker-petsc wf --- .github/workflows/docker-petsc.yml | 4 ++++ devito/petsc/solver_parameters.py | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-petsc.yml b/.github/workflows/docker-petsc.yml index 00d87874f5..7e782e7606 100644 --- a/.github/workflows/docker-petsc.yml +++ b/.github/workflows/docker-petsc.yml @@ -7,6 +7,10 @@ on: push: branches: - petsc # Push events on petsc branch + # TODO: drop this + pull_request: + branches: + - petsc jobs: build-and-push: diff --git a/devito/petsc/solver_parameters.py b/devito/petsc/solver_parameters.py index 63ea80265b..35ac231f33 100644 --- a/devito/petsc/solver_parameters.py +++ b/devito/petsc/solver_parameters.py @@ -1,7 +1,11 @@ import itertools -from petsctools import flatten_parameters - +try: + from petsctools import flatten_parameters +except ImportError: + # TODO: drop + def flatten_parameters(): + raise ImportError("petsctools is not installed") # NOTE: Will be extended, the default preconditioner is not going to be 'none' base_solve_defaults = {