Skip to content

Implement kernel rewriting - #279

Merged
inducer merged 12 commits into
inducer:mainfrom
alexfikl:kernel-rewrite
Nov 4, 2026
Merged

inducer merged 12 commits into
inducer:mainfrom
alexfikl:kernel-rewrite

Conversation

@alexfikl

@alexfikl alexfikl commented May 8, 2026 •

Copy link
Copy Markdown
Collaborator

This implements rewriting a target kernel (e.g. Stokeslet) in terms of a base kernel (e.g. biharmonic) as a linear constant-coefficient combination of derivatives.

Currently, it just hoists get_deriv_relation_kernel from inducer/pytential#162 with some minimal changes:

  • Clean up the retry logic for the LU factorization.
  • Add a loop on the max order of derivatives.

TODO:

  • Make sure the LU based decomposition works the same as before.
  • Add a bunch of tests for it (based on the tests in pytential).
  • Implement a hopefully better (but likely slower?) purely-symbolic version.
    • Implemented a faster Fourier-based thing instead. It only works with fundamental solutions though (i.e. Stokeslet, but not Stresslet)
  • Hook into documentation.

Needs

cc @isuruf

@alexfikl
alexfikl force-pushed the kernel-rewrite branch 2 times, most recently from c2abca1 to a9f5083 Compare September 4, 2026 08:04
@alexfikl
alexfikl force-pushed the kernel-rewrite branch 3 times, most recently from 8e21ddf to 6065fb6 Compare September 12, 2026 16:31
Comment thread sumpy.html Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved fallback failures, rejected constant-only rewrites, and parameter-symbol mismatches break supported behavior and existing tests.

5 open findings
What changed in this PR

Adds kernel rewriting to express target kernels as constant-coefficient combinations of base-kernel derivatives.

Changes:

  • Implements symbolic Fourier and numerical LU rewriting.
  • Standardizes spatial-constant parameters in kernel PDEs.
  • Adds rewrite tests and documentation.
File Description
sumpy/​tools.py Adds multi-index differentiation.
sumpy/​test/​test_misc.py Updates PDE tests for spatial constants.
sumpy/​test/​test_kernel_rewrite.py Adds rewriting and conditioning tests.
sumpy/​kernel.py Updates PDE parameters and marks unsupported system PDEs.
sumpy/​kernel_rewrite.py Implements rewrite representations and algorithms.
doc/​kernel.rst Includes kernel rewriting documentation.
.basedpyright/​baseline.json Updates type-checking diagnostics.

🧠 Review effort: Balanced


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

Comment thread sumpy/kernel.py Resolved
Comment thread sumpy/kernel_rewrite.py Resolved
Comment thread sumpy/kernel_rewrite.py Outdated
target_system_kernel, idx = None, None

if target_system_kernel is None:
pde_target = target_kernel.get_pde_as_diff_op()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not sure we want to support that.

Comment thread sumpy/kernel_rewrite.py Resolved
Comment thread sumpy/test/test_misc.py Resolved
Comment thread sumpy/kernel_rewrite.py Resolved
Comment thread sumpy/kernel_rewrite.py Resolved
Comment thread sumpy/kernel_rewrite.py Outdated


def rewrite_using_base_kernel(
target_kernel: ScalarKernel,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

kernel and base_kernel?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in f57077c.

Comment thread sumpy/kernel_rewrite.py Resolved
Comment thread sumpy/kernel_rewrite.py Resolved
@alexfikl
alexfikl force-pushed the kernel-rewrite branch 4 times, most recently from 7228321 to 82ef0cd Compare October 17, 2026 12:09
@alexfikl alexfikl mentioned this pull request Oct 24, 2026
5 tasks
@inducer

inducer commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Added a license header to the tests; I'm assuming this was intended. LMK if not. @isuruf @alexfikl

This looks great. Thanks for working on it, both of you!

@inducer
inducer enabled auto-merge (rebase) October 29, 2026 17:00
@inducer

inducer commented Nov 4, 2026

Copy link
Copy Markdown
Owner

The Symengine CI seems to die here. The only "obvious" thing in the log is a zillion warnings about bitcount, which appears to be an mpmath function (?) that was deprecated?

@alexfikl

alexfikl commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator Author

The Symengine CI seems to die here.

It's still dying in the distributed tests (two of them)

2026-11-03T19:54:40.1486721Z FAILED sumpy/test/test_distributed.py::test_against_single_rank[4-3-10000-10000-True] - subprocess.CalledProcessError: Command '['mpiexec', '-np', '4', '--oversubscribe', '-x', 'LD_PRELOAD', '-x', 'SHELL', '-x', 'SELENIUM_JAR_PATH', '-x', 'GITHUB_WORKSPACE', '-x', ..., '/home/runner/work/sumpy/sumpy/.conda-root/envs/testing/bin/python3', '-m', 'mpi4py', '/home/runner/work/sumpy/sumpy/sumpy/test/test_distributed.py']' returned non-zero exit status 1.

with the same

2026-11-03T19:54:40.1458997Z     tree_in_device_memory = comm.bcast(tree_in_device_memory, root=0)
2026-11-03T19:54:40.1459268Z   File "src/mpi4py/MPI.src/Comm.pyx", line 2129, in mpi4py.MPI.Comm.bcast
2026-11-03T19:54:40.1459538Z   File "src/mpi4py/MPI.src/msgpickle.pxi", line 736, in mpi4py.MPI.PyMPI_bcast
2026-11-03T19:54:40.1459806Z   File "src/mpi4py/MPI.src/msgpickle.pxi", line 737, in mpi4py.MPI.PyMPI_bcast
2026-11-03T19:54:40.1460049Z mpi4py.MPI.Exception: MPI_ERR_OTHER: known error not in list

so I'm guessing whatever was happening in the Array.__bool__ PR was some real issue.

a zillion warnings about bitcount, which appears to be an mpmath function (?) that was deprecated?

Yeah, that fix is in sympy main, so it'll probably be in the next version.

EDIT: I told pytest to ignore those deprecation warnings. Might want to add that to ci-support instead? Or just wait it out?

@alexfikl

alexfikl commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

@inducer A wholesome re-run seems to have "fixed" the problem.. 🤷

@inducer
inducer merged commit 025b269 into inducer:main Nov 4, 2026
9 checks passed
@alexfikl
alexfikl deleted the kernel-rewrite branch November 4, 2026 18:32
@alexfikl alexfikl mentioned this pull request Nov 6, 2026
4 of 9 tasks
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.

4 participants