Skip to content

Only pull factors that depend on a ListTensor index into the ListTensor - #317

Open
pbrubeck wants to merge 6 commits into
pbrubeck/zany-vectorfrom
pbrubeck/fix/listtensor-contraction
Open

pbrubeck wants to merge 6 commits into
pbrubeck/zany-vectorfrom
pbrubeck/fix/listtensor-contraction

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Nov 21, 2026 •

Copy link
Copy Markdown

Summary

Fixes firedrakeproject/firedrake#5690

Bug

Spectral mode raises FactorisationError for interpolate(v, T) when v is an Argument on a VectorFunctionSpace of a physically mapped element (Hermite, Morley, Argyris, Bell). Vanilla mode works.

The vector basis is a product of the transformed scalar basis and a component selector:

sum_j M[i, j] * phi_j  *  Delta(argcomp, valcomp)
      └─ ListTensor indexed by i ─┘   └─ independent of i ─┘

contraction() split the whole product along every free index of a ListTensor, so the Delta was copied into each ListTensor entry:

Indexed(ListTensor([... * Delta(argcomp, 0), ... * Delta(argcomp, 1), ...]), (i,))

collect_monomials cannot see an argument factor inside a ListTensor, so it raises FactorisationError.

Fix

Split only the factors that depend on the ListTensor index, and leave the rest outside:

 contraction(expression)
-  find free indices of any ListTensor in expression
-  split the whole expression along them; sum-factorise each entry
+  cancel Deltas, flatten into (sum_indices, factors)
+  group factors into independent contractions
+  for each group
+    if it has free ListTensor indices and no Delta selector index
+      split this group along them; sum-factorise each entry
+    else
+      sum-factorise the group as is
+  multiply the groups pointwise

The Delta now stays a top-level factor, where collect_monomials finds it.

Splitting a group substitutes fixed values for its ListTensor index. That exposed index bugs in GEM, which this PR also fixes:

  • replace_indices(IndexSum) renames a bound index when a substitution would capture it. When a specialised entry no longer depends on a summed index, it multiplies by that index's extent, so the sum keeps its value.
  • traverse_product and MonomialSum.product/_collect_monomials reserve the expression's free indices before renaming, so a renamed sum index cannot reuse a free index's name.
  • _collect_monomials sums out an index right away when only non-atomic factors use it, or when Delta cancellation has left no factor that depends on it.
  • _contract handles a sum index that no factor depends on.
  • associate falls back to a linear pass for products with more than 32 operands. Before, it raised NotImplementedError.

This PR is stacked on the coordinate-mapping changes in #316.

Evidence

  • Before: inner(interpolate(v, T), Constant((1, 0))) * dx with v in vector Hermite, Morley, Argyris or Bell and T vector CG1 or DG1: all 8 cases raise FactorisationError in spectral mode.
    After: all 8 compile and agree with "mode": "vanilla" (max difference 1.4e-17).
  • Before: test_refactorise_contracted_list_tensor fails on both parameters, because the Delta is buried inside the ListTensor.
    After: it passes. collect_monomials(contraction(expr)) returns a single monomial with atomics == (Delta(source, target),), and evaluating it gives the original values.
  • Before: with Firedrake #5688 on main's GEM, the wrapped Bernardi–Raugel spectral regression raises FactorisationError.
    After: the Bernardi–Raugel case and the vector Morley cases for RT, N1curl and gradient interpolation pass. They agree with vanilla mode to within 8.4e-17.
  • New GEM tests cover index capture, selector visibility, reduction multiplicity, Delta traces and products with more than 32 factors. All of test/gem and test/finat pass (685 passed, 8 skipped). The 400 TSFC tests pass, including test_sum_factorisation and test_flop_count for tensor-product H(div)/H(curl). The serial tests in Firedrake's test_interpolate_zany.py, test_interpolation_operators.py, test_interp_dual.py and test_helmholtz_zany.py pass. make lint is clean.

Merge Danger

Door: two-way

Reverting this PR restores the old splitting. No API or data-format change.

Blast Radius: kernels

Every kernel whose contraction has a ListTensor indexed by a free index now goes through the new grouping. This includes tensor-product H(div)/H(curl) elements. The flop-count tests pass, but exact kernel cost has not been benchmarked.

AI assistance used Claude Code (Claude Opus 5.5) and OpenAI Codex.

🤖 Generated with Claude Code

pbrubeck and others added 3 commits November 21, 2026 13:44
contraction() split the whole product into ListTensor entries, which
pulled the component Delta of a vector-valued Argument into every entry,
so spectral mode raised FactorisationError for vector spaces of
physically mapped elements.

Fixes firedrakeproject/firedrake#5690

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Partition factors after Delta cancellation and respect scope when locating free ListTensor indices. Preserve reductions over invariant factors and keep coupled argument axes visible to TSFC.

AI assistance used OpenAI Codex.
@pbrubeck
pbrubeck changed the base branch from main to pbrubeck/zany-vector November 21, 2026 14:04
@pbrubeck pbrubeck added the LLM used An LLM was used in the production of this PR label Nov 21, 2026
@pbrubeck
pbrubeck added this pull request to stack #318 November 22, 2026 12:37
pbrubeck and others added 2 commits November 22, 2026 14:25
Preserve free Delta selectors per contraction group so independent ListTensor entries still specialise. Restore the one-argument contraction interface.

AI assistance used OpenAI Codex.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pbrubeck added a commit to firedrakeproject/firedrake that referenced this pull request Nov 26, 2026
Install fiat 161738ac from firedrakeproject/fiat#317
and UFL 24a8b5dd from FEniCS/ufl#571 in the test and
documentation jobs. Drop this commit, with the earlier DROP BEFORE MERGE
commits, once both companions have merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pbrubeck added a commit to firedrakeproject/firedrake that referenced this pull request Nov 26, 2026
Install fiat from pbrubeck/fix/listtensor-contraction
(firedrakeproject/fiat#317) and UFL from
pbrubeck/fix/interpolate-target-domain (FEniCS/ufl#571)
in the test and documentation jobs. Drop this commit, with the earlier
DROP BEFORE MERGE commits, once both companions have merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The derivatives of a vector-valued basis form a ListTensor over the
derivative direction, and every entry carries the Delta that couples a
basis function to its value component.  contraction() refuses to split
a ListTensor contraction whose factors carry a Delta index, so the
buried Delta kept the basis transformation of a physically mapped
element from absorbing the contraction with an interpolated basis.
TSFC then contracted the interpolation matrix at every quadrature
point, and a vector of zany elements cost more than twice the scalar
form.

Since [c x_0, ..., c x_n]_i = c [x_0, ..., x_n]_i, contraction() now
pulls the factors shared by every entry of an indexed ListTensor out
before cancelling Deltas.

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LLM used An LLM was used in the production of this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: FactorisationError in spectral mode when interpolating an Argument from a VectorFunctionSpace of a physically mapped element

1 participant