Skip to content

Commit

Permalink
Adjoint: only skip expand_derivatives if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrubeck committed Jan 4, 2025
1 parent 6078f93 commit 5894b49
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion firedrake/adjoint_utils/variational_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ def wrapper(self, *args, **kwargs):
# Some forms (e.g. SLATE tensors) are not currently
# differentiable.
dFdu = derivative(self.F, self.u_restrict)
self._ad_adj_F = adjoint(dFdu, derivatives_expanded=True)
try:
self._ad_adj_F = adjoint(dFdu)
except ValueError:
# Try again without expanding derivatives,
# as dFdu might have been simplied to an empty Form
self._ad_adj_F = adjoint(dFdu, derivatives_expanded=True)
except (TypeError, NotImplementedError):
self._ad_adj_F = None
self._ad_kwargs = {'Jp': self.Jp, 'form_compiler_parameters': self.form_compiler_parameters, 'is_linear': self.is_linear}
Expand Down

0 comments on commit 5894b49

Please sign in to comment.