Hi Colin,
On 29 May 2019, at 13:06, Cotter, Colin J <colin.cotter@imperial.ac.uk> wrote:
Dear Firedrake, Using firedrake-adjoint provokes the message at the bottom of this email. Is it expected? How can it be avoided?
all the best --Colin
File "edge_stable.py", line 106, in <module> z_opt = solver.solve()[0] File "/home/cjc1/firedrake/src/pyadjoint/pyadjoint/tape.py", line 46, in wrapper return function(*args, **kwargs) File "/home/cjc1/firedrake/src/pyadjoint/pyadjoint/optimization/rol_solver.py", line 217, in solve solver.solve() File "/home/cjc1/firedrake/src/pyadjoint/pyadjoint/optimization/rol_solver.py", line 24, in gradient g.dat = g.riesz_map(self.deriv) File "/home/cjc1/firedrake/src/pyadjoint/pyadjoint/optimization/rol_solver.py", line 52, in riesz_map dat.append(deriv._ad_convert_type(deriv, options=opts)) File "/home/cjc1/firedrake/src/pyadjoint/pyadjoint/tape.py", line 46, in wrapper return function(*args, **kwargs) File "/home/cjc1/firedrake/src/pyadjoint/fenics_adjoint/types/function.py", line 131, in _ad_convert_type if not isinstance(value, backend.GenericVector): AttributeError: module 'firedrake' has no attribute 'GenericVector'
Looks like part of the code assumes dolfin. Can you report a bug at https://bitbucket.org/pyadjoint/pyadjoint? Plausibly this patch would DTRT: diff --git a/fenics_adjoint/types/compat.py b/fenics_adjoint/types/compat.py index 6b24b4f..49ac1e0 100644 --- a/fenics_adjoint/types/compat.py +++ b/fenics_adjoint/types/compat.py @@ -268,11 +268,13 @@ else: return arr - def linalg_solve(*args, **kwargs): + def linalg_solve(A, x, b, *args, **kwargs): """Temporary workaround for kwargs not expected in fenics linalg, but possible in firedrake. A better solution is expected in the future. """ - return backend.solve(*args) + if not isinstance(x, backend.GenericVector): + x = x.vector() + return backend.solve(A, x, b, *args) diff --git a/fenics_adjoint/types/function.py b/fenics_adjoint/types/function.py index 00e19d9..576af72 100644 --- a/fenics_adjoint/types/function.py +++ b/fenics_adjoint/types/function.py @@ -128,9 +128,7 @@ class Function(FloatingType, backend.Function): u = backend.TrialFunction(self.function_space()) v = backend.TestFunction(self.function_space()) M = backend.assemble(backend.inner(u, v) * backend.dx) - if not isinstance(value, backend.GenericVector): - value = value.vector() - backend.solve(M, ret.vector(), value) + compat.linalg_solve(M, ret.vector(), value) return ret elif riesz_representation == "H1": ret = Function(self.function_space()) @@ -139,9 +137,7 @@ class Function(FloatingType, backend.Function): M = backend.assemble( backend.inner(u, v) * backend.dx + backend.inner( backend.grad(u), backend.grad(v)) * backend.dx) - if not isinstance(value, backend.GenericVector): - value = value.vector() - backend.solve(M, ret.vector(), value) + compat.linalg_solve(M, ret.vector(), value) return ret elif callable(riesz_representation): return riesz_representation(value) Thanks, Lawrence