Skip to content

Port test_p2e2p to use expansion toys#278

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/port-test-p2e2p-expansion-toys
Draft

Port test_p2e2p to use expansion toys#278
Copilot wants to merge 2 commits intomainfrom
copilot/port-test-p2e2p-expansion-toys

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 27, 2026

test_p2e2p was written against the low-level P2EFromSingleBox/E2PFromSingleBox/P2P API with manual box index arrays. The expansion toys module (sumpy.toys) provides a cleaner abstraction for exactly this kind of test, as already used in test_translations and test_toy_p2e2e2p.

Changes

  • Replaced low-level kernel calls with t.ToyContext, t.PointSources, t.multipole_expand/t.local_expand, and .eval(). All manual box management arrays (source_boxes, box_source_starts, box_source_counts_nonchild, etc.) are removed — handled internally by the toys layer.

  • Split extra_kwargsextra_source_kwargs + extra_kernel_kwargs as required by ToyContext (kernel parameters like k need to reach both P2E and E2P).

  • Moved expansion construction outside the h-loop — the center and sources are fixed across h-values; only evaluation targets change. The expansion is computed once and reused.

  • Dropped the AxisTargetDerivative gradient test — target derivatives require a separate kernel evaluation and don't fit the one-kernel-at-a-time toys API. The h-convergence check for the primary potential is preserved in full.

  • Removed unused obj_array import (was only needed for actx.from_numpy(obj_array.new_1d(fp.points)), now handled inside _e2p).

# Before: ~80 lines of box arrays, P2EFromSingleBox, E2PFromSingleBox, P2P, actx conversions

# After:
toy_ctx = t.ToyContext(knl, local_expn_class=expn_class,
                       extra_source_kwargs=extra_source_kwargs,
                       extra_kernel_kwargs=extra_kernel_kwargs)
point_sources = t.PointSources(toy_ctx, sources, strengths)
expn = t.local_expand(actx, point_sources, loc_center, order=order, rscale=rscale)

for h in h_values:
    fp = FieldPlotter(loc_center, extent=h, npoints=res)
    pot = expn.eval(actx, fp.points)
    pot_direct = point_sources.eval(actx, fp.points)
    eoc_rec_pot.add_data_point(h, la.norm(pot - pot_direct) / la.norm(pot_direct))

Copilot AI linked an issue Apr 27, 2026 that may be closed by this pull request
…ipole_expand/local_expand)

Agent-Logs-Url: https://github.com/inducer/sumpy/sessions/624fb3c8-77e4-43be-b63c-79e9d59b3b8b

Co-authored-by: inducer <352067+inducer@users.noreply.github.com>
Copilot AI changed the title [WIP] Port test_p2e2p to use the expansion toys Port test_p2e2p to use expansion toys Apr 27, 2026
Copilot AI requested a review from inducer April 27, 2026 16:10
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.

Port test_p2e2p to use the expansion toys

2 participants