Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions pyadjoint/optimization/rol_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def value(self, x, tol):

def gradient(self, g, x, tol):
opts = {"riesz_representation": x.inner_product}
opts.update(x.inner_product_solver_opts)
self.deriv = self.rf.derivative(options=opts)
g.dat = Enlist(self.deriv)

Expand Down Expand Up @@ -63,10 +64,11 @@ def update(self, x, flag, iteration):
self._val = self.rf(x.dat)

class ROLVector(ROL.Vector):
def __init__(self, dat, inner_product="L2"):
def __init__(self, dat, inner_product="L2", inner_product_solver_opts={}):
super(ROLVector, self).__init__()
self.dat = dat
self.inner_product = inner_product
self.inner_product_solver_opts = inner_product_solver_opts

def plus(self, yy):
for (x, y) in zip(self.dat, yy.dat):
Expand Down Expand Up @@ -97,7 +99,8 @@ def clone(self):
dat = []
for x in self.dat:
dat.append(x._ad_copy())
res = ROLVector(dat, inner_product=self.inner_product)
res = ROLVector(dat, inner_product=self.inner_product,
inner_product_solver_opts=self.inner_product_solver_opts)
res.scale(0.0)
return res

Expand Down Expand Up @@ -143,7 +146,8 @@ class ROLSolver(OptimizationSolver):
Use ROL to solve the given optimisation problem.
"""

def __init__(self, problem, parameters, inner_product="L2"):
def __init__(self, problem, parameters, inner_product="L2",
inner_product_solver_opts=None):
"""
Create a new ROLSolver.

Expand All @@ -155,9 +159,9 @@ def __init__(self, problem, parameters, inner_product="L2"):
OptimizationSolver.__init__(self, problem, parameters)
self.rolobjective = ROLObjective(problem.reduced_functional)
x = [p.tape_value() for p in self.problem.reduced_functional.controls]
self.rolvector = ROLVector(x, inner_product=inner_product)
self.rolvector = ROLVector(x, inner_product=inner_product,
inner_product_solver_opts=inner_product_solver_opts)
self.params_dict = parameters

self.bounds = self.__get_bounds()
self.constraints = self.__get_constraints()

Expand Down
2 changes: 1 addition & 1 deletion pyadjoint/reduced_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def __call__(self, values):
raise TypeError(
f"The control at index {i} must be an `OverloadedType` object "
f"with the same type as the control, which is {control_type}"
)
)
# Call callback.
self.eval_cb_pre(self.controls.delist(values))

Expand Down