- marked as proposal
Failed nonlinear solves get recorded on tape even though no value is recorded
Issue #8
new
Sometimes optimization algorithms can go into areas of parameter space where a nonlinear solver crashes. If one has no a-priori guarantee of convergence then the best one can do is tune some parameters and try again. Unfortunately the failed solve attempts get recorded by dolfin-adjoint, as the script below demonstrates.
from dolfin import *
from dolfin_adjoint import *
mesh = UnitSquareMesh(3,3)
V = FunctionSpace(mesh, "CG",1)
u = Function(V)
v = TestFunction(V)
alpha = Constant(1.0e10)
F = inner(grad(u), grad(v))*dx + alpha*u**2*v*dx
bc = DirichletBC(V, Expression("x[0]"), "on_boundary")
try:
#I am going to fail
solve(F == 0, u, bc)
except:
#Oops alpha was too big better try something smaller.
alpha.assign(1.0)
#Now I can solve the problem!
solve(F == 0, u, bc)
I = Functional(u*dx)
Rd = ReducedFunctional(I, Control(alpha))
#I get confused by the solve that failed.
Rd.derivative()
Comments (1)
-
- Log in to comment