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

BUG: recompute tape is failing (interpolate) #3919

Open
Ig-dolci opened this issue Dec 11, 2024 · 4 comments
Open

BUG: recompute tape is failing (interpolate) #3919

Ig-dolci opened this issue Dec 11, 2024 · 4 comments
Assignees
Labels

Comments

@Ig-dolci
Copy link
Contributor

Describe the bug
recompute tape is failing for the following code:

Steps to Reproduce

from firedrake import *
import firedrake.adjoint as fda

mesh = UnitSquareMesh(2, 2)
V = FunctionSpace(mesh, "DG", 0)
u = Function(V)

fda.continue_annotation()
p = fda.AdjFloat(0.)
u.interpolate(p)
J = assemble(u*dx)

fda.stop_annotating()

Jhat = fda.ReducedFunctional(J, fda.Control(p))
J = Jhat(fda.AdjFloat(1.))
print("J: ", J, " u: ", u.block_variable.checkpoint.dat.data_ro)
J = Jhat(fda.AdjFloat(2.))
print("J: ", J, " u: ", u.block_variable.checkpoint.dat.data_ro)

The output is

J:  0.0  u:  [0. 0. 0. 0. 0. 0. 0. 0. 0.]
J:  0.0  u:  [0. 0. 0. 0. 0. 0. 0. 0. 0.]

The expected output is:

J:  1.0  u:  [1. 1. 1. 1. 1. 1. 1. 1. 1.]
J:  2.0  u:  [2. 2. 2. 2. 2. 2. 2. 2. 2.]

It seems to be an issue related to u.interpolate(p); when we modify it to u.assign(p), the result is right.

Environment:

  • OS: MacOS
  • Python version: 3.13
@Ig-dolci Ig-dolci added the bug label Dec 11, 2024
@Ig-dolci Ig-dolci self-assigned this Dec 11, 2024
@connorjward
Copy link
Contributor

Is this related to #3909?

@jrmaddison
Copy link
Contributor

jrmaddison commented Dec 11, 2024

UFL sees an AdjFloat as being just a float, and creates a FloatValue. I think the conversion is happening in as_ufl.

@dham
Copy link
Member

dham commented Dec 11, 2024

Yes, do we not need to use a function in R in these cases?

@Ig-dolci
Copy link
Contributor Author

Ig-dolci commented Dec 11, 2024

UFL sees an AdjFloat as being just a float, and creates a FloatValue. I think the conversion is happening in as_ufl.

I see.

Yes, do we not need to use a function in R in these cases?

The controls are working in R space. A warning (or raising an error) for this case looks to be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants