BUG: Interpolating into a Real space gives an adjoint scaled by the number of cells
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
- 22/100
Línea de trabajo
The bug sits in how interpolation into the Real space is assembled and annotated for the adjoint, so start with the interpolate path that handles an R-space target and with the pyadjoint annotation for it. Reproduce the three-mesh script from the issue and confirm paired and dJ/dm scale with num_cells. Done means the paired value equals exp(0.3) and the derivative equals 2 exp(0.6) on all meshes, matching a finite-difference check.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
Interpolating an expression into a Real space gives the correct forward value. Pairing the same interpolation with a cofunction, or taking its derivative through the tape, gives a result multiplied by the number of cells in the mesh. A Taylor test on a functional that depends on such an interpolation converges at first order.
Steps to Reproduce
from firedrake import *
from firedrake.adjoint import *
for n in (1, 2, 4):
mesh = UnitSquareMesh(n, n)
R = FunctionSpace(mesh, "R", 0)
m = Function(R).assign(0.3)
# Forward: correct
u = assemble(interpolate(exp(m), R))
# Pairing with a cofunction equal to one: expected exp(0.3)
c = Cofunction(R.dual())
c.dat.data[:] = 1.0
paired = assemble(interpolate(exp(m), c))
# Derivative through the tape: expected d/dm exp(2m) = 2 exp(0.6)
continue_annotation()
J = assemble(assemble(interpolate(exp(m), R)) ** 2 * dx)
pause_annotation()
dJdm = ReducedFunctional(J, Control(m)).derivative().dat.data_ro[0]
get_working_tape().clear_tape()
print(
f"cells={mesh.num_cells():2d} forward={u.dat.data_ro[0]:.6f} "
f"paired={float(paired):.6f} expected={float(exp(0.3)):.6f} "
f"dJ/dm={dJdm:.6f} expected={2 * float(exp(0.6)):.6f}"
)
Output:
cells= 2 forward=1.349859 paired=2.699718 expected=1.349859 dJ/dm=7.288475 expected=3.644238
cells= 8 forward=1.349859 paired=10.798870 expected=1.349859 dJ/dm=29.153901 expected=3.644238
cells=32 forward=1.349859 paired=43.195482 expected=1.349859 dJ/dm=116.615603 expected=3.644238
Expected behavior
The paired value should be exp(0.3) and the derivative 2 exp(0.6) on every mesh, independent of the number of cells. Instead both are exactly the number of cells times the expected value. A central finite difference through the same ReducedFunctional gives the expected derivative.
Error message
None. The result is silently wrong.
Environment:
- OS: macOS 15.6 (arm64)
- Python version: 3.14.7
- Firedrake version: 2026.10.0, with pyadjoint-ad 2026.10.0
- Run in serial
Additional Info
Evaluating the expression into the Real space as its integral over the mesh divided by the mesh volume, assemble(expr * dx) / volume, differentiates correctly and works around the problem.
- 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
-
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
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
firedrakeproject/firedrake#5642 ·
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