Skip to content

dsl: Add PETSc functionality #2570

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

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open

dsl: Add PETSc functionality #2570

wants to merge 30 commits into from

Conversation

ZoeLeibowitz
Copy link
Contributor

@ZoeLeibowitz ZoeLeibowitz commented Apr 3, 2025

Work in progress PETSc functionality

TODO before merging:

  • Add parallel tests

@mloubout mloubout added API api (symbolics, types, ...) feature-request labels Apr 3, 2025
Copy link

codecov bot commented Apr 3, 2025

Codecov Report

Attention: Patch coverage is 35.09593% with 1387 lines in your changes missing coverage. Please review.

Project coverage is 85.39%. Comparing base (8fa28c3) to head (6b6ad4f).

Files with missing lines Patch % Lines
devito/petsc/iet/routines.py 17.22% 548 Missing ⚠️
tests/test_petsc.py 13.07% 452 Missing ⚠️
devito/petsc/solve.py 32.12% 112 Missing ⚠️
devito/petsc/types/types.py 51.80% 80 Missing ⚠️
devito/petsc/iet/passes.py 41.74% 59 Missing and 1 partial ⚠️
devito/petsc/types/array.py 59.21% 31 Missing ⚠️
devito/petsc/types/object.py 79.60% 31 Missing ⚠️
devito/petsc/utils.py 54.71% 23 Missing and 1 partial ⚠️
devito/petsc/initialize.py 50.00% 10 Missing ⚠️
devito/symbolics/extended_sympy.py 68.42% 6 Missing ⚠️
... and 12 more

❗ There is a different number of reports uploaded between BASE (8fa28c3) and HEAD (6b6ad4f). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (8fa28c3) HEAD (6b6ad4f)
pytest-gpu-aomp-amdgpuX 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2570      +/-   ##
==========================================
- Coverage   91.30%   85.39%   -5.91%     
==========================================
  Files         245      261      +16     
  Lines       48495    50604    +2109     
  Branches     4261     4326      +65     
==========================================
- Hits        44276    43211    -1065     
- Misses       3521     6667    +3146     
- Partials      698      726      +28     
Flag Coverage Δ
pytest-gpu-aomp-amdgpuX ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines 21 to 90
name: ${{ matrix.name }}-${{ matrix.set }}
runs-on: "${{ matrix.os }}"

env:
DOCKER_BUILDKIT: "1"
DEVITO_ARCH: "${{ matrix.arch }}"
DEVITO_LANGUAGE: ${{ matrix.language }}

strategy:
# Prevent all build to stop if a single one fails
fail-fast: false

matrix:
name: [
pytest-docker-py39-gcc-noomp
]
include:
- name: pytest-docker-py39-gcc-noomp
python-version: '3.9'
os: ubuntu-latest
arch: "gcc"
language: "C"
sympy: "1.12"

steps:
- name: Checkout devito
uses: actions/checkout@v4

- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build docker image
run: |
docker build -f docker/Dockerfile.devito --build-arg base=zoeleibowitz/petsc_image:latest --tag zoeleibowitz/petsc_devito_image:latest .

- 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
id: set-run

- name: Set tests
run : |
echo "TESTS=tests/test_petsc.py" >> $GITHUB_ENV
id: set-tests

- name: Check configuration
run: |
${{ env.RUN_CMD }} python3 -c "from devito import configuration; print(''.join(['%s: %s \n' % (k, v) for (k, v) in configuration.items()]))"

- name: Test with pytest
run: |
${{ env.RUN_CMD }} mpiexec -n 1 pytest --cov --cov-config=.coveragerc --cov-report=xml ${{ env.TESTS }}

- name: Test examples
run: |
${{ env.RUN_CMD }} mpiexec -n 1 python3 examples/petsc/seismic/01_staggered_acoustic.py
${{ env.RUN_CMD }} mpiexec -n 1 python3 examples/petsc/cfd/01_navierstokes.py
${{ env.RUN_CMD }} mpiexec -n 1 python3 examples/petsc/Poisson/01_poisson.py
${{ env.RUN_CMD }} mpiexec -n 1 python3 examples/petsc/Poisson/02_laplace.py
${{ env.RUN_CMD }} mpiexec -n 1 python3 examples/petsc/random/01_helmholtz.py

- name: Upload coverage to Codecov
if: "!contains(matrix.name, 'docker')"
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: ${{ matrix.name }}

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
Copy link
Contributor

@EdCaunt EdCaunt left a comment

Choose a reason for hiding this comment

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

Some comments for now. Will go through some more at a later date


matrix:
name: [
pytest-docker-py39-gcc-noomp
Copy link
Contributor

Choose a reason for hiding this comment

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

Python 3.9 is EOL soon, so this version should get bumped. It would also be worth adding an Omp run


- name: Build docker image
run: |
docker build -f docker/Dockerfile.devito --build-arg base=zoeleibowitz/petsc_image:latest --tag zoeleibowitz/petsc_devito_image:latest .
Copy link
Contributor

Choose a reason for hiding this comment

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

This image should probably be on the main Devito Dockerhub now


- name: Check configuration
run: |
${{ env.RUN_CMD }} python3 -c "from devito import configuration; print(''.join(['%s: %s \n' % (k, v) for (k, v) in configuration.items()]))"
Copy link
Contributor

Choose a reason for hiding this comment

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

Ultra nitpick: fstring

${{ env.RUN_CMD }} mpiexec -n 1 python3 examples/petsc/Poisson/02_laplace.py
${{ env.RUN_CMD }} mpiexec -n 1 python3 examples/petsc/Poisson/03_poisson.py
${{ env.RUN_CMD }} mpiexec -n 1 python3 examples/petsc/Poisson/04_poisson.py
${{ env.RUN_CMD }} mpiexec -n 1 python3 examples/petsc/random/01_helmholtz.py
Copy link
Contributor

Choose a reason for hiding this comment

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

How about naming this folder 'misc' rather than 'random'?

@@ -17,9 +17,11 @@ on:
push:
branches:
- main
- master
Copy link
Contributor

Choose a reason for hiding this comment

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

These additional "master"s need dropping throughout the CI workflows



def initialize(iet):
# should be int because the correct type for argc is a C int
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: comment starts with lowercase

argv = ArgvSymbol(name='argv')
Help = Macro('help')

help_string = c.Line(r'static char help[] = "This is help text.\n";')
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a placeholder?

self.iters = iters
self.kwargs = kwargs
self.coupled = isinstance(injectsolve.expr.rhs.fielddata, MultipleFieldData)
self.args = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: whitespace above this line would improve readability

# the C code cleaner and more modular. This is also a step toward leveraging
# Devito's `reuse_efuncs` functionality, allowing reuse of efuncs when
# they are semantically identical.
objs = frozendict({
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be worth naming this petsc_objs to avoid potential namespace clashes?

self._main_matvec_callback = None
self._main_formfunc_callback = None
self._user_struct_callback = None
# TODO: Test pickling. The mutability of these lists
Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly initialise them to one, then generate tuples for each in a lazy manner?

Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly remove these, then make the properties into cached properties with the requisite machinery to fill them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API api (symbolics, types, ...) feature-request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants