Skip to content

Backport ZeroBaseForm fixes for vanishing derivatives - #557

Merged
jorgensd merged 5 commits into
releasefrom
pbrubeck/backport-zero-derivative
Nov 25, 2026
Merged

jorgensd merged 5 commits into
releasefrom
pbrubeck/backport-zero-derivative

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This backports the ZeroBaseForm part of #451 to release, together with #556, for firedrakeproject/firedrake#5571.

On 2026.2.0, a derivative that vanishes expands to an argument-less Form([]), so action and adjoint fail 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())

ZeroBaseForm then needs the form-compiler interface, so that FFCx's compute_form_data and Firedrake's assemblers can process it:

 class ZeroBaseForm(BaseForm):
+    _cache                  # Dict for external frameworks, as on Form
+    integrals()        -> ()
+    constants()        -> ()
+    terminal_numbering() -> {}

A third commit imports datetime as dt in doc/source/conf.py, as main does, because ruff 0.17.4 reports ICN001 there.

Evidence

Merge Danger

Door: two-way

Blast Radius: derivatives

The derivative of a non-empty form that vanishes is now a ZeroBaseForm instead of Form([]). Code that checks form.empty() sees no difference. Code that checks isinstance(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).

pbrubeck and others added 3 commits November 11, 2026 18:34
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>
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
jorgensd self-requested a review November 25, 2026 14:35
@jorgensd
jorgensd merged commit efb9370 into release Nov 25, 2026
8 checks passed
@jorgensd
jorgensd deleted the pbrubeck/backport-zero-derivative branch November 25, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants