Repository navigation
Backport ZeroBaseForm fixes for vanishing derivatives - #557
Merged
Merged
Conversation
Add integrals(), constants() and terminal_numbering() to ZeroBaseForm, all empty, and a _cache dict like the one on Form. Form compilers and Firedrake can then process a ZeroBaseForm like a Form without integrals. integrals() and constants() are backported from #451. terminal_numbering() and _cache are also proposed for UFL main. Needed for firedrakeproject/firedrake#5571. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Return ZeroBaseForm(arguments) from apply_derivatives when every integrand of a non-empty form vanishes, instead of an argument-less Form([]). The empty Form lost the rank of the derivative, so that action and adjoint failed on it, e.g. for the adjoint of a residual that depends on a control only through a conditional predicate. Backported from #451 for firedrakeproject/firedrake#5571. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ruff 0.17.4 reports ICN001 for a plain `import datetime`, which fails the lint job. Use the same import as main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pbrubeck
added a commit
to firedrakeproject/firedrake
that referenced
this pull request
Nov 11, 2026
Install UFL from the branch pbrubeck/backport-zero-derivative over the fenics-ufl==2026.2 pin, in the composite install action and in the docs job. The branch adds ZeroBaseForm.integrals(), constants(), terminal_numbering() and _cache, which the assembly of a ZeroBaseForm needs, and keeps the arguments of a vanishing derivative. Drop this commit once FEniCS/ufl#557 is in a UFL 2026.2.x release on PyPI, and replace it with a commit that relaxes the pin to fenics-ufl==2026.2.*. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 11, 2026
dham
approved these changes
Nov 17, 2026
pbrubeck
added a commit
to firedrakeproject/firedrake
that referenced
this pull request
Nov 17, 2026
Install UFL from the branch pbrubeck/backport-zero-derivative over the fenics-ufl==2026.2 pin, in the composite install action and in the docs job. The branch adds ZeroBaseForm.integrals(), constants(), terminal_numbering() and _cache, which the assembly of a ZeroBaseForm needs, and keeps the arguments of a vanishing derivative. Drop this commit once FEniCS/ufl#557 is in a UFL 2026.2.x release on PyPI, and replace it with a commit that relaxes the pin to fenics-ufl==2026.2.*. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jorgensd
self-requested a review
November 25, 2026 14:35
jorgensd
approved these changes
Nov 25, 2026
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
This backports the
ZeroBaseFormpart of #451 torelease, together with #556, for firedrakeproject/firedrake#5571.On 2026.2.0, a derivative that vanishes expands to an argument-less
Form([]), soactionandadjointfail on it:apply_derivatives(form) dform = map_integrands(rules, form) if dform is a bare 0 dform = ZeroBaseForm(form.arguments()) + elif form is not empty and dform is an empty Form + dform = ZeroBaseForm(form.arguments())ZeroBaseFormthen needs the form-compiler interface, so that FFCx'scompute_form_dataand Firedrake's assemblers can process it:A third commit imports
datetime as dtindoc/source/conf.py, as main does, because ruff 0.17.4 reports ICN001 there.Evidence
release:dJ = [0, 0]andtlm = 0.test_vanishing_form_keeps_its_arguments,test_compute_form_data_of_zero_base_formandtest_zero_base_form_compiler_interfacepass. The full suite passes (1037 passed). ruff 0.17.4 and mypy 2.4.1 (.[ci]) are clean.Merge Danger
Door: two-way
Blast Radius: derivatives
The derivative of a non-empty form that vanishes is now a
ZeroBaseForminstead ofForm([]). Code that checksform.empty()sees no difference. Code that checksisinstance(form, Form)on such a derivative takes a different branch. In Firedrake, the companion PR above handles this.🤖 Drafted with Claude Code (Claude Opus 5.5).