Moola minimizer for multiple control variables

Dear all,

I am trying to use Moola for my minimization problem in the Dolfin adjoint. Can you please tell me how should I use Moola for a problem with multiple control variables?

Below is a minimal code that is working with the dolfin-adjoint minimizer, but gives error for moola solver:

from dolfin import *
from dolfin_adjoint import *
import moola
n = 10
mesh = RectangleMesh(Point(-1,-1),Point(1,1), n, n)

V = FunctionSpace(mesh, "CG", 1)
u, d = Function(V), Function(V)
u_v, d_v = TestFunction(V), TestFunction(V)
S0 = Constant(1)

bc = DirichletBC(V, 1, "on_boundary")

u_v, u_d = project(u, V, bcs=bc), project(d, V, bcs=bc)
J = assemble((inner(grad(u_v), grad(u_v)) +inner(grad(d), grad(d))\
        - u_v*S0)*dx)
control = [Control(u), Control(d)]
J_hat = ReducedFunctional(J, control)   
m_opt = minimize(J_hat, method = "L-BFGS-B", options = {"gtol": 1e-9})
J_hat(m_opt)

For using moola minimzer, I tried to use below script instead of m_opt = minimize(J_hat, method = "L-BFGS-B", options = {"gtol": 1e-9})

problem = MoolaOptimizationProblem(J_hat)
m_moola = moola.DolfinPrimalVector([u,d])
solver = moola.BFGS(problem, m_moola, options={'jtol': 0,
                                                'gtol': 1e-9,
                                                'Hinit': "default",
                                                'maxiter': 100,
                                                'mem_lim': 10})    
    
sol = solver.solve()
m_opt = sol['control'].data

However, I get the error: AttributeError: 'list' object has no attribute 'function_space'

Any help is greatly appreciated.

Hi,

I believe this should work:

u_moola = moola.DolfinPrimalVector(u)
d_moola = moola.DolfinPrimalVector(d)
m_moola = moola.DolfinPrimalVectorSet([u_moola, d_moola])
1 Like

Thank you so much. It resolved my problem!