Skip to content

Give ZeroBaseForm terminal_numbering() and a _cache - #556

Merged
jorgensd merged 6 commits into
mainfrom
pbrubeck/zero-base-form-cache
Nov 25, 2026
Merged

jorgensd merged 6 commits into
mainfrom
pbrubeck/zero-base-form-cache

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Firedrake assembles a ZeroBaseForm through the same path as a Form without integrals, so it needs the rest of the form-compiler interface on ZeroBaseForm:

 class ZeroBaseForm(BaseForm):
     __slots__ = (
         "_arguments",
+        "_cache",
         ...
     )
     def integrals(self):           # from #451
         return ()
+    def terminal_numbering(self):
+        return {}
     def constants(self):           # from #451
         return ()

_cache stays on ZeroBaseForm, because BaseForm.__slots__ is kept empty for multiple inheritance.

Needed for firedrakeproject/firedrake#5571. The 2026.2 backport is #557.

Evidence

  • Before: assemble(ZeroBaseForm((v,))) in Firedrake, routed to its 1-form assembler:
    AttributeError: 'ZeroBaseForm' object has no attribute '_cache'
    AttributeError: 'ZeroBaseForm' object has no attribute 'terminal_numbering'
    
    After: it returns a zero Cofunction. The new test_zero_base_form_compiler_interface passes, and so does the full UFL suite (1259 passed). ruff 0.17.4 and mypy 2.4.1 (.[ci]) are clean.

Merge Danger

Door: two-way

Blast Radius: small

The change only adds methods and a slot. Code that tests hasattr(form, "_cache") to tell a Form from a ZeroBaseForm would now see both alike.

🤖 Drafted with Claude Code (Claude Opus 5.5).

Add terminal_numbering(), which returns an empty numbering, and a _cache
dict like the one on Form. Together with integrals() and constants(),
form compilers and Firedrake can then process a ZeroBaseForm like a Form
without integrals.

Needed for firedrakeproject/firedrake#5571.

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/zero-base-form-cache over the UFL
main pin, in the composite install action and in the docs job. The
branch adds ZeroBaseForm.terminal_numbering() and _cache, which the
assembly of a ZeroBaseForm needs. Install it after Firedrake, since the
direct URL pin on UFL main would otherwise reinstall main over it.

Drop this commit once
FEniCS/ufl#556 merges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pbrubeck
pbrubeck requested a review from jorgensd November 23, 2026 12:39
@jorgensd
jorgensd added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 53bec98 Nov 25, 2026
21 checks passed
@jorgensd
jorgensd deleted the pbrubeck/zero-base-form-cache branch November 25, 2026 14:43
pbrubeck added a commit to firedrakeproject/firedrake that referenced this pull request Nov 25, 2026
Use UFL main now that FEniCS/ufl#556 has merged.

Assisted-by: OpenAI Codex
pbrubeck added a commit to firedrakeproject/firedrake that referenced this pull request Nov 27, 2026
* Assemble a ZeroBaseForm like any other form

Dispatch a ZeroBaseForm to the 0-, 1- and 2-form assemblers, so that
assemble() returns a zero float, Cofunction or Matrix instead of the
symbolic ZeroBaseForm. TSFC generates no kernels for a form without
integrals, so the assemblers only allocate the output, zero it, and
apply the boundary conditions. A zero 2-form with Dirichlet boundary
conditions therefore gets the identity on the boundary rows, as any
other assembled matrix does.

Use COMM_SELF for the compilation cache and the scalar output of a form
without a mesh, since such a form has no integrals and nothing is
compiled or reduced.

This fixes the adjoint of a solve whose residual depends on a control
only through a conditional predicate (#5571), where dF/dm is a
ZeroBaseForm.

Requires a UFL in which ZeroBaseForm provides integrals(), constants(),
terminal_numbering() and _cache.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Test the assembly of a vanishing 0-form

Assemble 0*dx and 0*ds, which raised an IndexError on the release
branch (#3598). Main already returns 0, since #5551 left the
preprocessing of a plain form to TSFC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* DROP BEFORE MERGE: Install the UFL branch for ZeroBaseForm

Install UFL from the branch pbrubeck/zero-base-form-cache over the UFL
main pin, in the composite install action and in the docs job. The
branch adds ZeroBaseForm.terminal_numbering() and _cache, which the
assembly of a ZeroBaseForm needs. Install it after Firedrake, since the
direct URL pin on UFL main would otherwise reinstall main over it.

Drop this commit once
FEniCS/ufl#556 merges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Remove temporary UFL branch override

Use UFL main now that FEniCS/ufl#556 has merged.

Assisted-by: OpenAI Codex

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants