Closed dthillaithevan closed 1 year ago
Just had a short look at this. It appears to be the gradient of the final assembly with regards to the w that comes out of the preceding solve, that throws a wobbly.
I think the MWE can be reduced to the following:
from firedrake import *
from firedrake_adjoint import *
n = 100
mesh = PeriodicSquareMesh(n,n,1, direction='both', quadrilateral = True)
dx = Measure('dx', domain = mesh)
V = VectorFunctionSpace(mesh, 'CG', 1)
R = FunctionSpace(mesh, 'R', 0)
# R = FunctionSpace(mesh, 'CG', 1) - works if you use a "normal" function space
W = V*R*R
w = Function(W)
v, lamb0, lamb1 = split(w)
ww = assemble(inner(grad(v), grad(v))*dx)
dW = compute_gradient(ww, Control(w))
Which works correctly if you replace R
by a full function space (same for the original MWE). So I think this is just one of those cases where the R isn't fully supported.
As a workaround, I think you could probably reformulate your problem solving F==0
without the Lagrange multipliers, solving it as a singular system by providing the appropriate nullspace vectors, and then applying the appropriate constraint afterwards through projection...
Thanks for this @stephankramer! I have tried using nullspaces in the past but have run into convergence issues (for non-linear problems) which is why I switched to a Lagrange multiplier approach instead, which has proven to be must more stable.
Are there plans to add fixes to support R
for adjoint problems/fix this issue in the near future?
Hi @dham, just wanted to check if there are any updates on this?
OK here's a significantly more minimal case. This extracts the failing operation from the adjoint, so we're now down to a failing assemble with no adjoint aspect.
from firedrake import *
n = 4
mesh = UnitSquareMesh(n,n)
V = VectorFunctionSpace(mesh, 'CG', 1)
R = FunctionSpace(mesh, 'R', 0)
# R = FunctionSpace(mesh, 'CG', 1) - works if you use a "normal" function space
W = V*R
w = Function(W)
v, lamb0 = split(w)
assemble(derivative(inner(grad(v), grad(v))*dx, w))
OK, I think this is fixed in #2884. Try the fix_empty_real_assembly
branch.
Thank you @dham, really appreciate this.
This is great, thanks @dham!
OK here's a significantly more minimal case. This extracts the failing operation from the adjoint, so we're now down to a failing assemble with no adjoint aspect.
from firedrake import * n = 4 mesh = UnitSquareMesh(n,n) V = VectorFunctionSpace(mesh, 'CG', 1) R = FunctionSpace(mesh, 'R', 0) # R = FunctionSpace(mesh, 'CG', 1) - works if you use a "normal" function space W = V*R w = Function(W) v, lamb0 = split(w) assemble(derivative(inner(grad(v), grad(v))*dx, w))
I may want to know, whether there is a way to compute the norm of the assembled derivative?
I tried norm(assemble(derivative(inner(grad(v), grad(v))*dx, w))
, it doesn't work.
OK here's a significantly more minimal case. This extracts the failing operation from the adjoint, so we're now down to a failing assemble with no adjoint aspect.
from firedrake import * n = 4 mesh = UnitSquareMesh(n,n) V = VectorFunctionSpace(mesh, 'CG', 1) R = FunctionSpace(mesh, 'R', 0) # R = FunctionSpace(mesh, 'CG', 1) - works if you use a "normal" function space W = V*R w = Function(W) v, lamb0 = split(w) assemble(derivative(inner(grad(v), grad(v))*dx, w))
I may want to know, whether there is a way to compute the norm of the assembled derivative? I tried
norm(assemble(derivative(inner(grad(v), grad(v))*dx, w))
, it doesn't work.
Could you please open a new discussion for this? This one has already been closed.
Hi, When using
compute_gradient
to determine the gradient of a functional w.r.t. a control variable in a periodic linear elasticity problem that uses a mixed functionspace, I am getting aIndexError: tuple index out of range
error. I've included a MWE below which replicates this issue.**Edit I dont to have permission to assign so mentioning instead, @dham
Thanks