diff --git a/.github/workflows/docker-petsc.yml b/.github/workflows/docker-petsc.yml new file mode 100644 index 0000000000..7e782e7606 --- /dev/null +++ b/.github/workflows/docker-petsc.yml @@ -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 \ 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/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'] 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 = { diff --git a/docker/Dockerfile.petsc b/docker/Dockerfile.petsc index 056c860688..ced663019c 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: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) \ @@ -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