Skip to content

Commit

Permalink
Backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmaddison committed Oct 3, 2024
1 parent c18b0f4 commit 2250c0f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/icepack/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .utilities import default_solver_parameters

from firedrake.adjoint_utils.blocks.solving import NonlinearVariationalSolveBlock
import inspect
import ufl


Expand Down Expand Up @@ -143,12 +144,17 @@ def solve(self, *, annotate=None):

class Block(NonlinearVariationalSolveBlock):
def __init__(self, solver):
if "adj_cache" in inspect.signature(NonlinearVariationalSolveBlock).parameters:
kwargs = {"adj_cache": {}}
else:
# Backwards compatibility
kwargs = {"dFdm_cache": {}}
super().__init__(
solver.F == 0, solver.problem.u, solver.problem.bcs,
adj_F=firedrake.adjoint(solver.J), adj_cache={},
adj_F=firedrake.adjoint(solver.J),
problem_J=solver.J,
solver_params=solver.search_direction_solver.parameters,
solver_kwargs={})
solver_kwargs={}, **kwargs)
for dep in ufl.algorithms.extract_coefficients(solver.problem.S):
self.add_dependency(dep, no_duplicates=True)
self._icepack__solver = solver
Expand Down

0 comments on commit 2250c0f

Please sign in to comment.