Skip to content

Add type annotations around sumpy.fmm - #300

Open
alexfikl wants to merge 10 commits into
inducer:mainfrom
alexfikl:type-fmm
Open

Add type annotations around sumpy.fmm#300
alexfikl wants to merge 10 commits into
inducer:mainfrom
alexfikl:type-fmm

Conversation

@alexfikl

Copy link
Copy Markdown
Collaborator

Comment thread sumpy/__init__.py
Comment thread sumpy/__init__.py
Comment on lines +125 to +126
if self.previous_flag is not None or self.previous_no_cache_kernels is not None:
raise RuntimeError("cannot reuse the 'CacheMode' context manager")

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.

pyright was complaining about setting attributes outside of __init__, so I reworked this a bit. It now yells if it's nested like with ... as cm: with cm: ...

Comment thread sumpy/tools.py
Comment thread sumpy/tools.py
Comment thread sumpy/tools.py
Comment thread sumpy/fmm.py

@memoize_method
def multipole_expansion(self, order: int):
def multipole_expansion(self, order: int) -> MultipoleExpansionBase:

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.

I'm not sure about returning the base classes here. It makes sense, but they're currently not implemented very nicely for something like this (e.g. pyright complains MultipoleExpansionBase is not callable because it has no __call__ stub).

Comment thread sumpy/tools.py Outdated
actx: ArrayContext,
fft_app: tuple[Any, FFTBackend],
input_vec: Any,
fft_app: tuple[lp.TranslationUnit | VkFFTApp, FFTBackend],

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 a big fan of this being a tuple (the first and second element could get out of sync?). Any reason to not just do an isinstance?

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.

I agree, that would be nicer.

@alexfikl alexfikl Sep 4, 2026

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.

be09448 refactors this a bit.

Comment thread sumpy/fmm.py Outdated
Comment thread sumpy/fmm.py
Comment thread sumpy/fmm.py Outdated
@alexfikl
alexfikl marked this pull request as ready for review August 19, 2026 18:27
@inducer

inducer commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Thanks for sifting through this!

@alexfikl
alexfikl force-pushed the type-fmm branch 2 times, most recently from 50db89b to 1eaa222 Compare September 4, 2026 08:03
@alexfikl
alexfikl requested a lite review from Copilot September 4, 2026 08:03

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

A few introduced issues can break runtime behavior (string DTypeLike handling in KernelComputation, PoCL/VkFFT skip condition drift, and use of assert for runtime type validation).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR adds/updates type annotations across sumpy.fmm-related code paths and adjusts FFT backend selection plumbing (including tests and docs) to align with recent boxtree typing work.

Changes:

  • Add richer type annotations and @override markers in sumpy/fmm.py and related utilities.
  • Refactor OpenCL FFT helpers to return a backend-specific “app” object directly (Loopy TU vs VkFFTApp) and make backend selection configurable.
  • Update FMM tests to pass an FFTBackend selection explicitly and modernize RNG usage.
File summaries
File Description
sumpy/toys.py Updates get_opencl_fft_app calls to use the new keyword-only shape= argument.
sumpy/tools.py Introduces FFT backend enum/API tweaks and adds type annotations across multiple helpers.
sumpy/test/test_fmm.py Updates tests for typed FFT backend selection and RNG handling.
sumpy/fmm.py Adds extensive typing/override annotations and threads FFT backend selection into tree-independent data.
sumpy/distributed.py Minor whitespace cleanup.
sumpy/array_context.py Import ordering adjustment.
sumpy/init.py Adds type annotations and strengthens CacheMode context-manager behavior.
pyproject.toml Adds pyvkfft to the type optional dependency group and tweaks lint config lists.
doc/conf.py Adds pyvkfft intersphinx mapping and related nitpick_ignore entries.
Review details
  • Files reviewed: 9/10 changed files
  • Comments generated: 3
  • Review effort level: Lite

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

Comment thread sumpy/fmm.py
Comment thread sumpy/test/test_fmm.py
Comment thread sumpy/tools.py Outdated
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