Compute the target space of Interpolate only in UFL
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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).
- Lenguaje dominante
- Python
- Estrellas
- 684
- Forks
- 204
- Merge medio
- 4 d 14 h
- PR fusionados (30 d)
- 46
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de firedrakeproject/firedrake
-
BUG: NonlinearVariationalSolver errors with adj_kwargsPosiblemente ocupada @dham la tomó hace 151 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
firedrakeproject/firedrake#5186 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
firedrakeproject/firedrake#5091 ·
Los mantenedores suelen responder en 1 día
-
documentation
Dificultad 1/5 1-3 horas Aptitud para principiantes 82/100
firedrakeproject/firedrake#3556 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 4/5 3-5 días Aptitud para principiantes 22/100
firedrakeproject/firedrake#5644 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Function.assign on a subset fails with a Constant, a Real Function or abs in the expressionPosiblemente ocupada @connorjward la tomó hace 2 días. Abierto
firedrakeproject/firedrake#5643 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de firedrakeproject/firedrake
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
datamodel-code-generator/datamodel-code-generator#6906 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
UKGovernmentBEIS/optstop#12 ·
-
bug good first issue severity: low
Dificultad 1/5 1-3 horas Aptitud para principiantes 85/100
TMHSDigital/Awesome-Ads#37 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
smokin-salmon/smoked-salmon#1095 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Sienna-Platform/SiennaSchemas#130 ·
Los mantenedores suelen responder en 3 días