Compute the target space of Interpolate only in UFL
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Read firedrake/interpolation.py around the linked Interpolate.__init__ lines and compare them with UFL’s ufl/core/base_form_operator.py and ufl/core/interpolate.py; the issue also points to FEniCS/ufl#515 for the UFL work. Trace how the target space and adjoint status are computed, then check the UFL and Firedrake tests for these cases. Done means UFL exposes the target space and adjoint status, and Firedrake uses them without recomputing argument numbers.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Follow-up from the review of #5551 (comment).
Problem
firedrake.Interpolate.__init__ and ufl.Interpolate.__init__ both compute the argument numbers of the expression and use them to decide which argument of the dual slot is contracted. Firedrake does this in its own way:
UFL does it with _split_dual_slot_arguments in ufl/core/base_form_operator.py, and stores the result as Interpolate._function_space.
The two computations must agree, but nothing makes them agree. They already differ in small ways: Firedrake contracts the primal argument numbered 0, and UFL contracts the lowest-numbered primal argument. Firedrake does not check that the first argument of a form operand is a Coargument, and UFL does.
Why Firedrake computes the numbers again
UFL already computes the space that Firedrake needs, but it does not make it public. Firedrake needs two results from the argument numbers:
-
The target space. This is the space of the dual-slot argument that the output of the interpolation replaces. Firedrake uses it to select the
Interpolatorsubclass (target_space.mesh(),len(target_space)) and to check the shape of the expression. UFL computes the same space and stores it in the private_function_space. The public methodufl_function_space()does not return it. That method returns the dual of the first argument of the operator, which is a different space when the interpolation is an adjoint or when the dual slot is a form:Expression Target space ufl_function_space()Interpolate(u, V)VVInterpolate(TestFunction(U), V)(adjoint)VU*Interpolate(e, Cofunction(V*))VNoneInterpolate(w0, A(v0, v1))V0W0*Interpolate(w1, A(v0, v1))V1V0*Here
v0 ∈ V0,v1 ∈ V1,w0 ∈ W0(number 0), andw1 ∈ W1(number 1). These values were checked against UFLmain. With a 2-form in the dual slot, the target space depends on the argument numbers of the expression (see theBaseFormOperatordocstring). Because of this, the target space cannot be found from the dual slot alone. -
A Firedrake
Argumentfor a function-space dual slot. IfVis aWithGeometry, UFL makes aufl.Argument(V.dual(), n), which has no.function_space()method. Firedrake therefore makes its ownfiredrake.Argumentbefore it callssuper().__init__. To getn, it must know whether the expression is an adjoint (expr_arg_numbers == {0}), and UFL computes that again. This is also the source ofInterpolate.is_adjoint.
A third copy is in Interpolator.__init__, which sets self.target_space = dual_arg.function_space().dual(). That is correct only when the dual slot is a Coargument or a Cofunction.
Proposal
Make the target space a public attribute of ufl.BaseFormOperator. Then firedrake.Interpolate can be a thin wrapper around ufl.Interpolate.
BaseFormOperator.target_space (or ufl_target_space(), if it must follow the UFL naming convention) must return the space that the output of the operator N(u) is in:
- It is the
function_spaceargument ofBaseFormOperator.__init__.__init__already checks that this is the space of the contracted dual-slot argument. - It does not depend on the argument numbering. For the examples above, it is the space in the "Target space" column. It is never a dual space and it is never
None, also when the dual slot is aCofunction. - It is defined for every
BaseFormOperator, not only forInterpolate.ExternalOperatorgets the same attribute. ufl_shapeandufl_element()ofInterpolatemust be derived from it. At the moment they read_function_spacedirectly.
UFL must also expose whether the interpolation is an adjoint (for example Interpolate.is_adjoint), so that Firedrake does not compute the argument numbers again.
With these changes in UFL, Firedrake can:
- Remove the computation of
expr_arg_numbersand the selection of the contracted argument fromfiredrake.Interpolate.__init__, and useself.target_spacefrom UFL. - Remove
Interpolator.target_space = dual_arg.function_space().dual(), and useexpr.target_space. - Keep only the conversion of a
WithGeometryinto afiredrake.Argument. This is possible if UFL makes the argument through a hook that Firedrake can override, or ifufl.Argumentgets the information that Firedrake needs from.function_space().
FEniCS/ufl#515 changes ufl/core/interpolate.py and can be a good place for the UFL part of this change.
🤖 Drafted with Claude Code (Claude Opus 5.5).
- Lingua principale
- Python
- Stelle
- 684
- Fork
- 204
- Merge medio
- 4g 14h
- PR unite (30g)
- 46
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di firedrakeproject/firedrake
-
BUG: NonlinearVariationalSolver errors with adj_kwargsForse già presa @dham l’ha presa 151 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
firedrakeproject/firedrake#5186 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
firedrakeproject/firedrake#5091 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation
Difficoltà 1/5 1-3 ore Idoneità per principianti 82/100
firedrakeproject/firedrake#3556 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 22/100
firedrakeproject/firedrake#5644 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Function.assign on a subset fails with a Constant, a Real Function or abs in the expressionForse già presa @connorjward l’ha presa 2 giorni fa. Aperta
firedrakeproject/firedrake#5643 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di firedrakeproject/firedrake
Issue simili
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Sienna-Platform/SiennaSchemas#130 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
firedrakeproject/Irksome#293 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ida-arbeitszeit/workers-control#1578 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
aws-samples/sample-per-model-bedrock#898 ·
I maintainer di solito rispondono entro 1 giorno