Skip to content

Commit bc97163

Browse files
committed
Return Vector for evaluate_adj_component and evaluate_hessian_component
Pyadjoint expects Vectors to be returned for evaluate_adj_component and evaluate_hessian_component, not Functions as present. The tests have been changed to only pass when this is the case.
1 parent 07e728e commit bc97163

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

firedrake/adjoint/blocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def evaluate_adj_component(self, inputs, adj_inputs, block_variable, idx, prepar
402402
if len(adj_inputs) > 1:
403403
raise(NotImplementedError("Interpolate block must have a single output"))
404404
dJdm = self.backend.derivative(prepared, inputs[idx])
405-
return self.backend.Interpolator(dJdm, self.V).interpolate(adj_inputs[0], transpose=True)
405+
return self.backend.Interpolator(dJdm, self.V).interpolate(adj_inputs[0], transpose=True).vector()
406406

407407
def prepare_evaluate_tlm(self, inputs, tlm_inputs, relevant_outputs):
408408
return replace(self.expr, self._replace_map())
@@ -580,7 +580,7 @@ def evaluate_hessian_component(self, inputs, hessian_inputs, adj_inputs,
580580
# left multiply by dJ/dv (adj_inputs[0]) - i.e. interpolate using the
581581
# transpose operator
582582
component += self.backend.Interpolator(d2exprdudu, self.V).interpolate(adj_inputs[0], transpose=True)
583-
return component
583+
return component.vector()
584584

585585
def prepare_recompute_component(self, inputs, relevant_outputs):
586586
return replace(self.expr, self._replace_map())

tests/regression/test_adjoint_interpolate.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ def test_interpolate_hessian_linear_expr():
291291
g = f.copy(deepcopy=True)
292292

293293
dJdm = J.block_variable.tlm_value
294-
Hm = f.original_block_variable.hessian_value.vector().inner(h.vector())
294+
assert isinstance(f.original_block_variable.adj_value, Vector)
295+
assert isinstance(f.original_block_variable.hessian_value, Vector)
296+
Hm = f.original_block_variable.hessian_value.inner(h.vector())
295297
# If the new interpolate block has the right hessian, taylor test
296298
# convergence rate should be as for the unmodified test.
297299
assert taylor_test(Jhat, g, h, dJdm=dJdm, Hm=Hm) > 2.9
@@ -347,7 +349,9 @@ def test_interpolate_hessian_nonlinear_expr():
347349
g = f.copy(deepcopy=True)
348350

349351
dJdm = J.block_variable.tlm_value
350-
Hm = f.original_block_variable.hessian_value.vector().inner(h.vector())
352+
assert isinstance(f.original_block_variable.adj_value, Vector)
353+
assert isinstance(f.original_block_variable.hessian_value, Vector)
354+
Hm = f.original_block_variable.hessian_value.inner(h.vector())
351355
# If the new interpolate block has the right hessian, taylor test
352356
# convergence rate should be as for the unmodified test.
353357
assert taylor_test(Jhat, g, h, dJdm=dJdm, Hm=Hm) > 2.9
@@ -407,7 +411,9 @@ def test_interpolate_hessian_nonlinear_expr_multi():
407411
g = f.copy(deepcopy=True)
408412

409413
dJdm = J.block_variable.tlm_value
410-
Hm = f.original_block_variable.hessian_value.vector().inner(h.vector())
414+
assert isinstance(f.original_block_variable.adj_value, Vector)
415+
assert isinstance(f.original_block_variable.hessian_value, Vector)
416+
Hm = f.original_block_variable.hessian_value.inner(h.vector())
411417
# If the new interpolate block has the right hessian, taylor test
412418
# convergence rate should be as for the unmodified test.
413419
assert taylor_test(Jhat, g, h, dJdm=dJdm, Hm=Hm) > 2.9

0 commit comments

Comments
 (0)