Skip to content

JIT build: pass PETSc's include directories to the generated setup.py - #829

Merged
lmoresi merged 2 commits into
developmentfrom
bugfix/jit-petsc-include-dirs
Oct 7, 2026
Merged

lmoresi merged 2 commits into
developmentfrom
bugfix/jit-petsc-include-dirs

Conversation

@lmoresi

@lmoresi lmoresi commented Oct 7, 2026

Copy link
Copy Markdown
Member

Fixes #828.

Since #813, the generated JIT header includes <petscsystypes.h>, but the generated setup.py passed no PETSc include directory. That works only where PETSc's headers are on the compiler's default path (a conda-forge PETSc, as in CI). With a custom PETSc build, every JIT compile failed with 'petscsystypes.h' file not found, so no solver ran.

Change

_petsc_include_dirs() reads PETSC_DIR / PETSC_ARCH from petsc4py.get_config() and returns $PETSC_DIR/include and $PETSC_DIR/$PETSC_ARCH/include (for petscconf.h), keeping only the directories that exist. A prefix install has no arch directory. The generated setup.py appends these to its include dirs. Because setup.py is hashed into the JIT cache key, the key now also follows the PETSc installation, which #813's integer-width change needs.

Tests

tests/test_0021_jit_finds_petsc_headers.py captures the setup.py that a Poisson solve generates. It asserts that the file carries PETSc's include directories, read independently from petsc4py, so it fails on development everywhere, including CI. It also checks that those directories hold the headers the callbacks include, and that a JIT solve compiles and converges.

The adversarial review, run with the #823 branch stacked on this one, found two defects here. Both are fixed on this branch:

  • the first test could not fail on CI;
  • a try/except guarded the hard dependency petsc4py (Charter §5).

Underworld development team with AI support from Claude Code

#813 made the generated callback header include <petscsystypes.h>, so callbacks use
PETSc's configured integer width. The generated setup.py passes no PETSc include
directory, so the build works only where PETSc's headers are on the compiler's
default path: a conda-forge PETSc in the environment, as in CI. With a custom PETSc
build every JIT compile failed with "'petscsystypes.h' file not found".

_petsc_include_dirs() reads PETSC_DIR/PETSC_ARCH from petsc4py and adds
$PETSC_DIR/include and $PETSC_DIR/$PETSC_ARCH/include (petscconf.h).
test_0021 checks that the headers are found and that a JIT solve compiles.

Underworld development team with AI support from Claude Code
…etup.py

petsc4py is a hard dependency and conda's petsc4py has get_config(), so the
try/except around it guarded a state that cannot occur (Charter §5), and
PETSC_DIR is always in the configuration. PETSC_ARCH stays optional: it is
empty for a prefix install.

The test checked the helper's return value and a solve that compiles wherever
the headers sit on the compiler's default path, as they do in CI's conda-forge
PETSc, so it could not fail on CI. It now captures the setup.py the JIT
generates and asserts that it carries PETSc's include directories, read
independently from petsc4py.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Oct 7, 2026

Copy link
Copy Markdown
Member Author

Adversarial review

This branch was reviewed together with #830, which is stacked on it. Two findings, both fixed in 5cb3072:

  • The test could not fail on CI. It checked only the helper's return value, plus a solve that compiles wherever the headers are on the default path, as with CI's conda-forge PETSc. It now captures the generated setup.py and asserts that it carries PETSc's include directories, read independently from petsc4py.
  • A try/except around petsc4py.get_config() guarded a hard dependency (Charter §5). Its stated reason, the conda-forge case, was also wrong.

Checked and sound:

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Solver/JIT tests are incorrectly included in the level-1 selection reserved for checks without solving.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes custom-PETSc JIT compilation failures introduced by #813 by supplying PETSc’s configured header directories.

Changes:

  • Adds existing PETSc include directories to generated setup.py, also incorporating them into the cache key.
  • Adds regression checks for header availability, generated include paths, and solver convergence.
File Description
tests/​test_0021_jit_finds_petsc_headers.py Tests PETSc header discovery and JIT compilation.
src/​underworld3/​utilities/​_jitextension.py Adds PETSc include directories from petsc4py configuration.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.


import underworld3 as uw

pytestmark = [pytest.mark.level_1, pytest.mark.tier_a]
@lmoresi
lmoresi merged commit 8a01e83 into development Oct 7, 2026
3 checks passed
lmoresi added a commit to gthyagi/underworld3 that referenced this pull request Oct 12, 2026
…o picard-warmup-791

Conflicts: up_G2/up_G3 keep underworldcode#794's F1_for_up (newton_pressure_coupling) and
differentiate it with tier 1's diff_wrt_field; the reviews index keeps both
rows. The linearity check's top-level derivative also goes through
diff_wrt_field (the solver census in test_0023).

Underworld development team with AI support from Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants