Repository navigation
Negate a contracted Interpolate with free arguments as a form - #550
Merged
Merged
Conversation
Interpolate(v, cofunction) is a 1-form, but _value_parent_type follows the target space, which is primal, so negating or scaling it gave an expression. Subtracting it from a Form then raised a TypeError. Return BaseForm when the dual slot contracts the value and free arguments remain. Interpolate(v, V) and the 0-form Interpolate(u, cofunction) stay expressions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 * Coargument and sums of Coarguments are FormSums, so checking the type of the dual slot treated their output as contracted, and negation gave a FormSum. Check for a Coargument among the arguments of the dual slot instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 4, 2026
Member
|
This looks good to me. It doesn't interfere with any of the FFCx/DOLFINx developments, as we haven't planned how to do |
jorgensd
pushed a commit
that referenced
this pull request
Nov 25, 2026
…574) * Negate a contracted Interpolate with free arguments as a form (#550) * Negate a contracted Interpolate with free arguments as a form Interpolate(v, cofunction) is a 1-form, but _value_parent_type follows the target space, which is primal, so negating or scaling it gave an expression. Subtracting it from a Form then raised a TypeError. Return BaseForm when the dual slot contracts the value and free arguments remain. Interpolate(v, V) and the 0-form Interpolate(u, cofunction) stay expressions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Treat a scaled Coargument dual slot as a free output 2 * Coargument and sums of Coarguments are FormSums, so checking the type of the dual slot treated their output as contracted, and negation gave a FormSum. Check for a Coargument among the arguments of the dual slot instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 1b8d1e2) * Keep release interpolation target selection in the backport * Fix dual-slot form argument counting (#527) * Fix dual-slot form argument counting * Compare the stored function space in Interpolate.__eq__ Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * Fix dual-slot form argument handling * Remove outer_form argument plumbing * Materialize dual-slot arguments * Annotate delayed imports * Contract the highest-numbered argument of a form dual slot A form dual slot now contracts its highest-numbered primal argument, as the left operand of an Action does, so Interpolate(u, F) numbers its free arguments like Action(F, Interpolate(u, V)), starting at 0. Coarguments in the slot stay free. The stored slot is renumbered once, at construction, and argument analysis reads it back. BaseFormOperatorDerivative rejects duplicate argument numbers, and apply_derivatives numbers the direction after the highest operator argument instead of after the argument count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Simplify the contracted argument renumbering Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Test that dual-slot contraction ignores numbering gaps Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Keep arguments contracted inside a dual slot when renumbering Renumbering the slot's own arguments with replace could rename one onto an argument that an Action inside the slot contracts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Contract a form dual slot as an Action does Renumbering the free arguments in the constructor rewrote the user's form with replace, which needed _contained_arguments to avoid arguments that inner Actions contract. That traversal was exponential in the depth of shared subexpressions. The free arguments now keep their numbers, and N(u; F) contracts the argument that an Action would. If the primal slots use number 0, the output of N is numbered last, so N is the left operand and F's lowest argument is contracted. Otherwise F is the left operand and its highest argument is contracted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com> (cherry picked from commit 6a89eab) * Revert "Fix dual-slot form argument counting (#527)" This reverts commit ca2a2a7. * Drop the scaled-Coargument regression from the backport It tests the target space chosen for a FormSum dual slot, which #527 fixed and release does not have. It fails on release with or without #550. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Alias datetime as dt in the docs configuration Ruff 0.17 flags a plain datetime import. main made the same change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Let
d = Interpolate(v, cofunction), wherevis a test function. This is a 1-form, but_value_parent_typefollows the target space, which is primal, so-dwas aProduct, and for aFormF,F - draisedTypeError: unsupported operand type(s) for +: 'Form' and 'Product'.Interpolate(u, V)ProductProductInterpolate(v, V)ProductProductInterpolate(u, 2 * coargument)ProductProductInterpolate(u, cofunction)ProductProductInterpolate(v, cofunction)ProductFormSumInterpolate(u, form)ProductFormSumEvidence
test_negation_of_contracted_interpolation_with_argumentsfails, andtest_negation_of_interpolation_with_scaled_coargumentguards the dual slots that must stay expressions. In Irksome, all oftests/test_delta.pyfails on UFLmainwith theTypeErrorabove (or, fortest_delta, an unrelatedextract_domainsassertion that I relaxed locally for this run).After: the UFL test suite passes on
main(1069). With the patch applied to 2026.2.0, everything passes excepttest_negation_of_interpolation_with_scaled_coargument, which also needs aCoargumentimport there and then depends onPYTHONHASHSEED: 2026.2.0 takes its target space fromv.arguments()[0], which Fix dual-slot form argument counting #527 replaced. A backport should leave that test out. Irksome'stests/test_delta.pypasses 10/10 on both, with that assertion relaxed.main, where 3test_zeroform[False-*]tests fail with and without this change. They all pass (553) with the patch applied to 2026.2.0. These runs are serial.The full Firedrake suite, FFCx and DOLFINx were not run.
Merge Danger
Door: two-way
Blast Radius: interpolate-arithmetic
Only
Interpolateobjects with a contracted dual slot and free arguments change. For these,2 * dis now aFormSum, andd * 2andd * Constant(...)now raise aTypeError, matchingFormfor the scalar case.d / 2is still aDivision.This regression shipped in 2026.2.0, so it may also be worth backporting.
🤖 Generated with Claude Code