Skip to content

Conversation

@leo-collins
Copy link
Contributor

@leo-collins leo-collins commented Sep 26, 2025

Simplifies interpolation code and introduces new features. So far:

  • Interpolator becomes an internal object. We have removed the __new__ method and dispatch instead with a get_interpolator function. The public API is to call assemble on a symbolic interpolate as detailed in the manual.
  • Arguments to interpolate are no longer silently renumbered. See Stop renumbering arguments in the expression to interpolate #4582 for details.
  • Removed frozen_interpolator.

New features:

  • Implemented assembly of cross-mesh interpolation operators, both forward and adjoint.
  • We can now matfree adjoint interpolate cross-mesh and VomOntoVom.
  • Removed interp_data dictionary in favour of the InterpolateOptions dataclass. We get type hinting, better IDE support, single source of truth for these options.

@leo-collins leo-collins changed the title Leo/refactor interpolate refactor interpolation Sep 26, 2025
@connorjward
Copy link
Contributor

@leo-collins this looks like it includes changes from the other ongoing interpolation PRs. This will be much easier to review if you point this PR at that branch instead of main. Then we are only seeing the new changes.

@leo-collins leo-collins force-pushed the leo/refactor_interpolate branch from deb0a8c to 4097207 Compare September 26, 2025 13:19
@pbrubeck pbrubeck changed the base branch from main to pbrubeck/interp-adjoint-explicit September 26, 2025 13:33
@pbrubeck
Copy link
Contributor

  • Interpolator becomes an internal object. I removed the __new__ method and dispatch instead with a _get_interpolator function.

This is fine, but we might want to preserve a user-facing interface for reusable interpolators.

@pbrubeck pbrubeck force-pushed the pbrubeck/interp-adjoint-explicit branch 7 times, most recently from 210bae0 to 8d631f8 Compare September 30, 2025 21:56
Copy link
Contributor

@connorjward connorjward left a comment

Choose a reason for hiding this comment

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

I haven't reviewed this in great detail but this seems really good!

for indices, form in firedrake.formmanipulation.split_form(expr):
if isinstance(form, ufl.ZeroBaseForm):
# Get sub-interpolators and sub-bcs for each block
Isub: dict[tuple[int, int], tuple[Interpolator, list[DirichletBC]]] = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great idea. Big fan.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan. Why can we not have the BCs passed on to the Interpolator?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess that's just a matter of taste. We don't generate code for the boundary conditions so stashing things on the Interpolator is less important.

I was specifically praising the use of type hints to make an extremely complex data structure clear.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can't change the BCs on matrices on repeated assembly calls, or can we?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also the tuple[int, int] could in some cases just be tuple[int]

Copy link
Contributor

Choose a reason for hiding this comment

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

We can't change the BCs on matrices on repeated assembly calls, or can we?

Good point. I'm not sure. We switch the lgmaps out at runtime so feasibly it's OK to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thought was that BCs should be passed to assemble, like we do for all other forms

Copy link
Contributor

@connorjward connorjward left a comment

Choose a reason for hiding this comment

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

.

Copy link
Member

@dham dham left a comment

Choose a reason for hiding this comment

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

subject to checking that adjoint interpolation on mixed spaces is really correct, this is great. thanks.

sub_tensor.assign(sum(self[i]._interpolate(*function, adjoint=adjoint, **kwargs)
for i in self if i[0] == k))
return output
Isub[indices] = (get_interpolator(form), sub_bcs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we not do this instead?

Suggested change
Isub[indices] = (get_interpolator(form), sub_bcs)
Isub[indices] = get_interpolator(form, bcs=sub_bcs)

Copy link
Contributor

Choose a reason for hiding this comment

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

Or if that is not your intended design, I suggest we enable something like this

Suggested change
Isub[indices] = (get_interpolator(form), sub_bcs)
Isub[indices] = get_assembler(form, bcs=sub_bcs)

Copy link
Contributor

@pbrubeck pbrubeck Nov 18, 2025

Choose a reason for hiding this comment

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

A third option is to do something like

Suggested change
Isub[indices] = (get_interpolator(form), sub_bcs)
Isub[indices] = partial(get_interpolator(form).assemble, bcs=sub_bcs)

@leo-collins leo-collins force-pushed the leo/refactor_interpolate branch from b7368d7 to b5f8c0e Compare November 20, 2025 12:34
@leo-collins leo-collins changed the title refactor interpolation Remove Interpolator from public API and other interpolation refactoring Nov 20, 2025
@dham dham merged commit b7bd072 into main Nov 20, 2025
11 of 19 checks passed
@dham dham deleted the leo/refactor_interpolate branch November 20, 2025 16:28
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.

5 participants