Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify indexed ListTensor objects #336

Merged
merged 15 commits into from
Jan 15, 2025

Conversation

pbrubeck
Copy link
Contributor

@pbrubeck pbrubeck commented Dec 30, 2024

When splitting mixed Forms, mixed Arguments get replaced by ListTensors of Zero and subspace Arguments of the form [0, ..., 0, v[0], ..., v[k], 0, ..., 0]. The resulting split Form would contain many instances of Indexed objects with this ListTensor, that could be simplified to either 0 or [v[0], ..., v[k]] -> v.

Previously, the simplification step was left as a task for the form compiler, but working with such complicated expressions often results in sub-optimal code generation. This PR addresses the following simplications at the UFL-level:

  1. Indexed(ListTensor[v0, ..., vk], (j,)) -> vj
  2. ListTensor(Indexed(v, FixedIndex(i)) for i in range(k)) -> v
  3. Restricted(ConstantValue) -> ConstantValue

As a consequence, splitting a bilinear Form with a block in the diagonal equal to zero produces an empty Form, losing all the information that the unsimplified Form carried around, such as the Arguments and the arity. This situation needs to be handled carefully as a special case. See firedrakeproject/firedrake#3947

With these simplifications, we can correctly estimate quadrature degrees for integrands that only depend on one component of the solution, thus lowering flop counts.

@pbrubeck pbrubeck force-pushed the pbrubeck/simplify-indexed branch 2 times, most recently from 80ab7ca to a7a7922 Compare December 30, 2024 03:36
@pbrubeck pbrubeck force-pushed the pbrubeck/simplify-indexed branch from a7a7922 to 0a0a4df Compare December 30, 2024 03:55
@pbrubeck pbrubeck force-pushed the pbrubeck/simplify-indexed branch from 4dcc19a to 5db1162 Compare December 31, 2024 16:00
@pbrubeck pbrubeck force-pushed the pbrubeck/simplify-indexed branch from 4fa252a to 7100560 Compare January 1, 2025 01:39
@pbrubeck pbrubeck force-pushed the pbrubeck/simplify-indexed branch from 40d6f2f to 35509b8 Compare January 2, 2025 15:45
@pbrubeck pbrubeck force-pushed the pbrubeck/simplify-indexed branch from 766da29 to e0c4e6a Compare January 4, 2025 19:41
@pbrubeck pbrubeck force-pushed the pbrubeck/simplify-indexed branch 2 times, most recently from e09ca53 to 1356ae0 Compare January 7, 2025 01:36
@pbrubeck pbrubeck force-pushed the pbrubeck/simplify-indexed branch from 1356ae0 to bfa596d Compare January 7, 2025 06:15
@jhale
Copy link
Member

jhale commented Jan 8, 2025

This seems fine to me and thanks for the various modernisations added as well.

@pbrubeck pbrubeck force-pushed the pbrubeck/simplify-indexed branch from 33bd10d to bfa596d Compare January 8, 2025 17:07
@pbrubeck pbrubeck force-pushed the pbrubeck/simplify-indexed branch from 07b0c74 to cd1d21b Compare January 14, 2025 14:35
ufl/indexed.py Outdated Show resolved Hide resolved
@pbrubeck pbrubeck force-pushed the pbrubeck/simplify-indexed branch 2 times, most recently from 55cc653 to fa6f5c2 Compare January 15, 2025 13:40
ufl/indexed.py Outdated Show resolved Hide resolved
@jorgensd jorgensd added this pull request to the merge queue Jan 15, 2025
@jorgensd jorgensd removed this pull request from the merge queue due to a manual request Jan 15, 2025
@pbrubeck pbrubeck force-pushed the pbrubeck/simplify-indexed branch from fa6f5c2 to df1ddf3 Compare January 15, 2025 15:08
@jorgensd jorgensd added this pull request to the merge queue Jan 15, 2025
Merged via the queue into FEniCS:main with commit cb9052d Jan 15, 2025
12 checks passed
@pbrubeck pbrubeck deleted the pbrubeck/simplify-indexed branch January 15, 2025 15:50
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.

4 participants