Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
51 changes: 51 additions & 0 deletions .github/workflows/docker-petsc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Publish devito-petsc docker image

permissions:
contents: read

on:
push:
branches:
- petsc # Push events on petsc branch
# TODO: drop this
pull_request:
branches:
- petsc

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
build-args: base=devitocodes/devito:gcc-dev-amd64
platforms: linux/amd64

- name: Remove dangling layers
run: docker system prune -f
14 changes: 5 additions & 9 deletions .github/workflows/pytest-petsc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:

jobs:
pytest:
name: ${{ matrix.name }}-${{ matrix.set }}
name: ${{ matrix.name }}
runs-on: "${{ matrix.os }}"

env:
Expand All @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions devito/petsc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JDBetteridge I moved the petsc imports from requirements.txt to requirements-petsc.txt as you advised. As a result, the petsc dependencies are no longer installed in Dockerfile.devito - which is preferred - but this leads to the following errors (this and this). I've addressed them by wrapping the imports in except ImportError blocks (see also petsc/solver_parameters.py below), in a similar way to how mpi4py is imported in distributed.py. Is this fine? What is best practice? Any suggestions for a longer term solution, particularly as requirements-petsc.txt grows?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you will need to import guard petsctools. And wherever possible you should avoid importing anything PETSc specific if PETSc isn't present on the system. Long term we may want to revisit the module structure, but for now this is fine

petsc_variables = {}
except MissingPetscException:
petsc_variables = {}

from devito.tools import memoized_func

Expand Down Expand Up @@ -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']
Expand Down
8 changes: 6 additions & 2 deletions devito/petsc/solver_parameters.py
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
33 changes: 23 additions & 10 deletions docker/Dockerfile.petsc
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,40 @@
# 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:gcc-dev-amd64

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) \
--with-openblas-lib=$(pkg-config --variable=libdir openblas)/libopenblas.so \
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["."]
Expand Down
1 change: 1 addition & 0 deletions requirements-petsc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
petsctools<=2025.1
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ codepy>=2019.1,<2025
multidict<6.3
anytree>=2.4.3,<=2.13.0
packaging<25.1
petsctools<=2025.1
Loading