Skip to content

Implement kernel rewriting - #279

Open
alexfikl wants to merge 11 commits into
inducer:mainfrom
alexfikl:kernel-rewrite
Open

alexfikl wants to merge 11 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 Outdated

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
Comment thread sumpy/kernel_rewrite.py Outdated
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 Outdated
Comment thread sumpy/test/test_misc.py
Comment thread sumpy/kernel_rewrite.py Outdated
Comment thread sumpy/kernel_rewrite.py Outdated
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 Outdated
Comment thread sumpy/kernel_rewrite.py
@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
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.

3 participants