xref: /petsc/doc/manual/tao.md (revision 7f296bb328fcd4c99f2da7bfe8ba7ed8a4ebceee)
1*7f296bb3SBarry Smith(ch_tao)=
2*7f296bb3SBarry Smith
3*7f296bb3SBarry Smith# TAO: Optimization Solvers
4*7f296bb3SBarry Smith
5*7f296bb3SBarry SmithThe Toolkit for Advanced Optimization (TAO) focuses on algorithms for the
6*7f296bb3SBarry Smithsolution of large-scale optimization problems on high-performance
7*7f296bb3SBarry Smitharchitectures. Methods are available for
8*7f296bb3SBarry Smith
9*7f296bb3SBarry Smith- {any}`sec_tao_leastsquares`
10*7f296bb3SBarry Smith- {any}`sec_tao_quadratic`
11*7f296bb3SBarry Smith- {any}`sec_tao_unconstrained`
12*7f296bb3SBarry Smith- {any}`sec_tao_bound`
13*7f296bb3SBarry Smith- {any}`sec_tao_constrained`
14*7f296bb3SBarry Smith- {any}`sec_tao_complementary`
15*7f296bb3SBarry Smith- {any}`sec_tao_pde_constrained`
16*7f296bb3SBarry Smith
17*7f296bb3SBarry Smith(sec_tao_getting_started)=
18*7f296bb3SBarry Smith
19*7f296bb3SBarry Smith## Getting Started: A Simple TAO Example
20*7f296bb3SBarry Smith
21*7f296bb3SBarry SmithTo help the user start using TAO immediately, we introduce here a simple
22*7f296bb3SBarry Smithuniprocessor example. Please read {any}`sec_tao_solvers`
23*7f296bb3SBarry Smithfor a more in-depth discussion on using the TAO solvers. The code
24*7f296bb3SBarry Smithpresented {any}`below <tao_example1>` minimizes the
25*7f296bb3SBarry Smithextended Rosenbrock function $f: \mathbb R^n \to \mathbb R$
26*7f296bb3SBarry Smithdefined by
27*7f296bb3SBarry Smith
28*7f296bb3SBarry Smith$$
29*7f296bb3SBarry Smithf(x) = \sum_{i=0}^{m-1} \left( \alpha(x_{2i+1}-x_{2i}^2)^2 + (1-x_{2i})^2 \right),
30*7f296bb3SBarry Smith$$
31*7f296bb3SBarry Smith
32*7f296bb3SBarry Smithwhere $n = 2m$ is the number of variables. Note that while we use
33*7f296bb3SBarry Smiththe C language to introduce the TAO software, the package is fully
34*7f296bb3SBarry Smithusable from C++ and Fortran.
35*7f296bb3SBarry Smith{any}`ch_fortran` discusses additional
36*7f296bb3SBarry Smithissues concerning Fortran usage.
37*7f296bb3SBarry Smith
38*7f296bb3SBarry SmithThe code in {any}`the example <tao_example1>` contains many of
39*7f296bb3SBarry Smiththe components needed to write most TAO programs and thus is
40*7f296bb3SBarry Smithillustrative of the features present in complex optimization problems.
41*7f296bb3SBarry SmithNote that for display purposes we have omitted some nonessential lines
42*7f296bb3SBarry Smithof code as well as the (essential) code required for the routine
43*7f296bb3SBarry Smith`FormFunctionGradient`, which evaluates the function and gradient, and
44*7f296bb3SBarry Smiththe code for `FormHessian`, which evaluates the Hessian matrix for
45*7f296bb3SBarry SmithRosenbrock’s function. The complete code is available in
46*7f296bb3SBarry Smith<a href="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/unconstrained/tutorials/rosenbrock1.c.html">\$TAO_DIR/src/unconstrained/tutorials/rosenbrock1.c</a>.
47*7f296bb3SBarry SmithThe following sections annotate the lines of code in
48*7f296bb3SBarry Smith{any}`the example <tao_example1>`.
49*7f296bb3SBarry Smith
50*7f296bb3SBarry Smith(tao_example1)=
51*7f296bb3SBarry Smith
52*7f296bb3SBarry Smith:::{admonition} Listing: `src/tao/unconstrained/tutorials/rosenbrock1.c`
53*7f296bb3SBarry Smith```{literalinclude} /../src/tao/unconstrained/tutorials/rosenbrock1.c
54*7f296bb3SBarry Smith:append: return ierr;}
55*7f296bb3SBarry Smith:end-at: PetscFinalize
56*7f296bb3SBarry Smith:prepend: '#include <petsctao.h>'
57*7f296bb3SBarry Smith:start-at: typedef struct
58*7f296bb3SBarry Smith```
59*7f296bb3SBarry Smith:::
60*7f296bb3SBarry Smith
61*7f296bb3SBarry Smith(sec_tao_workflow)=
62*7f296bb3SBarry Smith
63*7f296bb3SBarry Smith## TAO Workflow
64*7f296bb3SBarry Smith
65*7f296bb3SBarry SmithMany TAO applications will follow an ordered set of procedures for
66*7f296bb3SBarry Smithsolving an optimization problem: The user creates a `Tao` context and
67*7f296bb3SBarry Smithselects a default algorithm. Call-back routines as well as vector
68*7f296bb3SBarry Smith(`Vec`) and matrix (`Mat`) data structures are then set. These
69*7f296bb3SBarry Smithcall-back routines will be used for evaluating the objective function,
70*7f296bb3SBarry Smithgradient, and perhaps the Hessian matrix. The user then invokes TAO to
71*7f296bb3SBarry Smithsolve the optimization problem and finally destroys the `Tao` context.
72*7f296bb3SBarry SmithA list of the necessary functions for performing these steps using TAO
73*7f296bb3SBarry Smithis shown below.
74*7f296bb3SBarry Smith
75*7f296bb3SBarry Smith```
76*7f296bb3SBarry SmithTaoCreate(MPI_Comm comm, Tao *tao);
77*7f296bb3SBarry SmithTaoSetType(Tao tao, TaoType type);
78*7f296bb3SBarry SmithTaoSetSolution(Tao tao, Vec x);
79*7f296bb3SBarry SmithTaoSetObjectiveAndGradient(Tao tao, Vec g, PetscErrorCode (*FormFGradient)(Tao, Vec, PetscReal*, Vec, void*), void *user);
80*7f296bb3SBarry SmithTaoSetHessian(Tao tao, Mat H, Mat Hpre, PetscErrorCode (*FormHessian)(Tao, Vec, Mat, Mat, void*), void *user);
81*7f296bb3SBarry SmithTaoSolve(Tao tao);
82*7f296bb3SBarry SmithTaoDestroy(Tao tao);
83*7f296bb3SBarry Smith```
84*7f296bb3SBarry Smith
85*7f296bb3SBarry SmithNote that the solver algorithm selected through the function
86*7f296bb3SBarry Smith`TaoSetType()` can be overridden at runtime by using an options
87*7f296bb3SBarry Smithdatabase. Through this database, the user not only can select a
88*7f296bb3SBarry Smithminimization method (e.g., limited-memory variable metric, conjugate
89*7f296bb3SBarry Smithgradient, Newton with line search or trust region) but also can
90*7f296bb3SBarry Smithprescribe the convergence tolerance, set various monitoring routines,
91*7f296bb3SBarry Smithset iterative methods and preconditions for solving the linear systems,
92*7f296bb3SBarry Smithand so forth. See {any}`sec_tao_solvers` for more
93*7f296bb3SBarry Smithinformation on the solver methods available in TAO.
94*7f296bb3SBarry Smith
95*7f296bb3SBarry Smith### Header File
96*7f296bb3SBarry Smith
97*7f296bb3SBarry SmithTAO applications written in C/C++ should have the statement
98*7f296bb3SBarry Smith
99*7f296bb3SBarry Smith```
100*7f296bb3SBarry Smith#include <petsctao.h>
101*7f296bb3SBarry Smith```
102*7f296bb3SBarry Smith
103*7f296bb3SBarry Smithin each file that uses a routine in the TAO libraries.
104*7f296bb3SBarry Smith
105*7f296bb3SBarry Smith### Creation and Destruction
106*7f296bb3SBarry Smith
107*7f296bb3SBarry SmithA TAO solver can be created by calling the
108*7f296bb3SBarry Smith
109*7f296bb3SBarry Smith```
110*7f296bb3SBarry SmithTaoCreate(MPI_Comm, Tao*);
111*7f296bb3SBarry Smith```
112*7f296bb3SBarry Smith
113*7f296bb3SBarry Smithroutine. Much like creating PETSc vector and matrix objects, the first
114*7f296bb3SBarry Smithargument is an MPI *communicator*. An MPI [^mpi]
115*7f296bb3SBarry Smithcommunicator indicates a collection of processors that will be used to
116*7f296bb3SBarry Smithevaluate the objective function, compute constraints, and provide
117*7f296bb3SBarry Smithderivative information. When only one processor is being used, the
118*7f296bb3SBarry Smithcommunicator `PETSC_COMM_SELF` can be used with no understanding of
119*7f296bb3SBarry SmithMPI. Even parallel users need to be familiar with only the basic
120*7f296bb3SBarry Smithconcepts of message passing and distributed-memory computing. Most
121*7f296bb3SBarry Smithapplications running TAO in parallel environments can employ the
122*7f296bb3SBarry Smithcommunicator `PETSC_COMM_WORLD` to indicate all processes known to
123*7f296bb3SBarry SmithPETSc in a given run.
124*7f296bb3SBarry Smith
125*7f296bb3SBarry SmithThe routine
126*7f296bb3SBarry Smith
127*7f296bb3SBarry Smith```
128*7f296bb3SBarry SmithTaoSetType(Tao, TaoType);
129*7f296bb3SBarry Smith```
130*7f296bb3SBarry Smith
131*7f296bb3SBarry Smithcan be used to set the algorithm TAO uses to solve the application. The
132*7f296bb3SBarry Smithvarious types of TAO solvers and the flags that identify them will be
133*7f296bb3SBarry Smithdiscussed in the following sections. The solution method should be
134*7f296bb3SBarry Smithcarefully chosen depending on the problem being solved. Some solvers,
135*7f296bb3SBarry Smithfor instance, are meant for problems with no constraints, whereas other
136*7f296bb3SBarry Smithsolvers acknowledge constraints in the problem and handle them
137*7f296bb3SBarry Smithaccordingly. The user must also be aware of the derivative information
138*7f296bb3SBarry Smiththat is available. Some solvers require second-order information, while
139*7f296bb3SBarry Smithother solvers require only gradient or function information. The command
140*7f296bb3SBarry Smithline option `-tao_type` followed by
141*7f296bb3SBarry Smitha TAO method will override any method specified by the second argument.
142*7f296bb3SBarry SmithThe command line option `-tao_type bqnls`, for instance, will
143*7f296bb3SBarry Smithspecify the limited-memory quasi-Newton line search method for
144*7f296bb3SBarry Smithbound-constrained problems. Note that the `TaoType` variable is a string that
145*7f296bb3SBarry Smithrequires quotation marks in an application program, but quotation marks
146*7f296bb3SBarry Smithare not required at the command line.
147*7f296bb3SBarry Smith
148*7f296bb3SBarry SmithEach TAO solver that has been created should also be destroyed by using
149*7f296bb3SBarry Smiththe
150*7f296bb3SBarry Smith
151*7f296bb3SBarry Smith```
152*7f296bb3SBarry SmithTaoDestroy(Tao tao);
153*7f296bb3SBarry Smith```
154*7f296bb3SBarry Smith
155*7f296bb3SBarry Smithcommand. This routine frees the internal data structures used by the
156*7f296bb3SBarry Smithsolver.
157*7f296bb3SBarry Smith
158*7f296bb3SBarry Smith### Command-line Options
159*7f296bb3SBarry Smith
160*7f296bb3SBarry SmithAdditional options for the TAO solver can be set from the command
161*7f296bb3SBarry Smithline by using the
162*7f296bb3SBarry Smith
163*7f296bb3SBarry Smith```
164*7f296bb3SBarry SmithTaoSetFromOptions(Tao)
165*7f296bb3SBarry Smith```
166*7f296bb3SBarry Smith
167*7f296bb3SBarry Smithroutine. This command also provides information about runtime options
168*7f296bb3SBarry Smithwhen the user includes the `-help` option on the command line.
169*7f296bb3SBarry Smith
170*7f296bb3SBarry SmithIn addition to common command line options shared by all TAO solvers, each TAO
171*7f296bb3SBarry Smithmethod also implements its own specialized options. Please refer to the
172*7f296bb3SBarry Smithdocumentation for individual methods for more details.
173*7f296bb3SBarry Smith
174*7f296bb3SBarry Smith### Defining Variables
175*7f296bb3SBarry Smith
176*7f296bb3SBarry SmithIn all the optimization solvers, the application must provide a `Vec`
177*7f296bb3SBarry Smithobject of appropriate dimension to represent the variables. This vector
178*7f296bb3SBarry Smithwill be cloned by the solvers to create additional work space within the
179*7f296bb3SBarry Smithsolver. If this vector is distributed over multiple processors, it
180*7f296bb3SBarry Smithshould have a parallel distribution that allows for efficient scaling,
181*7f296bb3SBarry Smithinner products, and function evaluations. This vector can be passed to
182*7f296bb3SBarry Smiththe application object by using the
183*7f296bb3SBarry Smith
184*7f296bb3SBarry Smith```
185*7f296bb3SBarry SmithTaoSetSolution(Tao, Vec);
186*7f296bb3SBarry Smith```
187*7f296bb3SBarry Smith
188*7f296bb3SBarry Smithroutine. When using this routine, the application should initialize the
189*7f296bb3SBarry Smithvector with an approximate solution of the optimization problem before
190*7f296bb3SBarry Smithcalling the TAO solver. This vector will be used by the TAO solver to
191*7f296bb3SBarry Smithstore the solution. Elsewhere in the application, this solution vector
192*7f296bb3SBarry Smithcan be retrieved from the application object by using the
193*7f296bb3SBarry Smith
194*7f296bb3SBarry Smith```
195*7f296bb3SBarry SmithTaoGetSolution(Tao, Vec*);
196*7f296bb3SBarry Smith```
197*7f296bb3SBarry Smith
198*7f296bb3SBarry Smithroutine. This routine takes the address of a `Vec` in the second
199*7f296bb3SBarry Smithargument and sets it to the solution vector used in the application.
200*7f296bb3SBarry Smith
201*7f296bb3SBarry Smith### User Defined Call-back Routines
202*7f296bb3SBarry Smith
203*7f296bb3SBarry SmithUsers of TAO are required to provide routines that perform function
204*7f296bb3SBarry Smithevaluations. Depending on the solver chosen, they may also have to write
205*7f296bb3SBarry Smithroutines that evaluate the gradient vector and Hessian matrix.
206*7f296bb3SBarry Smith
207*7f296bb3SBarry Smith#### Application Context
208*7f296bb3SBarry Smith
209*7f296bb3SBarry SmithWriting a TAO application may require use of an *application context*.
210*7f296bb3SBarry SmithAn application context is a structure or object defined by an
211*7f296bb3SBarry Smithapplication developer, passed into a routine also written by the
212*7f296bb3SBarry Smithapplication developer, and used within the routine to perform its stated
213*7f296bb3SBarry Smithtask.
214*7f296bb3SBarry Smith
215*7f296bb3SBarry SmithFor example, a routine that evaluates an objective function may need
216*7f296bb3SBarry Smithparameters, work vectors, and other information. This information, which
217*7f296bb3SBarry Smithmay be specific to an application and necessary to evaluate the
218*7f296bb3SBarry Smithobjective, can be collected in a single structure and used as one of the
219*7f296bb3SBarry Smitharguments in the routine. The address of this structure will be cast as
220*7f296bb3SBarry Smithtype `(void*)` and passed to the routine in the final argument. Many
221*7f296bb3SBarry Smithexamples of these structures are included in the TAO distribution.
222*7f296bb3SBarry Smith
223*7f296bb3SBarry SmithThis technique offers several advantages. In particular, it allows for a
224*7f296bb3SBarry Smithuniform interface between TAO and the applications. The fundamental
225*7f296bb3SBarry Smithinformation needed by TAO appears in the arguments of the routine, while
226*7f296bb3SBarry Smithdata specific to an application and its implementation is confined to an
227*7f296bb3SBarry Smithopaque pointer. The routines can access information created outside the
228*7f296bb3SBarry Smithlocal scope without the use of global variables. The TAO solvers and
229*7f296bb3SBarry Smithapplication objects will never access this structure, so the application
230*7f296bb3SBarry Smithdeveloper has complete freedom to define it. If no such structure or
231*7f296bb3SBarry Smithneeded by the application then a NULL pointer can be used.
232*7f296bb3SBarry Smith
233*7f296bb3SBarry Smith(sec_tao_fghj)=
234*7f296bb3SBarry Smith
235*7f296bb3SBarry Smith#### Objective Function and Gradient Routines
236*7f296bb3SBarry Smith
237*7f296bb3SBarry SmithTAO solvers that minimize an objective function require the application
238*7f296bb3SBarry Smithto evaluate the objective function. Some solvers may also require the
239*7f296bb3SBarry Smithapplication to evaluate derivatives of the objective function. Routines
240*7f296bb3SBarry Smiththat perform these computations must be identified to the application
241*7f296bb3SBarry Smithobject and must follow a strict calling sequence.
242*7f296bb3SBarry Smith
243*7f296bb3SBarry SmithRoutines should follow the form
244*7f296bb3SBarry Smith
245*7f296bb3SBarry Smith```
246*7f296bb3SBarry SmithPetscErrorCode EvaluateObjective(Tao, Vec, PetscReal*, void*);
247*7f296bb3SBarry Smith```
248*7f296bb3SBarry Smith
249*7f296bb3SBarry Smithin order to evaluate an objective function
250*7f296bb3SBarry Smith$f: \, \mathbb R^n \to \mathbb R$. The first argument is the TAO
251*7f296bb3SBarry SmithSolver object, the second argument is the $n$-dimensional vector
252*7f296bb3SBarry Smiththat identifies where the objective should be evaluated, and the fourth
253*7f296bb3SBarry Smithargument is an application context. This routine should use the third
254*7f296bb3SBarry Smithargument to return the objective value evaluated at the point specified
255*7f296bb3SBarry Smithby the vector in the second argument.
256*7f296bb3SBarry Smith
257*7f296bb3SBarry SmithThis routine, and the application context, should be passed to the
258*7f296bb3SBarry Smithapplication object by using the
259*7f296bb3SBarry Smith
260*7f296bb3SBarry Smith```
261*7f296bb3SBarry SmithTaoSetObjective(Tao, PetscErrorCode(*)(Tao,Vec,PetscReal*,void*), void*);
262*7f296bb3SBarry Smith```
263*7f296bb3SBarry Smith
264*7f296bb3SBarry Smithroutine. The first argument in this routine is the TAO solver object,
265*7f296bb3SBarry Smiththe second argument is a function pointer to the routine that evaluates
266*7f296bb3SBarry Smiththe objective, and the third argument is the pointer to an appropriate
267*7f296bb3SBarry Smithapplication context. Although the final argument may point to anything,
268*7f296bb3SBarry Smithit must be cast as a `(void*)` type. This pointer will be passed back
269*7f296bb3SBarry Smithto the developer in the fourth argument of the routine that evaluates
270*7f296bb3SBarry Smiththe objective. In this routine, the pointer can be cast back to the
271*7f296bb3SBarry Smithappropriate type. Examples of these structures and their usage are
272*7f296bb3SBarry Smithprovided in the distribution.
273*7f296bb3SBarry Smith
274*7f296bb3SBarry SmithMany TAO solvers also require gradient information from the application
275*7f296bb3SBarry SmithThe gradient of the objective function is specified in a similar manner.
276*7f296bb3SBarry SmithRoutines that evaluate the gradient should have the calling sequence
277*7f296bb3SBarry Smith
278*7f296bb3SBarry Smith```
279*7f296bb3SBarry SmithPetscErrorCode EvaluateGradient(Tao, Vec, Vec, void*);
280*7f296bb3SBarry Smith```
281*7f296bb3SBarry Smith
282*7f296bb3SBarry Smithwhere the first argument is the TAO solver object, the second argument
283*7f296bb3SBarry Smithis the variable vector, the third argument is the gradient vector, and
284*7f296bb3SBarry Smiththe fourth argument is the user-defined application context. Only the
285*7f296bb3SBarry Smiththird argument in this routine is different from the arguments in the
286*7f296bb3SBarry Smithroutine for evaluating the objective function. The numbers in the
287*7f296bb3SBarry Smithgradient vector have no meaning when passed into this routine, but they
288*7f296bb3SBarry Smithshould represent the gradient of the objective at the specified point at
289*7f296bb3SBarry Smiththe end of the routine. This routine, and the user-defined pointer, can
290*7f296bb3SBarry Smithbe passed to the application object by using the
291*7f296bb3SBarry Smith
292*7f296bb3SBarry Smith```
293*7f296bb3SBarry SmithTaoSetGradient(Tao, Vec, PetscErrorCode (*)(Tao,Vec,Vec,void*), void*);
294*7f296bb3SBarry Smith```
295*7f296bb3SBarry Smith
296*7f296bb3SBarry Smithroutine. In this routine, the first argument is the Tao object, the second
297*7f296bb3SBarry Smithargument is the optional vector to hold the computed gradient, the
298*7f296bb3SBarry Smiththird argument is the function pointer, and the fourth object is the
299*7f296bb3SBarry Smithapplication context, cast to `(void*)`.
300*7f296bb3SBarry Smith
301*7f296bb3SBarry SmithInstead of evaluating the objective and its gradient in separate
302*7f296bb3SBarry Smithroutines, TAO also allows the user to evaluate the function and the
303*7f296bb3SBarry Smithgradient in the same routine. In fact, some solvers are more efficient
304*7f296bb3SBarry Smithwhen both function and gradient information can be computed in the same
305*7f296bb3SBarry Smithroutine. These routines should follow the form
306*7f296bb3SBarry Smith
307*7f296bb3SBarry Smith```
308*7f296bb3SBarry SmithPetscErrorCode EvaluateFunctionAndGradient(Tao, Vec, PetscReal*, Vec, void*);
309*7f296bb3SBarry Smith```
310*7f296bb3SBarry Smith
311*7f296bb3SBarry Smithwhere the first argument is the TAO solver and the second argument
312*7f296bb3SBarry Smithpoints to the input vector for use in evaluating the function and
313*7f296bb3SBarry Smithgradient. The third argument should return the function value, while the
314*7f296bb3SBarry Smithfourth argument should return the gradient vector. The fifth argument is
315*7f296bb3SBarry Smitha pointer to a user-defined context. This context and the name of the
316*7f296bb3SBarry Smithroutine should be set with the call
317*7f296bb3SBarry Smith
318*7f296bb3SBarry Smith```
319*7f296bb3SBarry SmithTaoSetObjectiveAndGradient(Tao, Vec PetscErrorCode (*)(Tao,Vec,PetscReal*,Vec,void*), void*);
320*7f296bb3SBarry Smith```
321*7f296bb3SBarry Smith
322*7f296bb3SBarry Smithwhere the arguments are the TAO application, the optional vector to be
323*7f296bb3SBarry Smithused to hold the computed gradient, a function pointer, and a
324*7f296bb3SBarry Smithpointer to a user-defined context.
325*7f296bb3SBarry Smith
326*7f296bb3SBarry SmithThe TAO example problems demonstrate the use of these application
327*7f296bb3SBarry Smithcontexts as well as specific instances of function, gradient, and
328*7f296bb3SBarry SmithHessian evaluation routines. All these routines should return the
329*7f296bb3SBarry Smithinteger $0$ after successful completion and a nonzero integer if
330*7f296bb3SBarry Smiththe function is undefined at that point or an error occurred.
331*7f296bb3SBarry Smith
332*7f296bb3SBarry Smith(sec_tao_matrixfree)=
333*7f296bb3SBarry Smith
334*7f296bb3SBarry Smith#### Hessian Evaluation
335*7f296bb3SBarry Smith
336*7f296bb3SBarry SmithSome optimization routines also require a Hessian matrix from the user.
337*7f296bb3SBarry SmithThe routine that evaluates the Hessian should have the form
338*7f296bb3SBarry Smith
339*7f296bb3SBarry Smith```
340*7f296bb3SBarry SmithPetscErrorCode EvaluateHessian(Tao, Vec, Mat, Mat, void*);
341*7f296bb3SBarry Smith```
342*7f296bb3SBarry Smith
343*7f296bb3SBarry Smithwhere the first argument of this routine is a TAO solver object. The
344*7f296bb3SBarry Smithsecond argument is the point at which the Hessian should be evaluated.
345*7f296bb3SBarry SmithThe third argument is the Hessian matrix, and the sixth argument is a
346*7f296bb3SBarry Smithuser-defined context. Since the Hessian matrix is usually used in
347*7f296bb3SBarry Smithsolving a system of linear equations, a preconditioner for the matrix is
348*7f296bb3SBarry Smithoften needed. The fourth argument is the matrix that will be used for
349*7f296bb3SBarry Smithpreconditioning the linear system; in most cases, this matrix will be
350*7f296bb3SBarry Smiththe same as the Hessian matrix. The fifth argument is the flag used to
351*7f296bb3SBarry Smithset the Hessian matrix and linear solver in the routine
352*7f296bb3SBarry Smith`KSPSetOperators()`.
353*7f296bb3SBarry Smith
354*7f296bb3SBarry SmithOne can set the Hessian evaluation routine by calling the
355*7f296bb3SBarry Smith
356*7f296bb3SBarry Smith```
357*7f296bb3SBarry SmithTaoSetHessian(Tao, Mat, Mat, PetscErrorCode (*)(Tao,Vec,Mat,Mat,void*), void*);
358*7f296bb3SBarry Smith```
359*7f296bb3SBarry Smith
360*7f296bb3SBarry Smithroutine. The first argument is the TAO Solver object. The second and
361*7f296bb3SBarry Smiththird arguments are, respectively, the Mat object where the Hessian will
362*7f296bb3SBarry Smithbe stored and the Mat object that will be used for the preconditioning
363*7f296bb3SBarry Smith(they may be the same). The fourth argument is the function that
364*7f296bb3SBarry Smithevaluates the Hessian, and the fifth argument is a pointer to a
365*7f296bb3SBarry Smithuser-defined context, cast to `(void*)`.
366*7f296bb3SBarry Smith
367*7f296bb3SBarry Smith##### Finite Differences
368*7f296bb3SBarry Smith
369*7f296bb3SBarry SmithFinite-difference approximations can be used to compute the gradient and
370*7f296bb3SBarry Smiththe Hessian of an objective function. These approximations will slow the
371*7f296bb3SBarry Smithsolve considerably and are recommended primarily for checking the
372*7f296bb3SBarry Smithaccuracy of hand-coded gradients and Hessians. These routines are
373*7f296bb3SBarry Smith
374*7f296bb3SBarry Smith```
375*7f296bb3SBarry SmithTaoDefaultComputeGradient(Tao, Vec, Vec, void*);
376*7f296bb3SBarry Smith```
377*7f296bb3SBarry Smith
378*7f296bb3SBarry Smithand
379*7f296bb3SBarry Smith
380*7f296bb3SBarry Smith```
381*7f296bb3SBarry SmithTaoDefaultComputeHessian(Tao, Vec, Mat*, Mat*,void*);
382*7f296bb3SBarry Smith```
383*7f296bb3SBarry Smith
384*7f296bb3SBarry Smithrespectively. They can be set by using `TaoSetGradient()` and
385*7f296bb3SBarry Smith`TaoSetHessian()` or through the options database with the
386*7f296bb3SBarry Smithoptions `-tao_fdgrad` and `-tao_fd`, respectively.
387*7f296bb3SBarry Smith
388*7f296bb3SBarry SmithThe efficiency of the finite-difference Hessian can be improved if the
389*7f296bb3SBarry Smithcoloring of the matrix is known. If the application programmer creates a
390*7f296bb3SBarry SmithPETSc `MatFDColoring` object, it can be applied to the
391*7f296bb3SBarry Smithfinite-difference approximation by setting the Hessian evaluation
392*7f296bb3SBarry Smithroutine to
393*7f296bb3SBarry Smith
394*7f296bb3SBarry Smith```
395*7f296bb3SBarry SmithTaoDefaultComputeHessianColor(Tao, Vec, Mat*, Mat*, void*);
396*7f296bb3SBarry Smith```
397*7f296bb3SBarry Smith
398*7f296bb3SBarry Smithand using the `MatFDColoring` object as the last (`void *`) argument
399*7f296bb3SBarry Smithto `TaoSetHessian()`.
400*7f296bb3SBarry Smith
401*7f296bb3SBarry SmithOne also can use finite-difference approximations to directly check the
402*7f296bb3SBarry Smithcorrectness of the gradient and/or Hessian evaluation routines. This
403*7f296bb3SBarry Smithprocess can be initiated from the command line by using the special TAO
404*7f296bb3SBarry Smithsolver `tao_fd_test` together with the option `-tao_test_gradient`
405*7f296bb3SBarry Smithor `-tao_test_hessian`.
406*7f296bb3SBarry Smith
407*7f296bb3SBarry Smith##### Matrix-Free Methods
408*7f296bb3SBarry Smith
409*7f296bb3SBarry SmithTAO fully supports matrix-free methods. The matrices specified in the
410*7f296bb3SBarry SmithHessian evaluation routine need not be conventional matrices; instead,
411*7f296bb3SBarry Smiththey can point to the data required to implement a particular
412*7f296bb3SBarry Smithmatrix-free method. The matrix-free variant is allowed *only* when the
413*7f296bb3SBarry Smithlinear systems are solved by an iterative method in combination with no
414*7f296bb3SBarry Smithpreconditioning (`PCNONE` or `-pc_type none`), a user-provided
415*7f296bb3SBarry Smithpreconditioner matrix, or a user-provided preconditioner shell
416*7f296bb3SBarry Smith(`PCSHELL`). In other words, matrix-free methods cannot be used if a
417*7f296bb3SBarry Smithdirect solver is to be employed. Details about using matrix-free methods
418*7f296bb3SBarry Smithare provided in the {doc}`/manual/index`.
419*7f296bb3SBarry Smith
420*7f296bb3SBarry Smith:::{figure} /images/manual/taofig.svg
421*7f296bb3SBarry Smith:name: fig_taocallbacks
422*7f296bb3SBarry Smith
423*7f296bb3SBarry SmithTao use of PETSc and callbacks
424*7f296bb3SBarry Smith:::
425*7f296bb3SBarry Smith
426*7f296bb3SBarry Smith(sec_tao_bounds)=
427*7f296bb3SBarry Smith
428*7f296bb3SBarry Smith#### Constraints
429*7f296bb3SBarry Smith
430*7f296bb3SBarry SmithSome optimization problems also impose constraints on the variables or
431*7f296bb3SBarry Smithintermediate application states. The user defines these constraints through
432*7f296bb3SBarry Smiththe appropriate TAO interface functions and call-back routines where necessary.
433*7f296bb3SBarry Smith
434*7f296bb3SBarry Smith##### Variable Bounds
435*7f296bb3SBarry Smith
436*7f296bb3SBarry SmithThe simplest type of constraint on an optimization problem puts lower or
437*7f296bb3SBarry Smithupper bounds on the variables. Vectors that represent lower and upper
438*7f296bb3SBarry Smithbounds for each variable can be set with the
439*7f296bb3SBarry Smith
440*7f296bb3SBarry Smith```
441*7f296bb3SBarry SmithTaoSetVariableBounds(Tao, Vec, Vec);
442*7f296bb3SBarry Smith```
443*7f296bb3SBarry Smith
444*7f296bb3SBarry Smithcommand. The first vector and second vector should contain the lower and
445*7f296bb3SBarry Smithupper bounds, respectively. When no upper or lower bound exists for a
446*7f296bb3SBarry Smithvariable, the bound may be set to `PETSC_INFINITY` or `PETSC_NINFINITY`.
447*7f296bb3SBarry SmithAfter the two bound vectors have been set, they may be accessed with the
448*7f296bb3SBarry Smithcommand `TaoGetVariableBounds()`.
449*7f296bb3SBarry Smith
450*7f296bb3SBarry SmithSince not all solvers recognize the presence of bound constraints on
451*7f296bb3SBarry Smithvariables, the user must be careful to select a solver that acknowledges
452*7f296bb3SBarry Smiththese bounds.
453*7f296bb3SBarry Smith
454*7f296bb3SBarry Smith(sec_tao_programming)=
455*7f296bb3SBarry Smith
456*7f296bb3SBarry Smith##### General Constraints
457*7f296bb3SBarry Smith
458*7f296bb3SBarry SmithSome TAO algorithms also support general constraints as a linear or nonlinear
459*7f296bb3SBarry Smithfunction of the optimization variables. These constraints can be imposed either
460*7f296bb3SBarry Smithas equalities or inequalities. TAO currently does not make any distinctions
461*7f296bb3SBarry Smithbetween linear and nonlinear constraints, and implements them through the
462*7f296bb3SBarry Smithsame software interfaces.
463*7f296bb3SBarry Smith
464*7f296bb3SBarry SmithIn the equality constrained case, TAO assumes that the constraints are
465*7f296bb3SBarry Smithformulated as $c_e(x) = 0$ and requires the user to implement a call-back
466*7f296bb3SBarry Smithroutine for evaluating $c_e(x)$ at a given vector of optimization
467*7f296bb3SBarry Smithvariables,
468*7f296bb3SBarry Smith
469*7f296bb3SBarry Smith```
470*7f296bb3SBarry SmithPetscErrorCode EvaluateEqualityConstraints(Tao, Vec, Vec, void*);
471*7f296bb3SBarry Smith```
472*7f296bb3SBarry Smith
473*7f296bb3SBarry SmithAs in the previous call-back routines, the first argument is the TAO solver
474*7f296bb3SBarry Smithobject. The second and third arguments are the vector of optimization variables
475*7f296bb3SBarry Smith(input) and vector of equality constraints (output), respectively. The final
476*7f296bb3SBarry Smithargument is a pointer to the user-defined application context, cast into
477*7f296bb3SBarry Smith`(void*)`.
478*7f296bb3SBarry Smith
479*7f296bb3SBarry SmithGenerally constrained TAO algorithms also require a second user call-back
480*7f296bb3SBarry Smithfunction to compute the constraint Jacobian matrix $\nabla_x c_e(x)$,
481*7f296bb3SBarry Smith
482*7f296bb3SBarry Smith```
483*7f296bb3SBarry SmithPetscErrorCode EvaluateEqualityJacobian(Tao, Vec, Mat, Mat, void*);
484*7f296bb3SBarry Smith```
485*7f296bb3SBarry Smith
486*7f296bb3SBarry Smithwhere the first and last arguments are the TAO solver object and the application
487*7f296bb3SBarry Smithcontext pointer as before. The second argument is the vector of optimization
488*7f296bb3SBarry Smithvariables at which the computation takes place. The third and fourth arguments
489*7f296bb3SBarry Smithare the constraint Jacobian and its pseudo-inverse (optional), respectively. The
490*7f296bb3SBarry Smithpseudoinverse is optional, and if not available, the user can simply set it
491*7f296bb3SBarry Smithto the constraint Jacobian itself.
492*7f296bb3SBarry Smith
493*7f296bb3SBarry SmithThese call-back functions are then given to the TAO solver using the
494*7f296bb3SBarry Smithinterface functions
495*7f296bb3SBarry Smith
496*7f296bb3SBarry Smith```
497*7f296bb3SBarry SmithTaoSetEqualityConstraintsRoutine(Tao, Vec, PetscErrorCode (*)(Tao,Vec,Vec,void*), void*);
498*7f296bb3SBarry Smith```
499*7f296bb3SBarry Smith
500*7f296bb3SBarry Smithand
501*7f296bb3SBarry Smith
502*7f296bb3SBarry Smith```
503*7f296bb3SBarry SmithTaoSetJacobianEqualityRoutine(Tao, Mat, Mat, PetscErrorCode (*)(Tao,Vec,Mat,Mat,void*), void*);
504*7f296bb3SBarry Smith```
505*7f296bb3SBarry Smith
506*7f296bb3SBarry SmithInequality constraints are assumed to be formulated as $c_i(x) \leq 0$
507*7f296bb3SBarry Smithand follow the same workflow as equality constraints using the
508*7f296bb3SBarry Smith`TaoSetInequalityConstraintsRoutine()` and `TaoSetJacobianInequalityRoutine()`
509*7f296bb3SBarry Smithinterfaces.
510*7f296bb3SBarry Smith
511*7f296bb3SBarry SmithSome TAO algorithms may adopt an alternative double-sided
512*7f296bb3SBarry Smith$c_l \leq c_i(x) \leq c_u$ formulation and require the lower and upper
513*7f296bb3SBarry Smithbounds $c_l$ and $c_u$ to be set using the
514*7f296bb3SBarry Smith`TaoSetInequalityBounds(Tao,Vec,Vec)` interface. Please refer to the
515*7f296bb3SBarry Smithdocumentation for each TAO algorithm for further details.
516*7f296bb3SBarry Smith
517*7f296bb3SBarry Smith### Solving
518*7f296bb3SBarry Smith
519*7f296bb3SBarry SmithOnce the application and solver have been set up, the solver can be
520*7f296bb3SBarry Smith
521*7f296bb3SBarry Smith```
522*7f296bb3SBarry SmithTaoSolve(Tao);
523*7f296bb3SBarry Smith```
524*7f296bb3SBarry Smith
525*7f296bb3SBarry Smithroutine. We discuss several universal options below.
526*7f296bb3SBarry Smith
527*7f296bb3SBarry Smith(sec_tao_customize)=
528*7f296bb3SBarry Smith
529*7f296bb3SBarry Smith#### Convergence
530*7f296bb3SBarry Smith
531*7f296bb3SBarry SmithAlthough TAO and its solvers set default parameters that are useful for
532*7f296bb3SBarry Smithmany problems, the user may need to modify these parameters in order to
533*7f296bb3SBarry Smithchange the behavior and convergence of various algorithms.
534*7f296bb3SBarry Smith
535*7f296bb3SBarry SmithOne convergence criterion for most algorithms concerns the number of
536*7f296bb3SBarry Smithdigits of accuracy needed in the solution. In particular, the
537*7f296bb3SBarry Smithconvergence test employed by TAO attempts to stop when the error in the
538*7f296bb3SBarry Smithconstraints is less than $\epsilon_{crtol}$ and either
539*7f296bb3SBarry Smith
540*7f296bb3SBarry Smith$$
541*7f296bb3SBarry Smith\begin{array}{lcl}
542*7f296bb3SBarry Smith||g(X)|| &\leq& \epsilon_{gatol}, \\
543*7f296bb3SBarry Smith||g(X)||/|f(X)| &\leq& \epsilon_{grtol}, \quad \text{or} \\
544*7f296bb3SBarry Smith||g(X)||/|g(X_0)| &\leq& \epsilon_{gttol},
545*7f296bb3SBarry Smith\end{array}
546*7f296bb3SBarry Smith$$
547*7f296bb3SBarry Smith
548*7f296bb3SBarry Smithwhere $X$ is the current approximation to the true solution
549*7f296bb3SBarry Smith$X^*$ and $X_0$ is the initial guess. $X^*$ is
550*7f296bb3SBarry Smithunknown, so TAO estimates $f(X) - f(X^*)$ with either the square
551*7f296bb3SBarry Smithof the norm of the gradient or the duality gap. A relative tolerance of
552*7f296bb3SBarry Smith$\epsilon_{frtol}=0.01$ indicates that two significant digits are
553*7f296bb3SBarry Smithdesired in the objective function. Each solver sets its own convergence
554*7f296bb3SBarry Smithtolerances, but they can be changed by using the routine
555*7f296bb3SBarry Smith`TaoSetTolerances()`. Another set of convergence tolerances terminates
556*7f296bb3SBarry Smiththe solver when the norm of the gradient function (or Lagrangian
557*7f296bb3SBarry Smithfunction for bound-constrained problems) is sufficiently close to zero.
558*7f296bb3SBarry Smith
559*7f296bb3SBarry SmithOther stopping criteria include a minimum trust-region radius or a
560*7f296bb3SBarry Smithmaximum number of iterations. These parameters can be set with the
561*7f296bb3SBarry Smithroutines `TaoSetTrustRegionTolerance()` and
562*7f296bb3SBarry Smith`TaoSetMaximumIterations()` Similarly, a maximum number of function
563*7f296bb3SBarry Smithevaluations can be set with the command
564*7f296bb3SBarry Smith`TaoSetMaximumFunctionEvaluations()`. `-tao_max_it`, and
565*7f296bb3SBarry Smith`-tao_max_funcs`.
566*7f296bb3SBarry Smith
567*7f296bb3SBarry Smith#### Viewing Status
568*7f296bb3SBarry Smith
569*7f296bb3SBarry SmithTo see parameters and performance statistics for the solver, the routine
570*7f296bb3SBarry Smith
571*7f296bb3SBarry Smith```
572*7f296bb3SBarry SmithTaoView(Tao tao)
573*7f296bb3SBarry Smith```
574*7f296bb3SBarry Smith
575*7f296bb3SBarry Smithcan be used. This routine will display to standard output the number of
576*7f296bb3SBarry Smithfunction evaluations need by the solver and other information specific
577*7f296bb3SBarry Smithto the solver. This same output can be produced by using the command
578*7f296bb3SBarry Smithline option `-tao_view`.
579*7f296bb3SBarry Smith
580*7f296bb3SBarry SmithThe progress of the optimization solver can be monitored with the
581*7f296bb3SBarry Smithruntime option `-tao_monitor`. Although monitoring routines can be
582*7f296bb3SBarry Smithcustomized, the default monitoring routine will print out several
583*7f296bb3SBarry Smithrelevant statistics to the screen.
584*7f296bb3SBarry Smith
585*7f296bb3SBarry SmithThe user also has access to information about the current solution. The
586*7f296bb3SBarry Smithcurrent iteration number, objective function value, gradient norm,
587*7f296bb3SBarry Smithinfeasibility norm, and step length can be retrieved with the following
588*7f296bb3SBarry Smithcommand.
589*7f296bb3SBarry Smith
590*7f296bb3SBarry Smith```
591*7f296bb3SBarry SmithTaoGetSolutionStatus(Tao tao, PetscInt* iterate, PetscReal* f,
592*7f296bb3SBarry Smith                  PetscReal* gnorm, PetscReal* cnorm, PetscReal* xdiff,
593*7f296bb3SBarry Smith                  TaoConvergedReason* reason)
594*7f296bb3SBarry Smith```
595*7f296bb3SBarry Smith
596*7f296bb3SBarry SmithThe last argument returns a code that indicates the reason that the
597*7f296bb3SBarry Smithsolver terminated. Positive numbers indicate that a solution has been
598*7f296bb3SBarry Smithfound, while negative numbers indicate a failure. A list of reasons can
599*7f296bb3SBarry Smithbe found in the manual page for `TaoGetConvergedReason()`.
600*7f296bb3SBarry Smith
601*7f296bb3SBarry Smith#### Obtaining a Solution
602*7f296bb3SBarry Smith
603*7f296bb3SBarry SmithAfter exiting the `TaoSolve()` function, the solution and the gradient can be
604*7f296bb3SBarry Smithrecovered with the following routines.
605*7f296bb3SBarry Smith
606*7f296bb3SBarry Smith```
607*7f296bb3SBarry SmithTaoGetSolution(Tao, Vec*);
608*7f296bb3SBarry SmithTaoGetGradient(Tao, Vec*, NULL, NULL);
609*7f296bb3SBarry Smith```
610*7f296bb3SBarry Smith
611*7f296bb3SBarry SmithNote that the `Vec` returned by `TaoGetSolution()` will be the
612*7f296bb3SBarry Smithsame vector passed to `TaoSetSolution()`. This information can be
613*7f296bb3SBarry Smithobtained during user-defined routines such as a function evaluation and
614*7f296bb3SBarry Smithcustomized monitoring routine or after the solver has terminated.
615*7f296bb3SBarry Smith
616*7f296bb3SBarry Smith### Special Problem structures
617*7f296bb3SBarry Smith
618*7f296bb3SBarry SmithCertain special classes of problems solved with TAO utilize specialized
619*7f296bb3SBarry Smithcode interfaces that are described below per problem type.
620*7f296bb3SBarry Smith
621*7f296bb3SBarry Smith(sec_tao_pde_constrained)=
622*7f296bb3SBarry Smith
623*7f296bb3SBarry Smith#### PDE-constrained Optimization
624*7f296bb3SBarry Smith
625*7f296bb3SBarry SmithTAO solves PDE-constrained optimization problems of the form
626*7f296bb3SBarry Smith
627*7f296bb3SBarry Smith$$
628*7f296bb3SBarry Smith\begin{array}{ll}
629*7f296bb3SBarry Smith\displaystyle \min_{u,v} & f(u,v) \\
630*7f296bb3SBarry Smith\text{subject to} & g(u,v) = 0,
631*7f296bb3SBarry Smith\end{array}
632*7f296bb3SBarry Smith$$
633*7f296bb3SBarry Smith
634*7f296bb3SBarry Smithwhere the state variable $u$ is the solution to the discretized
635*7f296bb3SBarry Smithpartial differential equation defined by $g$ and parametrized by
636*7f296bb3SBarry Smiththe design variable $v$, and $f$ is an objective function.
637*7f296bb3SBarry SmithThe Lagrange multipliers on the constraint are denoted by $y$.
638*7f296bb3SBarry SmithThis method is set by using the linearly constrained augmented
639*7f296bb3SBarry SmithLagrangian TAO solver `tao_lcl`.
640*7f296bb3SBarry Smith
641*7f296bb3SBarry SmithWe make two main assumptions when solving these problems: the objective
642*7f296bb3SBarry Smithfunction and PDE constraints have been discretized so that we can treat
643*7f296bb3SBarry Smiththe optimization problem as finite dimensional and
644*7f296bb3SBarry Smith$\nabla_u g(u,v)$ is invertible for all $u$ and $v$.
645*7f296bb3SBarry Smith
646*7f296bb3SBarry SmithUnlike other TAO solvers where the solution vector contains only the
647*7f296bb3SBarry Smithoptimization variables, PDE-constrained problems solved with `tao_lcl`
648*7f296bb3SBarry Smithcombine the design and state variables together in a monolithic solution vector
649*7f296bb3SBarry Smith$x^T = [u^T, v^T]$. Consequently, the user must provide index sets to
650*7f296bb3SBarry Smithseparate the two,
651*7f296bb3SBarry Smith
652*7f296bb3SBarry Smith```
653*7f296bb3SBarry SmithTaoSetStateDesignIS(Tao, IS, IS);
654*7f296bb3SBarry Smith```
655*7f296bb3SBarry Smith
656*7f296bb3SBarry Smithwhere the first IS is a PETSc IndexSet containing the indices of the
657*7f296bb3SBarry Smithstate variables and the second IS the design variables.
658*7f296bb3SBarry Smith
659*7f296bb3SBarry SmithPDE constraints have the general form $g(x) = 0$,
660*7f296bb3SBarry Smithwhere $c: \mathbb R^n \to \mathbb R^m$. These constraints should
661*7f296bb3SBarry Smithbe specified in a routine, written by the user, that evaluates
662*7f296bb3SBarry Smith$g(x)$. The routine that evaluates the constraint equations
663*7f296bb3SBarry Smithshould have the form
664*7f296bb3SBarry Smith
665*7f296bb3SBarry Smith```
666*7f296bb3SBarry SmithPetscErrorCode EvaluateConstraints(Tao, Vec, Vec, void*);
667*7f296bb3SBarry Smith```
668*7f296bb3SBarry Smith
669*7f296bb3SBarry SmithThe first argument of this routine is a TAO solver object. The second
670*7f296bb3SBarry Smithargument is the variable vector at which the constraint function should
671*7f296bb3SBarry Smithbe evaluated. The third argument is the vector of function values
672*7f296bb3SBarry Smith$g(x)$, and the fourth argument is a pointer to a user-defined
673*7f296bb3SBarry Smithcontext. This routine and the user-defined context should be set in the
674*7f296bb3SBarry SmithTAO solver with the
675*7f296bb3SBarry Smith
676*7f296bb3SBarry Smith```
677*7f296bb3SBarry SmithTaoSetConstraintsRoutine(Tao, Vec, PetscErrorCode (*)(Tao,Vec,Vec,void*), void*);
678*7f296bb3SBarry Smith```
679*7f296bb3SBarry Smith
680*7f296bb3SBarry Smithcommand. In this function, the first argument is the TAO solver object,
681*7f296bb3SBarry Smiththe second argument a vector in which to store the constraints, the
682*7f296bb3SBarry Smiththird argument is a function point to the routine for evaluating the
683*7f296bb3SBarry Smithconstraints, and the fourth argument is a pointer to a user-defined
684*7f296bb3SBarry Smithcontext.
685*7f296bb3SBarry Smith
686*7f296bb3SBarry SmithThe Jacobian of $g(x)$ is the matrix in
687*7f296bb3SBarry Smith$\mathbb R^{m \times n}$ such that each column contains the
688*7f296bb3SBarry Smithpartial derivatives of $g(x)$ with respect to one variable. The
689*7f296bb3SBarry Smithevaluation of the Jacobian of $g$ should be performed by calling
690*7f296bb3SBarry Smiththe
691*7f296bb3SBarry Smith
692*7f296bb3SBarry Smith```
693*7f296bb3SBarry SmithPetscErrorCode JacobianState(Tao, Vec, Mat, Mat, Mat, void*);
694*7f296bb3SBarry SmithPetscErrorCode JacobianDesign(Tao, Vec, Mat*, void*);
695*7f296bb3SBarry Smith```
696*7f296bb3SBarry Smith
697*7f296bb3SBarry Smithroutines. In these functions, The first argument is the TAO solver
698*7f296bb3SBarry Smithobject. The second argument is the variable vector at which to evaluate
699*7f296bb3SBarry Smiththe Jacobian matrix, the third argument is the Jacobian matrix, and the
700*7f296bb3SBarry Smithlast argument is a pointer to a user-defined context. The fourth and
701*7f296bb3SBarry Smithfifth arguments of the Jacobian evaluation with respect to the state
702*7f296bb3SBarry Smithvariables are for providing PETSc matrix objects for the preconditioner
703*7f296bb3SBarry Smithand for applying the inverse of the state Jacobian, respectively. This
704*7f296bb3SBarry Smithinverse matrix may be `PETSC_NULL`, in which case TAO will use a PETSc
705*7f296bb3SBarry SmithKrylov subspace solver to solve the state system. These evaluation
706*7f296bb3SBarry Smithroutines should be registered with TAO by using the
707*7f296bb3SBarry Smith
708*7f296bb3SBarry Smith```
709*7f296bb3SBarry SmithTaoSetJacobianStateRoutine(Tao, Mat, Mat, Mat,
710*7f296bb3SBarry Smith                        PetscErrorCode (*)(Tao,Vec,Mat,Mat,void*),
711*7f296bb3SBarry Smith                        void*);
712*7f296bb3SBarry SmithTaoSetJacobianDesignRoutine(Tao, Mat,
713*7f296bb3SBarry Smith                        PetscErrorCode (*)(Tao,Vec,Mat*,void*),
714*7f296bb3SBarry Smith                        void*);
715*7f296bb3SBarry Smith```
716*7f296bb3SBarry Smith
717*7f296bb3SBarry Smithroutines. The first argument is the TAO solver object, and the second
718*7f296bb3SBarry Smithargument is the matrix in which the Jacobian information can be stored.
719*7f296bb3SBarry SmithFor the state Jacobian, the third argument is the matrix that will be
720*7f296bb3SBarry Smithused for preconditioning, and the fourth argument is an optional matrix
721*7f296bb3SBarry Smithfor the inverse of the state Jacobian. One can use `PETSC_NULL` for
722*7f296bb3SBarry Smiththis inverse argument and let PETSc apply the inverse using a KSP
723*7f296bb3SBarry Smithmethod, but faster results may be obtained by manipulating the structure
724*7f296bb3SBarry Smithof the Jacobian and providing an inverse. The fifth argument is the
725*7f296bb3SBarry Smithfunction pointer, and the sixth argument is an optional user-defined
726*7f296bb3SBarry Smithcontext. Since no solve is performed with the design Jacobian, there is
727*7f296bb3SBarry Smithno need to provide preconditioner or inverse matrices.
728*7f296bb3SBarry Smith
729*7f296bb3SBarry Smith(sec_tao_evalsof)=
730*7f296bb3SBarry Smith
731*7f296bb3SBarry Smith#### Nonlinear Least Squares
732*7f296bb3SBarry Smith
733*7f296bb3SBarry SmithFor nonlinear least squares applications, we are solving the
734*7f296bb3SBarry Smithoptimization problem
735*7f296bb3SBarry Smith
736*7f296bb3SBarry Smith$$
737*7f296bb3SBarry Smith\min_{x} \;\frac{1}{2}||r(x)||_2^2.
738*7f296bb3SBarry Smith$$
739*7f296bb3SBarry Smith
740*7f296bb3SBarry SmithFor these problems, the objective function value should be computed as a
741*7f296bb3SBarry Smithvector of residuals, $r(x)$, computed with a function of the form
742*7f296bb3SBarry Smith
743*7f296bb3SBarry Smith```
744*7f296bb3SBarry SmithPetscErrorCode EvaluateResidual(Tao, Vec, Vec, void*);
745*7f296bb3SBarry Smith```
746*7f296bb3SBarry Smith
747*7f296bb3SBarry Smithand set with the
748*7f296bb3SBarry Smith
749*7f296bb3SBarry Smith```
750*7f296bb3SBarry SmithTaoSetResidualRoutine(Tao, PetscErrorCode (*)(Tao,Vec,Vec,void*), void*);
751*7f296bb3SBarry Smith```
752*7f296bb3SBarry Smith
753*7f296bb3SBarry Smithroutine. If required by the algorithm, the Jacobian of the residual,
754*7f296bb3SBarry Smith$J = \partial r(x) / \partial x$, should be computed with a
755*7f296bb3SBarry Smithfunction of the form
756*7f296bb3SBarry Smith
757*7f296bb3SBarry Smith```
758*7f296bb3SBarry SmithPetscErrorCode EvaluateJacobian(Tao, Vec, Mat, void*);
759*7f296bb3SBarry Smith```
760*7f296bb3SBarry Smith
761*7f296bb3SBarry Smithand set with the
762*7f296bb3SBarry Smith
763*7f296bb3SBarry Smith```
764*7f296bb3SBarry SmithTaoSetJacobianResidualRoutine(Tao, PetscErrorCode (*)(Tao,Vec,Mat,void*), void *);
765*7f296bb3SBarry Smith```
766*7f296bb3SBarry Smith
767*7f296bb3SBarry Smithroutine.
768*7f296bb3SBarry Smith
769*7f296bb3SBarry Smith(sec_tao_complementary)=
770*7f296bb3SBarry Smith
771*7f296bb3SBarry Smith#### Complementarity
772*7f296bb3SBarry Smith
773*7f296bb3SBarry SmithComplementarity applications have equality constraints in the form of
774*7f296bb3SBarry Smithnonlinear equations $C(X) = 0$, where
775*7f296bb3SBarry Smith$C: \mathbb R^n \to \mathbb R^m$. These constraints should be
776*7f296bb3SBarry Smithspecified in a routine written by the user with the form
777*7f296bb3SBarry Smith
778*7f296bb3SBarry Smith```
779*7f296bb3SBarry SmithPetscErrorCode EqualityConstraints(Tao, Vec, Vec, void*);
780*7f296bb3SBarry Smith```
781*7f296bb3SBarry Smith
782*7f296bb3SBarry Smiththat evaluates $C(X)$. The first argument of this routine is a TAO
783*7f296bb3SBarry SmithSolver object. The second argument is the variable vector $X$ at
784*7f296bb3SBarry Smithwhich the constraint function should be evaluated. The third argument is
785*7f296bb3SBarry Smiththe output vector of function values $C(X)$, and the fourth
786*7f296bb3SBarry Smithargument is a pointer to a user-defined context.
787*7f296bb3SBarry Smith
788*7f296bb3SBarry SmithThis routine and the user-defined context must be registered with TAO by
789*7f296bb3SBarry Smithusing the
790*7f296bb3SBarry Smith
791*7f296bb3SBarry Smith```
792*7f296bb3SBarry SmithTaoSetConstraintRoutine(Tao, Vec, PetscErrorCode (*)(Tao,Vec,Vec,void*), void*);
793*7f296bb3SBarry Smith```
794*7f296bb3SBarry Smith
795*7f296bb3SBarry Smithcommand. In this command, the first argument is TAO Solver object, the
796*7f296bb3SBarry Smithsecond argument is vector in which to store the function values, the
797*7f296bb3SBarry Smiththird argument is the user-defined routine that evaluates $C(X)$,
798*7f296bb3SBarry Smithand the fourth argument is a pointer to a user-defined context that will
799*7f296bb3SBarry Smithbe passed back to the user.
800*7f296bb3SBarry Smith
801*7f296bb3SBarry SmithThe Jacobian of the function is the matrix in
802*7f296bb3SBarry Smith$\mathbb R^{m \times n}$ such that each column contains the
803*7f296bb3SBarry Smithpartial derivatives of $f$ with respect to one variable. The
804*7f296bb3SBarry Smithevaluation of the Jacobian of $C$ should be performed in a routine
805*7f296bb3SBarry Smithof the form
806*7f296bb3SBarry Smith
807*7f296bb3SBarry Smith```
808*7f296bb3SBarry SmithPetscErrorCode EvaluateJacobian(Tao, Vec, Mat, Mat, void*);
809*7f296bb3SBarry Smith```
810*7f296bb3SBarry Smith
811*7f296bb3SBarry SmithIn this function, the first argument is the TAO Solver object and the
812*7f296bb3SBarry Smithsecond argument is the variable vector at which to evaluate the Jacobian
813*7f296bb3SBarry Smithmatrix. The third argument is the Jacobian matrix, and the sixth
814*7f296bb3SBarry Smithargument is a pointer to a user-defined context. Since the Jacobian
815*7f296bb3SBarry Smithmatrix may be used in solving a system of linear equations, a
816*7f296bb3SBarry Smithpreconditioner for the matrix may be needed. The fourth argument is the
817*7f296bb3SBarry Smithmatrix that will be used for preconditioning the linear system; in most
818*7f296bb3SBarry Smithcases, this matrix will be the same as the Hessian matrix. The fifth
819*7f296bb3SBarry Smithargument is the flag used to set the Jacobian matrix and linear solver
820*7f296bb3SBarry Smithin the routine `KSPSetOperators()`.
821*7f296bb3SBarry Smith
822*7f296bb3SBarry SmithThis routine should be specified to TAO by using the
823*7f296bb3SBarry Smith
824*7f296bb3SBarry Smith```
825*7f296bb3SBarry SmithTaoSetJacobianRoutine(Tao, Mat, Mat, PetscErrorCode (*)(Tao,Vec,Mat,Mat,void*), void*);
826*7f296bb3SBarry Smith```
827*7f296bb3SBarry Smith
828*7f296bb3SBarry Smithcommand. The first argument is the TAO Solver object; the second and
829*7f296bb3SBarry Smiththird arguments are the Mat objects in which the Jacobian will be stored
830*7f296bb3SBarry Smithand the Mat object that will be used for the preconditioning (they may
831*7f296bb3SBarry Smithbe the same), respectively. The fourth argument is the function pointer;
832*7f296bb3SBarry Smithand the fifth argument is an optional user-defined context. The Jacobian
833*7f296bb3SBarry Smithmatrix should be created in a way such that the product of it and the
834*7f296bb3SBarry Smithvariable vector can be stored in the constraint vector.
835*7f296bb3SBarry Smith
836*7f296bb3SBarry Smith(sec_tao_solvers)=
837*7f296bb3SBarry Smith
838*7f296bb3SBarry Smith## TAO Algorithms
839*7f296bb3SBarry Smith
840*7f296bb3SBarry SmithTAO includes a variety of optimization algorithms for several classes of
841*7f296bb3SBarry Smithproblems (unconstrained, bound-constrained, and PDE-constrained
842*7f296bb3SBarry Smithminimization, nonlinear least-squares, and complementarity). The TAO
843*7f296bb3SBarry Smithalgorithms for solving these problems are detailed in this section, a
844*7f296bb3SBarry Smithparticular algorithm can chosen by using the `TaoSetType()` function
845*7f296bb3SBarry Smithor using the command line arguments `-tao_type <name>`. For those
846*7f296bb3SBarry Smithinterested in extending these algorithms or using new ones, please see
847*7f296bb3SBarry Smith{any}`sec_tao_addsolver` for more information.
848*7f296bb3SBarry Smith
849*7f296bb3SBarry Smith(sec_tao_unconstrained)=
850*7f296bb3SBarry Smith
851*7f296bb3SBarry Smith### Unconstrained Minimization
852*7f296bb3SBarry Smith
853*7f296bb3SBarry SmithUnconstrained minimization is used to minimize a function of many
854*7f296bb3SBarry Smithvariables without any constraints on the variables, such as bounds. The
855*7f296bb3SBarry Smithmethods available in TAO for solving these problems can be classified
856*7f296bb3SBarry Smithaccording to the amount of derivative information required:
857*7f296bb3SBarry Smith
858*7f296bb3SBarry Smith1. Function evaluation only – Nelder-Mead method (`tao_nm`)
859*7f296bb3SBarry Smith2. Function and gradient evaluations – limited-memory, variable-metric
860*7f296bb3SBarry Smith   method (`tao_lmvm`) and nonlinear conjugate gradient method
861*7f296bb3SBarry Smith   (`tao_cg`)
862*7f296bb3SBarry Smith3. Function, gradient, and Hessian evaluations – Newton Krylov methods:
863*7f296bb3SBarry Smith   Newton line search (`tao_nls`), Newton trust-region (`tao_ntr`),
864*7f296bb3SBarry Smith   and Newton trust-region line-search (`tao_ntl`)
865*7f296bb3SBarry Smith
866*7f296bb3SBarry SmithThe best method to use depends on the particular problem being solved
867*7f296bb3SBarry Smithand the accuracy required in the solution. If a Hessian evaluation
868*7f296bb3SBarry Smithroutine is available, then the Newton line search and Newton
869*7f296bb3SBarry Smithtrust-region methods will likely perform best. When a Hessian evaluation
870*7f296bb3SBarry Smithroutine is not available, then the limited-memory, variable-metric
871*7f296bb3SBarry Smithmethod is likely to perform best. The Nelder-Mead method should be used
872*7f296bb3SBarry Smithonly as a last resort when no gradient information is available.
873*7f296bb3SBarry Smith
874*7f296bb3SBarry SmithEach solver has a set of options associated with it that can be set with
875*7f296bb3SBarry Smithcommand line arguments. These algorithms and the associated options are
876*7f296bb3SBarry Smithbriefly discussed in this section.
877*7f296bb3SBarry Smith
878*7f296bb3SBarry Smith#### Newton-Krylov Methods
879*7f296bb3SBarry Smith
880*7f296bb3SBarry SmithTAO features three Newton-Krylov algorithms, separated by their globalization methods
881*7f296bb3SBarry Smithfor unconstrained optimization: line search (NLS), trust region (NTR), and trust
882*7f296bb3SBarry Smithregion with a line search (NTL). They are available via the TAO solvers
883*7f296bb3SBarry Smith`TAONLS`, `TAONTR` and `TAONTL`, respectively, or the `-tao_type`
884*7f296bb3SBarry Smith`nls`/`ntr`/`ntl` flag.
885*7f296bb3SBarry Smith
886*7f296bb3SBarry Smith##### Newton Line Search Method (NLS)
887*7f296bb3SBarry Smith
888*7f296bb3SBarry SmithThe Newton line search method solves the symmetric system of equations
889*7f296bb3SBarry Smith
890*7f296bb3SBarry Smith$$
891*7f296bb3SBarry SmithH_k d_k = -g_k
892*7f296bb3SBarry Smith$$
893*7f296bb3SBarry Smith
894*7f296bb3SBarry Smithto obtain a step $d_k$, where $H_k$ is the Hessian of the
895*7f296bb3SBarry Smithobjective function at $x_k$ and $g_k$ is the gradient of the
896*7f296bb3SBarry Smithobjective function at $x_k$. For problems where the Hessian matrix
897*7f296bb3SBarry Smithis indefinite, the perturbed system of equations
898*7f296bb3SBarry Smith
899*7f296bb3SBarry Smith$$
900*7f296bb3SBarry Smith(H_k + \rho_k I) d_k = -g_k
901*7f296bb3SBarry Smith$$
902*7f296bb3SBarry Smith
903*7f296bb3SBarry Smithis solved to obtain the direction, where $\rho_k$ is a positive
904*7f296bb3SBarry Smithconstant. If the direction computed is not a descent direction, the
905*7f296bb3SBarry Smith(scaled) steepest descent direction is used instead. Having obtained the
906*7f296bb3SBarry Smithdirection, a Moré-Thuente line search is applied to obtain a step
907*7f296bb3SBarry Smithlength, $\tau_k$, that approximately solves the one-dimensional
908*7f296bb3SBarry Smithoptimization problem
909*7f296bb3SBarry Smith
910*7f296bb3SBarry Smith$$
911*7f296bb3SBarry Smith\min_\tau f(x_k + \tau d_k).
912*7f296bb3SBarry Smith$$
913*7f296bb3SBarry Smith
914*7f296bb3SBarry SmithThe Newton line search method can be selected by using the TAO solver
915*7f296bb3SBarry Smith`tao_nls`. The options available for this solver are listed in
916*7f296bb3SBarry Smith{numref}`table_nlsoptions`. For the best efficiency, function and
917*7f296bb3SBarry Smithgradient evaluations should be performed simultaneously when using this
918*7f296bb3SBarry Smithalgorithm.
919*7f296bb3SBarry Smith
920*7f296bb3SBarry Smith> ```{eval-rst}
921*7f296bb3SBarry Smith> .. table:: Summary of ``nls`` options
922*7f296bb3SBarry Smith>    :name: table_nlsoptions
923*7f296bb3SBarry Smith>
924*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
925*7f296bb3SBarry Smith>    | Name  ``-tao_nls_``      | Value          | Default            | Description        |
926*7f296bb3SBarry Smith>    +==========================+================+====================+====================+
927*7f296bb3SBarry Smith>    |          ``ksp_type``    | cg, nash,      | stcg               | KSPType for        |
928*7f296bb3SBarry Smith>    |                          |                |                    | linear system      |
929*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
930*7f296bb3SBarry Smith>    |          ``pc_type``     | none, jacobi   | lmvm               | PCType for linear  |
931*7f296bb3SBarry Smith>    |                          |                |                    | system             |
932*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
933*7f296bb3SBarry Smith>    |          ``sval``        | real           | :math:`0`          | Initial            |
934*7f296bb3SBarry Smith>    |                          |                |                    | perturbation       |
935*7f296bb3SBarry Smith>    |                          |                |                    | value              |
936*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
937*7f296bb3SBarry Smith>    |          ``imin``        | real           | :math:`10^{-4}`    | Minimum            |
938*7f296bb3SBarry Smith>    |                          |                |                    | initial            |
939*7f296bb3SBarry Smith>    |                          |                |                    | perturbation       |
940*7f296bb3SBarry Smith>    |                          |                |                    | value              |
941*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
942*7f296bb3SBarry Smith>    |          ``imax``        | real           | :math:`100`        | Maximum            |
943*7f296bb3SBarry Smith>    |                          |                |                    | initial            |
944*7f296bb3SBarry Smith>    |                          |                |                    | perturbation       |
945*7f296bb3SBarry Smith>    |                          |                |                    | value              |
946*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
947*7f296bb3SBarry Smith>    |          ``imfac``       | real           | :math:`0.1`        | Gradient norm      |
948*7f296bb3SBarry Smith>    |                          |                |                    | factor when        |
949*7f296bb3SBarry Smith>    |                          |                |                    | initializing       |
950*7f296bb3SBarry Smith>    |                          |                |                    | perturbation       |
951*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
952*7f296bb3SBarry Smith>    |          ``pmax``        | real           | :math:`100`        | Maximum            |
953*7f296bb3SBarry Smith>    |                          |                |                    | perturbation       |
954*7f296bb3SBarry Smith>    |                          |                |                    | when               |
955*7f296bb3SBarry Smith>    |                          |                |                    | increasing         |
956*7f296bb3SBarry Smith>    |                          |                |                    | value              |
957*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
958*7f296bb3SBarry Smith>    |          ``pgfac``       | real           | :math:`10`         | Perturbation growth|
959*7f296bb3SBarry Smith>    |                          |                |                    | when               |
960*7f296bb3SBarry Smith>    |                          |                |                    | increasing         |
961*7f296bb3SBarry Smith>    |                          |                |                    | value              |
962*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
963*7f296bb3SBarry Smith>    |          ``pmgfac``      | real           | :math:`0.1`        | Gradient norm      |
964*7f296bb3SBarry Smith>    |                          |                |                    | factor when        |
965*7f296bb3SBarry Smith>    |                          |                |                    | increasing         |
966*7f296bb3SBarry Smith>    |                          |                |                    | perturbation       |
967*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
968*7f296bb3SBarry Smith>    |          ``pmin``        | real           | :math:`10^{-12}`   | Minimum non-zero   |
969*7f296bb3SBarry Smith>    |                          |                |                    | perturbation       |
970*7f296bb3SBarry Smith>    |                          |                |                    | when               |
971*7f296bb3SBarry Smith>    |                          |                |                    | decreasing         |
972*7f296bb3SBarry Smith>    |                          |                |                    | value              |
973*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
974*7f296bb3SBarry Smith>    |          ``psfac``       | real           | :math:`0.4`        | Perturbation shrink|
975*7f296bb3SBarry Smith>    |                          |                |                    | factor when        |
976*7f296bb3SBarry Smith>    |                          |                |                    | decreasing         |
977*7f296bb3SBarry Smith>    |                          |                |                    | value              |
978*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
979*7f296bb3SBarry Smith>    |          ``pmsfac``      | real           | :math:`0.1`        | Gradient norm      |
980*7f296bb3SBarry Smith>    |                          |                |                    | factor when        |
981*7f296bb3SBarry Smith>    |                          |                |                    | decreasing         |
982*7f296bb3SBarry Smith>    |                          |                |                    | perturbation       |
983*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
984*7f296bb3SBarry Smith>    |          ``nu1``         | real           | 0.25               | :math:`\nu_1`      |
985*7f296bb3SBarry Smith>    |                          |                |                    | in ``step``        |
986*7f296bb3SBarry Smith>    |                          |                |                    | update             |
987*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
988*7f296bb3SBarry Smith>    |          ``nu2``         | real           | 0.50               | :math:`\nu_2`      |
989*7f296bb3SBarry Smith>    |                          |                |                    | in ``step``        |
990*7f296bb3SBarry Smith>    |                          |                |                    | update             |
991*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
992*7f296bb3SBarry Smith>    |          ``nu3``         | real           | 1.00               | :math:`\nu_3`      |
993*7f296bb3SBarry Smith>    |                          |                |                    | in ``step``        |
994*7f296bb3SBarry Smith>    |                          |                |                    | update             |
995*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
996*7f296bb3SBarry Smith>    |          ``nu4``         | real           | 1.25               | :math:`\nu_4`      |
997*7f296bb3SBarry Smith>    |                          |                |                    | in ``step``        |
998*7f296bb3SBarry Smith>    |                          |                |                    | update             |
999*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1000*7f296bb3SBarry Smith>    |          ``omega1``      | real           | 0.25               | :math:`\omega_1`   |
1001*7f296bb3SBarry Smith>    |                          |                |                    | in ``step``        |
1002*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1003*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1004*7f296bb3SBarry Smith>    |          ``omega2``      | real           | 0.50               | :math:`\omega_2`   |
1005*7f296bb3SBarry Smith>    |                          |                |                    | in ``step``        |
1006*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1007*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1008*7f296bb3SBarry Smith>    |          ``omega3``      | real           | 1.00               | :math:`\omega_3`   |
1009*7f296bb3SBarry Smith>    |                          |                |                    | in ``step``        |
1010*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1011*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1012*7f296bb3SBarry Smith>    |          ``omega4``      | real           | 2.00               | :math:`\omega_4`   |
1013*7f296bb3SBarry Smith>    |                          |                |                    | in ``step``        |
1014*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1015*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1016*7f296bb3SBarry Smith>    |          ``omega5``      | real           | 4.00               | :math:`\omega_5`   |
1017*7f296bb3SBarry Smith>    |                          |                |                    | in ``step``        |
1018*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1019*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1020*7f296bb3SBarry Smith>    |          ``eta1``        | real           | :math:`10^{-4}`    | :math:`\eta_1`     |
1021*7f296bb3SBarry Smith>    |                          |                |                    | in                 |
1022*7f296bb3SBarry Smith>    |                          |                |                    | ``reduction``      |
1023*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1024*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1025*7f296bb3SBarry Smith>    |          ``eta2``        | real           | 0.25               | :math:`\eta_2`     |
1026*7f296bb3SBarry Smith>    |                          |                |                    | in                 |
1027*7f296bb3SBarry Smith>    |                          |                |                    | ``reduction``      |
1028*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1029*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1030*7f296bb3SBarry Smith>    |          ``eta3``        | real           | 0.50               | :math:`\eta_3`     |
1031*7f296bb3SBarry Smith>    |                          |                |                    | in                 |
1032*7f296bb3SBarry Smith>    |                          |                |                    | ``reduction``      |
1033*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1034*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1035*7f296bb3SBarry Smith>    |          ``eta4``        | real           | 0.90               | :math:`\eta_4`     |
1036*7f296bb3SBarry Smith>    |                          |                |                    | in                 |
1037*7f296bb3SBarry Smith>    |                          |                |                    | ``reduction``      |
1038*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1039*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1040*7f296bb3SBarry Smith>    |          ``alpha1``      | real           | 0.25               | :math:`\alpha_1`   |
1041*7f296bb3SBarry Smith>    |                          |                |                    | in                 |
1042*7f296bb3SBarry Smith>    |                          |                |                    | ``reduction``      |
1043*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1044*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1045*7f296bb3SBarry Smith>    |          ``alpha2``      | real           | 0.50               | :math:`\alpha_2`   |
1046*7f296bb3SBarry Smith>    |                          |                |                    | in                 |
1047*7f296bb3SBarry Smith>    |                          |                |                    | ``reduction``      |
1048*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1049*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1050*7f296bb3SBarry Smith>    |          ``alpha3``      | real           | 1.00               | :math:`\alpha_3`   |
1051*7f296bb3SBarry Smith>    |                          |                |                    | in                 |
1052*7f296bb3SBarry Smith>    |                          |                |                    | ``reduction``      |
1053*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1054*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1055*7f296bb3SBarry Smith>    |          ``alpha4``      | real           | 2.00               | :math:`\alpha_4`   |
1056*7f296bb3SBarry Smith>    |                          |                |                    | in                 |
1057*7f296bb3SBarry Smith>    |                          |                |                    | ``reduction``      |
1058*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1059*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1060*7f296bb3SBarry Smith>    |          ``alpha5``      | real           | 4.00               | :math:`\alpha_5`   |
1061*7f296bb3SBarry Smith>    |                          |                |                    | in                 |
1062*7f296bb3SBarry Smith>    |                          |                |                    | ``reduction``      |
1063*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1064*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1065*7f296bb3SBarry Smith>    |          ``mu1``         | real           | 0.10               | :math:`\mu_1`      |
1066*7f296bb3SBarry Smith>    |                          |                |                    | in                 |
1067*7f296bb3SBarry Smith>    |                          |                |                    | ``interpolation``  |
1068*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1069*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1070*7f296bb3SBarry Smith>    |          ``mu2``         | real           | 0.50               | :math:`\mu_2`      |
1071*7f296bb3SBarry Smith>    |                          |                |                    | in                 |
1072*7f296bb3SBarry Smith>    |                          |                |                    | ``interpolation``  |
1073*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1074*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1075*7f296bb3SBarry Smith>    |          ``gamma1``      | real           | 0.25               | :math:`\gamma_1`   |
1076*7f296bb3SBarry Smith>    |                          |                |                    | in                 |
1077*7f296bb3SBarry Smith>    |                          |                |                    | ``interpolation``  |
1078*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1079*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1080*7f296bb3SBarry Smith>    |          ``gamma2``      | real           | 0.50               | :math:`\gamma_2`   |
1081*7f296bb3SBarry Smith>    |                          |                |                    | in                 |
1082*7f296bb3SBarry Smith>    |                          |                |                    | ``interpolation``  |
1083*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1084*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1085*7f296bb3SBarry Smith>    |          ``gamma3``      | real           | 2.00               | :math:`\gamma_3`   |
1086*7f296bb3SBarry Smith>    |                          |                |                    | in                 |
1087*7f296bb3SBarry Smith>    |                          |                |                    | ``interpolation``  |
1088*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1089*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1090*7f296bb3SBarry Smith>    |          ``gamma4``      | real           | 4.00               | :math:`\gamma_4`   |
1091*7f296bb3SBarry Smith>    |                          |                |                    | in                 |
1092*7f296bb3SBarry Smith>    |                          |                |                    | ``interpolation``  |
1093*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1094*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1095*7f296bb3SBarry Smith>    |          ``theta``       | real           | 0.05               | :math:`\theta`     |
1096*7f296bb3SBarry Smith>    |                          |                |                    | in                 |
1097*7f296bb3SBarry Smith>    |                          |                |                    | ``interpolation``  |
1098*7f296bb3SBarry Smith>    |                          |                |                    | update             |
1099*7f296bb3SBarry Smith>    +--------------------------+----------------+--------------------+--------------------+
1100*7f296bb3SBarry Smith> ```
1101*7f296bb3SBarry Smith
1102*7f296bb3SBarry SmithThe system of equations is approximately solved by applying the
1103*7f296bb3SBarry Smithconjugate gradient method, Nash conjugate gradient method,
1104*7f296bb3SBarry SmithSteihaug-Toint conjugate gradient method, generalized Lanczos method, or
1105*7f296bb3SBarry Smithan alternative Krylov subspace method supplied by PETSc. The method used
1106*7f296bb3SBarry Smithto solve the systems of equations is specified with the command line
1107*7f296bb3SBarry Smithargument `-tao_nls_ksp_type <cg,nash,stcg,gltr,gmres,...>`; `stcg`
1108*7f296bb3SBarry Smithis the default. See the PETSc manual for further information on changing
1109*7f296bb3SBarry Smiththe behavior of the linear system solvers.
1110*7f296bb3SBarry Smith
1111*7f296bb3SBarry SmithA good preconditioner reduces the number of iterations required to solve
1112*7f296bb3SBarry Smiththe linear system of equations. For the conjugate gradient methods and
1113*7f296bb3SBarry Smithgeneralized Lanczos method, this preconditioner must be symmetric and
1114*7f296bb3SBarry Smithpositive definite. The available options are to use no preconditioner,
1115*7f296bb3SBarry Smiththe absolute value of the diagonal of the Hessian matrix, a
1116*7f296bb3SBarry Smithlimited-memory BFGS approximation to the Hessian matrix, or one of the
1117*7f296bb3SBarry Smithother preconditioners provided by the PETSc package. These
1118*7f296bb3SBarry Smithpreconditioners are specified by the command line arguments
1119*7f296bb3SBarry Smith`-tao_nls_pc_type <none,jacobi,icc,ilu,lmvm>`, respectively. The
1120*7f296bb3SBarry Smithdefault is the `lmvm` preconditioner, which uses a BFGS approximation
1121*7f296bb3SBarry Smithof the inverse Hessian. See the PETSc manual for further information on
1122*7f296bb3SBarry Smithchanging the behavior of the preconditioners.
1123*7f296bb3SBarry Smith
1124*7f296bb3SBarry SmithThe perturbation $\rho_k$ is added when the direction returned by
1125*7f296bb3SBarry Smiththe Krylov subspace method is not a descent direction, the Krylov method
1126*7f296bb3SBarry Smithdiverged due to an indefinite preconditioner or matrix, or a direction
1127*7f296bb3SBarry Smithof negative curvature was found. In the last two cases, if the step
1128*7f296bb3SBarry Smithreturned is a descent direction, it is used during the line search.
1129*7f296bb3SBarry SmithOtherwise, a steepest descent direction is used during the line search.
1130*7f296bb3SBarry SmithThe perturbation is decreased as long as the Krylov subspace method
1131*7f296bb3SBarry Smithreports success and increased if further problems are encountered. There
1132*7f296bb3SBarry Smithare three cases: initializing, increasing, and decreasing the
1133*7f296bb3SBarry Smithperturbation. These cases are described below.
1134*7f296bb3SBarry Smith
1135*7f296bb3SBarry Smith1. If $\rho_k$ is zero and a problem was detected with either the
1136*7f296bb3SBarry Smith   direction or the Krylov subspace method, the perturbation is
1137*7f296bb3SBarry Smith   initialized to
1138*7f296bb3SBarry Smith
1139*7f296bb3SBarry Smith   $$
1140*7f296bb3SBarry Smith   \rho_{k+1} = \text{median}\left\{\text{imin}, \text{imfac} * \|g(x_k)\|, \text{imax}\right\},
1141*7f296bb3SBarry Smith   $$
1142*7f296bb3SBarry Smith
1143*7f296bb3SBarry Smith   where $g(x_k)$ is the gradient of the objective function and
1144*7f296bb3SBarry Smith   `imin` is set with the command line argument
1145*7f296bb3SBarry Smith   `-tao_nls_imin <real>` with a default value of $10^{-4}$,
1146*7f296bb3SBarry Smith   `imfac` by `-tao_nls_imfac` with a default value of 0.1, and
1147*7f296bb3SBarry Smith   `imax` by `-tao_nls_imax` with a default value of 100. When using
1148*7f296bb3SBarry Smith   the `gltr` method to solve the system of equations, an estimate of
1149*7f296bb3SBarry Smith   the minimum eigenvalue $\lambda_1$ of the Hessian matrix is
1150*7f296bb3SBarry Smith   available. This value is used to initialize the perturbation to
1151*7f296bb3SBarry Smith   $\rho_{k+1} = \max\left\{\rho_{k+1}, -\lambda_1\right\}$ in
1152*7f296bb3SBarry Smith   this case.
1153*7f296bb3SBarry Smith
1154*7f296bb3SBarry Smith2. If $\rho_k$ is nonzero and a problem was detected with either
1155*7f296bb3SBarry Smith   the direction or Krylov subspace method, the perturbation is
1156*7f296bb3SBarry Smith   increased to
1157*7f296bb3SBarry Smith
1158*7f296bb3SBarry Smith   $$
1159*7f296bb3SBarry Smith   \rho_{k+1} = \min\left\{\text{pmax}, \max\left\{\text{pgfac} * \rho_k, \text{pmgfac} * \|g(x_k)\|\right\}\right\},
1160*7f296bb3SBarry Smith   $$
1161*7f296bb3SBarry Smith
1162*7f296bb3SBarry Smith   where $g(x_k)$ is the gradient of the objective function and
1163*7f296bb3SBarry Smith   `pgfac` is set with the command line argument `-tao_nls_pgfac`
1164*7f296bb3SBarry Smith   with a default value of 10, `pmgfac` by `-tao_nls_pmgfac` with a
1165*7f296bb3SBarry Smith   default value of 0.1, and `pmax` by `-tao_nls_pmax` with a
1166*7f296bb3SBarry Smith   default value of 100.
1167*7f296bb3SBarry Smith
1168*7f296bb3SBarry Smith3. If $\rho_k$ is nonzero and no problems were detected with
1169*7f296bb3SBarry Smith   either the direction or Krylov subspace method, the perturbation is
1170*7f296bb3SBarry Smith   decreased to
1171*7f296bb3SBarry Smith
1172*7f296bb3SBarry Smith   $$
1173*7f296bb3SBarry Smith   \rho_{k+1} = \min\left\{\text{psfac} * \rho_k, \text{pmsfac} * \|g(x_k)\|\right\},
1174*7f296bb3SBarry Smith   $$
1175*7f296bb3SBarry Smith
1176*7f296bb3SBarry Smith   where $g(x_k)$ is the gradient of the objective function,
1177*7f296bb3SBarry Smith   `psfac` is set with the command line argument `-tao_nls_psfac`
1178*7f296bb3SBarry Smith   with a default value of 0.4, and `pmsfac` is set by
1179*7f296bb3SBarry Smith   `-tao_nls_pmsfac` with a default value of 0.1. Moreover, if
1180*7f296bb3SBarry Smith   $\rho_{k+1} < \text{pmin}$, then $\rho_{k+1} = 0$, where
1181*7f296bb3SBarry Smith   `pmin` is set with the command line argument `-tao_nls_pmin` and
1182*7f296bb3SBarry Smith   has a default value of $10^{-12}$.
1183*7f296bb3SBarry Smith
1184*7f296bb3SBarry SmithNear a local minimizer to the unconstrained optimization problem, the
1185*7f296bb3SBarry SmithHessian matrix will be positive-semidefinite; the perturbation will
1186*7f296bb3SBarry Smithshrink toward zero, and one would eventually observe a superlinear
1187*7f296bb3SBarry Smithconvergence rate.
1188*7f296bb3SBarry Smith
1189*7f296bb3SBarry SmithWhen using `nash`, `stcg`, or `gltr` to solve the linear systems
1190*7f296bb3SBarry Smithof equation, a trust-region radius needs to be initialized and updated.
1191*7f296bb3SBarry SmithThis trust-region radius simultaneously limits the size of the step
1192*7f296bb3SBarry Smithcomputed and reduces the number of iterations of the conjugate gradient
1193*7f296bb3SBarry Smithmethod. The method for initializing the trust-region radius is set with
1194*7f296bb3SBarry Smiththe command line argument
1195*7f296bb3SBarry Smith`-tao_nls_init_type <constant,direction,interpolation>`;
1196*7f296bb3SBarry Smith`interpolation`, which chooses an initial value based on the
1197*7f296bb3SBarry Smithinterpolation scheme found in {cite}`cgt`, is the default.
1198*7f296bb3SBarry SmithThis scheme performs a number of function and gradient evaluations to
1199*7f296bb3SBarry Smithdetermine a radius such that the reduction predicted by the quadratic
1200*7f296bb3SBarry Smithmodel along the gradient direction coincides with the actual reduction
1201*7f296bb3SBarry Smithin the nonlinear function. The iterate obtaining the best objective
1202*7f296bb3SBarry Smithfunction value is used as the starting point for the main line search
1203*7f296bb3SBarry Smithalgorithm. The `constant` method initializes the trust-region radius
1204*7f296bb3SBarry Smithby using the value specified with the `-tao_trust0 <real>` command
1205*7f296bb3SBarry Smithline argument, where the default value is 100. The `direction`
1206*7f296bb3SBarry Smithtechnique solves the first quadratic optimization problem by using a
1207*7f296bb3SBarry Smithstandard conjugate gradient method and initializes the trust region to
1208*7f296bb3SBarry Smith$\|s_0\|$.
1209*7f296bb3SBarry Smith
1210*7f296bb3SBarry SmithThe method for updating the trust-region radius is set with the command
1211*7f296bb3SBarry Smithline argument `-tao_nls_update_type <step,reduction,interpolation>`;
1212*7f296bb3SBarry Smith`step` is the default. The `step` method updates the trust-region
1213*7f296bb3SBarry Smithradius based on the value of $\tau_k$. In particular,
1214*7f296bb3SBarry Smith
1215*7f296bb3SBarry Smith$$
1216*7f296bb3SBarry Smith\Delta_{k+1} = \left\{\begin{array}{ll}
1217*7f296bb3SBarry Smith\omega_1 \text{min}(\Delta_k, \|d_k\|) & \text{if } \tau_k \in [0, \nu_1) \\
1218*7f296bb3SBarry Smith\omega_2 \text{min}(\Delta_k, \|d_k\|) & \text{if } \tau_k \in [\nu_1, \nu_2) \\
1219*7f296bb3SBarry Smith\omega_3 \Delta_k & \text{if } \tau_k \in [\nu_2, \nu_3) \\
1220*7f296bb3SBarry Smith\text{max}(\Delta_k, \omega_4 \|d_k\|) & \text{if } \tau_k \in [\nu_3, \nu_4) \\
1221*7f296bb3SBarry Smith\text{max}(\Delta_k, \omega_5 \|d_k\|) & \text{if } \tau_k \in [\nu_4, \infty),
1222*7f296bb3SBarry Smith\end{array}
1223*7f296bb3SBarry Smith\right.
1224*7f296bb3SBarry Smith$$
1225*7f296bb3SBarry Smith
1226*7f296bb3SBarry Smithwhere
1227*7f296bb3SBarry Smith$0 < \omega_1 < \omega_2 < \omega_3 = 1 < \omega_4 < \omega_5$ and
1228*7f296bb3SBarry Smith$0 < \nu_1 < \nu_2 < \nu_3 < \nu_4$ are constants. The
1229*7f296bb3SBarry Smith`reduction` method computes the ratio of the actual reduction in the
1230*7f296bb3SBarry Smithobjective function to the reduction predicted by the quadratic model for
1231*7f296bb3SBarry Smiththe full step,
1232*7f296bb3SBarry Smith$\kappa_k = \frac{f(x_k) - f(x_k + d_k)}{q(x_k) - q(x_k + d_k)}$,
1233*7f296bb3SBarry Smithwhere $q_k$ is the quadratic model. The radius is then updated as
1234*7f296bb3SBarry Smith
1235*7f296bb3SBarry Smith$$
1236*7f296bb3SBarry Smith\Delta_{k+1} = \left\{\begin{array}{ll}
1237*7f296bb3SBarry Smith\alpha_1 \text{min}(\Delta_k, \|d_k\|) & \text{if } \kappa_k \in (-\infty, \eta_1) \\
1238*7f296bb3SBarry Smith\alpha_2 \text{min}(\Delta_k, \|d_k\|) & \text{if } \kappa_k \in [\eta_1, \eta_2) \\
1239*7f296bb3SBarry Smith\alpha_3 \Delta_k & \text{if } \kappa_k \in [\eta_2, \eta_3) \\
1240*7f296bb3SBarry Smith\text{max}(\Delta_k, \alpha_4 \|d_k\|) & \text{if } \kappa_k \in [\eta_3, \eta_4) \\
1241*7f296bb3SBarry Smith\text{max}(\Delta_k, \alpha_5 \|d_k\|) & \text{if } \kappa_k \in [\eta_4, \infty),
1242*7f296bb3SBarry Smith\end{array}
1243*7f296bb3SBarry Smith\right.
1244*7f296bb3SBarry Smith$$
1245*7f296bb3SBarry Smith
1246*7f296bb3SBarry Smithwhere
1247*7f296bb3SBarry Smith$0 < \alpha_1 < \alpha_2 < \alpha_3 = 1 < \alpha_4 < \alpha_5$ and
1248*7f296bb3SBarry Smith$0 < \eta_1 < \eta_2 < \eta_3 < \eta_4$ are constants. The
1249*7f296bb3SBarry Smith`interpolation` method uses the same interpolation mechanism as in the
1250*7f296bb3SBarry Smithinitialization to compute a new value for the trust-region radius.
1251*7f296bb3SBarry Smith
1252*7f296bb3SBarry SmithThis algorithm will be deprecated in the next version and replaced by
1253*7f296bb3SBarry Smiththe Bounded Newton Line Search (BNLS) algorithm that can solve both
1254*7f296bb3SBarry Smithbound constrained and unconstrained problems.
1255*7f296bb3SBarry Smith
1256*7f296bb3SBarry Smith##### Newton Trust-Region Method (NTR)
1257*7f296bb3SBarry Smith
1258*7f296bb3SBarry SmithThe Newton trust-region method solves the constrained quadratic
1259*7f296bb3SBarry Smithprogramming problem
1260*7f296bb3SBarry Smith
1261*7f296bb3SBarry Smith$$
1262*7f296bb3SBarry Smith\begin{array}{ll}
1263*7f296bb3SBarry Smith\min_d  & \frac{1}{2}d^T H_k d  + g_k^T d \\
1264*7f296bb3SBarry Smith\text{subject to} & \|d\| \leq \Delta_k
1265*7f296bb3SBarry Smith\end{array}
1266*7f296bb3SBarry Smith$$
1267*7f296bb3SBarry Smith
1268*7f296bb3SBarry Smithto obtain a direction $d_k$, where $H_k$ is the Hessian of
1269*7f296bb3SBarry Smiththe objective function at $x_k$, $g_k$ is the gradient of
1270*7f296bb3SBarry Smiththe objective function at $x_k$, and $\Delta_k$ is the
1271*7f296bb3SBarry Smithtrust-region radius. If $x_k + d_k$ sufficiently reduces the
1272*7f296bb3SBarry Smithnonlinear objective function, then the step is accepted, and the
1273*7f296bb3SBarry Smithtrust-region radius is updated. However, if $x_k + d_k$ does not
1274*7f296bb3SBarry Smithsufficiently reduce the nonlinear objective function, then the step is
1275*7f296bb3SBarry Smithrejected, the trust-region radius is reduced, and the quadratic program
1276*7f296bb3SBarry Smithis re-solved by using the updated trust-region radius. The Newton
1277*7f296bb3SBarry Smithtrust-region method can be set by using the TAO solver `tao_ntr`. The
1278*7f296bb3SBarry Smithoptions available for this solver are listed in
1279*7f296bb3SBarry Smith{numref}`table_ntroptions`. For the best efficiency, function and
1280*7f296bb3SBarry Smithgradient evaluations should be performed separately when using this
1281*7f296bb3SBarry Smithalgorithm.
1282*7f296bb3SBarry Smith
1283*7f296bb3SBarry Smith> ```{eval-rst}
1284*7f296bb3SBarry Smith> .. table:: Summary of ``ntr`` options
1285*7f296bb3SBarry Smith>    :name: table_ntroptions
1286*7f296bb3SBarry Smith>
1287*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1288*7f296bb3SBarry Smith>    | Name ``-tao_ntr_``        | Value          | Default          | Description          |
1289*7f296bb3SBarry Smith>    +===========================+================+==================+======================+
1290*7f296bb3SBarry Smith>    | ``ksp_type``              | nash, stcg     | stcg             | KSPType for          |
1291*7f296bb3SBarry Smith>    |                           |                |                  | linear system        |
1292*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1293*7f296bb3SBarry Smith>    | ``pc_type``               | none, jacobi   | lmvm             | PCType for linear    |
1294*7f296bb3SBarry Smith>    |                           |                |                  | system               |
1295*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1296*7f296bb3SBarry Smith>    |          ``init_type``    | constant,      | interpolation    | Radius               |
1297*7f296bb3SBarry Smith>    |                           | direction,     |                  | initialization       |
1298*7f296bb3SBarry Smith>    |                           | interpolation  |                  | method               |
1299*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1300*7f296bb3SBarry Smith>    |          ``mu1_i``        | real           | 0.35             | :math:`\mu_1`        |
1301*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1302*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1303*7f296bb3SBarry Smith>    |                           |                |                  | init                 |
1304*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1305*7f296bb3SBarry Smith>    |          ``mu2_i``        | real           | 0.50             | :math:`\mu_2`        |
1306*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1307*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1308*7f296bb3SBarry Smith>    |                           |                |                  | init                 |
1309*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1310*7f296bb3SBarry Smith>    |          ``gamma1_i``     | real           | 0.0625           | :math:`\gamma_1`     |
1311*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1312*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1313*7f296bb3SBarry Smith>    |                           |                |                  | init                 |
1314*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1315*7f296bb3SBarry Smith>    |          ``gamma2_i``     | real           | 0.50             | :math:`\gamma_2`     |
1316*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1317*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1318*7f296bb3SBarry Smith>    |                           |                |                  | init                 |
1319*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1320*7f296bb3SBarry Smith>    |          ``gamma3_i``     | real           | 2.00             | :math:`\gamma_3`     |
1321*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1322*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1323*7f296bb3SBarry Smith>    |                           |                |                  | init                 |
1324*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1325*7f296bb3SBarry Smith>    |          ``gamma4_i``     | real           | 5.00             | :math:`\gamma_4`     |
1326*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1327*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1328*7f296bb3SBarry Smith>    |                           |                |                  | init                 |
1329*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1330*7f296bb3SBarry Smith>    |          ``theta_i``      | real           | 0.25             | :math:`\theta`       |
1331*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1332*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1333*7f296bb3SBarry Smith>    |                           |                |                  | init                 |
1334*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1335*7f296bb3SBarry Smith>    |          ``update_type``  | step,          | step             | Radius               |
1336*7f296bb3SBarry Smith>    |                           | reduction,     |                  | update method        |
1337*7f296bb3SBarry Smith>    |                           | interpolation  |                  |                      |
1338*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1339*7f296bb3SBarry Smith>    | ``mu1_i``                 | real           | 0.35             | :math:`\mu_1`        |
1340*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1341*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1342*7f296bb3SBarry Smith>    |                           |                |                  | init                 |
1343*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1344*7f296bb3SBarry Smith>    | ``mu2_i``                 | real           | 0.50             | :math:`\mu_2`        |
1345*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1346*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1347*7f296bb3SBarry Smith>    |                           |                |                  | init                 |
1348*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1349*7f296bb3SBarry Smith>    | ``gamma1_i``              | real           | 0.0625           | :math:`\gamma_1`     |
1350*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1351*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1352*7f296bb3SBarry Smith>    |                           |                |                  | init                 |
1353*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1354*7f296bb3SBarry Smith>    | ``gamma2_i``              | real           | 0.50             | :math:`\gamma_2`     |
1355*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1356*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1357*7f296bb3SBarry Smith>    |                           |                |                  | init                 |
1358*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1359*7f296bb3SBarry Smith>    | ``gamma3_i``              | real           | 2.00             | :math:`\gamma_3`     |
1360*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1361*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1362*7f296bb3SBarry Smith>    |                           |                |                  | init                 |
1363*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1364*7f296bb3SBarry Smith>    | ``gamma4_i``              | real           | 5.00             | :math:`\gamma_4`     |
1365*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1366*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1367*7f296bb3SBarry Smith>    |                           |                |                  | init                 |
1368*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1369*7f296bb3SBarry Smith>    | ``theta_i``               | real           | 0.25             | :math:`\theta`       |
1370*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1371*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1372*7f296bb3SBarry Smith>    |                           |                |                  | init                 |
1373*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1374*7f296bb3SBarry Smith>    |          ``eta1``         | real           | :                | :math:`\eta_1`       |
1375*7f296bb3SBarry Smith>    |                           |                |                  | in ``reduction``     |
1376*7f296bb3SBarry Smith>    |                           |                |                  | update               |
1377*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1378*7f296bb3SBarry Smith>    |          ``eta2``         | real           | 0.25             | :math:`\eta_2`       |
1379*7f296bb3SBarry Smith>    |                           |                |                  | in ``reduction``     |
1380*7f296bb3SBarry Smith>    |                           |                |                  | update               |
1381*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1382*7f296bb3SBarry Smith>    |          ``eta3``         | real           | 0.50             | :math:`\eta_3`       |
1383*7f296bb3SBarry Smith>    |                           |                |                  | in ``reduction``     |
1384*7f296bb3SBarry Smith>    |                           |                |                  | update               |
1385*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1386*7f296bb3SBarry Smith>    |          ``eta4``         | real           | 0.90             | :math:`\eta_4`       |
1387*7f296bb3SBarry Smith>    |                           |                |                  | in ``reduction``     |
1388*7f296bb3SBarry Smith>    |                           |                |                  | update               |
1389*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1390*7f296bb3SBarry Smith>    |          ``alpha1``       | real           | 0.25             | :math:`\alpha_1`     |
1391*7f296bb3SBarry Smith>    |                           |                |                  | in ``reduction``     |
1392*7f296bb3SBarry Smith>    |                           |                |                  | update               |
1393*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1394*7f296bb3SBarry Smith>    |          ``alpha2``       | real           | 0.50             | :math:`\alpha_2`     |
1395*7f296bb3SBarry Smith>    |                           |                |                  | in ``reduction``     |
1396*7f296bb3SBarry Smith>    |                           |                |                  | update               |
1397*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1398*7f296bb3SBarry Smith>    |          ``alpha3``       | real           | 1.00             | :math:`\alpha_3`     |
1399*7f296bb3SBarry Smith>    |                           |                |                  | in ``reduction``     |
1400*7f296bb3SBarry Smith>    |                           |                |                  | update               |
1401*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1402*7f296bb3SBarry Smith>    |          ``alpha4``       | real           | 2.00             | :math:`\alpha_4`     |
1403*7f296bb3SBarry Smith>    |                           |                |                  | in ``reduction``     |
1404*7f296bb3SBarry Smith>    |                           |                |                  | update               |
1405*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1406*7f296bb3SBarry Smith>    |          ``alpha5``       | real           | 4.00             | :math:`\alpha_5`     |
1407*7f296bb3SBarry Smith>    |                           |                |                  | in ``reduction``     |
1408*7f296bb3SBarry Smith>    |                           |                |                  | update               |
1409*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1410*7f296bb3SBarry Smith>    |          ``mu1``          | real           | 0.10             | :math:`\mu_1`        |
1411*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1412*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1413*7f296bb3SBarry Smith>    |                           |                |                  | update               |
1414*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1415*7f296bb3SBarry Smith>    |          ``mu2``          | real           | 0.50             | :math:`\mu_2`        |
1416*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1417*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1418*7f296bb3SBarry Smith>    |                           |                |                  | update               |
1419*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1420*7f296bb3SBarry Smith>    |          ``gamma1``       | real           | 0.25             | :math:`\gamma_1`     |
1421*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1422*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1423*7f296bb3SBarry Smith>    |                           |                |                  | update               |
1424*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1425*7f296bb3SBarry Smith>    |          ``gamma2``       | real           | 0.50             | :math:`\gamma_2`     |
1426*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1427*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1428*7f296bb3SBarry Smith>    |                           |                |                  | update               |
1429*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1430*7f296bb3SBarry Smith>    |          ``gamma3``       | real           | 2.00             | :math:`\gamma_3`     |
1431*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1432*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1433*7f296bb3SBarry Smith>    |                           |                |                  | update               |
1434*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1435*7f296bb3SBarry Smith>    |          ``gamma4``       | real           | 4.00             | :math:`\gamma_4`     |
1436*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1437*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1438*7f296bb3SBarry Smith>    |                           |                |                  | update               |
1439*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1440*7f296bb3SBarry Smith>    |          ``theta``        | real           | 0.05             | :math:`\theta`       |
1441*7f296bb3SBarry Smith>    |                           |                |                  | in                   |
1442*7f296bb3SBarry Smith>    |                           |                |                  | ``interpolation``    |
1443*7f296bb3SBarry Smith>    |                           |                |                  | update               |
1444*7f296bb3SBarry Smith>    +---------------------------+----------------+------------------+----------------------+
1445*7f296bb3SBarry Smith> ```
1446*7f296bb3SBarry Smith
1447*7f296bb3SBarry SmithThe quadratic optimization problem is approximately solved by applying
1448*7f296bb3SBarry Smiththe Nash or Steihaug-Toint conjugate gradient methods or the generalized
1449*7f296bb3SBarry SmithLanczos method to the symmetric system of equations
1450*7f296bb3SBarry Smith$H_k d = -g_k$. The method used to solve the system of equations
1451*7f296bb3SBarry Smithis specified with the command line argument
1452*7f296bb3SBarry Smith`-tao_ntr_ksp_type <nash,stcg,gltr>`; `stcg` is the default. See the
1453*7f296bb3SBarry SmithPETSc manual for further information on changing the behavior of these
1454*7f296bb3SBarry Smithlinear system solvers.
1455*7f296bb3SBarry Smith
1456*7f296bb3SBarry SmithA good preconditioner reduces the number of iterations required to
1457*7f296bb3SBarry Smithcompute the direction. For the Nash and Steihaug-Toint conjugate
1458*7f296bb3SBarry Smithgradient methods and generalized Lanczos method, this preconditioner
1459*7f296bb3SBarry Smithmust be symmetric and positive definite. The available options are to
1460*7f296bb3SBarry Smithuse no preconditioner, the absolute value of the diagonal of the Hessian
1461*7f296bb3SBarry Smithmatrix, a limited-memory BFGS approximation to the Hessian matrix, or
1462*7f296bb3SBarry Smithone of the other preconditioners provided by the PETSc package. These
1463*7f296bb3SBarry Smithpreconditioners are specified by the command line argument
1464*7f296bb3SBarry Smith`-tao_ntr_pc_type <none,jacobi,icc,ilu,lmvm>`, respectively. The
1465*7f296bb3SBarry Smithdefault is the `lmvm` preconditioner. See the PETSc manual for further
1466*7f296bb3SBarry Smithinformation on changing the behavior of the preconditioners.
1467*7f296bb3SBarry Smith
1468*7f296bb3SBarry SmithThe method for computing an initial trust-region radius is set with the
1469*7f296bb3SBarry Smithcommand line arguments
1470*7f296bb3SBarry Smith`-tao_ntr_init_type <constant,direction,interpolation>`;
1471*7f296bb3SBarry Smith`interpolation`, which chooses an initial value based on the
1472*7f296bb3SBarry Smithinterpolation scheme found in {cite}`cgt`, is the default.
1473*7f296bb3SBarry SmithThis scheme performs a number of function and gradient evaluations to
1474*7f296bb3SBarry Smithdetermine a radius such that the reduction predicted by the quadratic
1475*7f296bb3SBarry Smithmodel along the gradient direction coincides with the actual reduction
1476*7f296bb3SBarry Smithin the nonlinear function. The iterate obtaining the best objective
1477*7f296bb3SBarry Smithfunction value is used as the starting point for the main trust-region
1478*7f296bb3SBarry Smithalgorithm. The `constant` method initializes the trust-region radius
1479*7f296bb3SBarry Smithby using the value specified with the `-tao_trust0 <real>` command
1480*7f296bb3SBarry Smithline argument, where the default value is 100. The `direction`
1481*7f296bb3SBarry Smithtechnique solves the first quadratic optimization problem by using a
1482*7f296bb3SBarry Smithstandard conjugate gradient method and initializes the trust region to
1483*7f296bb3SBarry Smith$\|s_0\|$.
1484*7f296bb3SBarry Smith
1485*7f296bb3SBarry SmithThe method for updating the trust-region radius is set with the command
1486*7f296bb3SBarry Smithline arguments `-tao_ntr_update_type <reduction,interpolation>`;
1487*7f296bb3SBarry Smith`reduction` is the default. The `reduction` method computes the
1488*7f296bb3SBarry Smithratio of the actual reduction in the objective function to the reduction
1489*7f296bb3SBarry Smithpredicted by the quadratic model for the full step,
1490*7f296bb3SBarry Smith$\kappa_k = \frac{f(x_k) - f(x_k + d_k)}{q(x_k) - q(x_k + d_k)}$,
1491*7f296bb3SBarry Smithwhere $q_k$ is the quadratic model. The radius is then updated as
1492*7f296bb3SBarry Smith
1493*7f296bb3SBarry Smith$$
1494*7f296bb3SBarry Smith\Delta_{k+1} = \left\{\begin{array}{ll}
1495*7f296bb3SBarry Smith\alpha_1 \text{min}(\Delta_k, \|d_k\|) & \text{if } \kappa_k \in (-\infty, \eta_1) \\
1496*7f296bb3SBarry Smith\alpha_2 \text{min}(\Delta_k, \|d_k\|) & \text{if } \kappa_k \in [\eta_1, \eta_2) \\
1497*7f296bb3SBarry Smith\alpha_3 \Delta_k & \text{if } \kappa_k \in [\eta_2, \eta_3) \\
1498*7f296bb3SBarry Smith\text{max}(\Delta_k, \alpha_4 \|d_k\|) & \text{if } \kappa_k \in [\eta_3, \eta_4) \\
1499*7f296bb3SBarry Smith\text{max}(\Delta_k, \alpha_5 \|d_k\|) & \text{if } \kappa_k \in [\eta_4, \infty),
1500*7f296bb3SBarry Smith\end{array}
1501*7f296bb3SBarry Smith\right.
1502*7f296bb3SBarry Smith$$
1503*7f296bb3SBarry Smith
1504*7f296bb3SBarry Smithwhere
1505*7f296bb3SBarry Smith$0 < \alpha_1 < \alpha_2 < \alpha_3 = 1 < \alpha_4 < \alpha_5$ and
1506*7f296bb3SBarry Smith$0 < \eta_1 < \eta_2 < \eta_3 < \eta_4$ are constants. The
1507*7f296bb3SBarry Smith`interpolation` method uses the same interpolation mechanism as in the
1508*7f296bb3SBarry Smithinitialization to compute a new value for the trust-region radius.
1509*7f296bb3SBarry Smith
1510*7f296bb3SBarry SmithThis algorithm will be deprecated in the next version and replaced by
1511*7f296bb3SBarry Smiththe Bounded Newton Trust Region (BNTR) algorithm that can solve both
1512*7f296bb3SBarry Smithbound constrained and unconstrained problems.
1513*7f296bb3SBarry Smith
1514*7f296bb3SBarry Smith##### Newton Trust Region with Line Search (NTL)
1515*7f296bb3SBarry Smith
1516*7f296bb3SBarry SmithNTL safeguards the trust-region globalization such that a line search
1517*7f296bb3SBarry Smithis used in the event that the step is initially rejected by the
1518*7f296bb3SBarry Smithpredicted versus actual decrease comparison. If the line search fails to
1519*7f296bb3SBarry Smithfind a viable step length for the Newton step, it falls back onto a
1520*7f296bb3SBarry Smithscaled gradient or a gradient descent step. The trust radius is then
1521*7f296bb3SBarry Smithmodified based on the line search step length.
1522*7f296bb3SBarry Smith
1523*7f296bb3SBarry SmithThis algorithm will be deprecated in the next version and replaced by
1524*7f296bb3SBarry Smiththe Bounded Newton Trust Region with Line Search (BNTL) algorithm that
1525*7f296bb3SBarry Smithcan solve both bound constrained and unconstrained problems.
1526*7f296bb3SBarry Smith
1527*7f296bb3SBarry Smith#### Limited-Memory Variable-Metric Method (LMVM)
1528*7f296bb3SBarry Smith
1529*7f296bb3SBarry SmithThe limited-memory, variable-metric method (LMVM) computes a positive definite
1530*7f296bb3SBarry Smithapproximation to the Hessian matrix from a limited number of previous
1531*7f296bb3SBarry Smithiterates and gradient evaluations. A direction is then obtained by
1532*7f296bb3SBarry Smithsolving the system of equations
1533*7f296bb3SBarry Smith
1534*7f296bb3SBarry Smith$$
1535*7f296bb3SBarry SmithH_k d_k = -\nabla f(x_k),
1536*7f296bb3SBarry Smith$$
1537*7f296bb3SBarry Smith
1538*7f296bb3SBarry Smithwhere $H_k$ is the Hessian approximation obtained by using the
1539*7f296bb3SBarry SmithBFGS update formula. The inverse of $H_k$ can readily be applied
1540*7f296bb3SBarry Smithto obtain the direction $d_k$. Having obtained the direction, a
1541*7f296bb3SBarry SmithMoré-Thuente line search is applied to compute a step length,
1542*7f296bb3SBarry Smith$\tau_k$, that approximately solves the one-dimensional
1543*7f296bb3SBarry Smithoptimization problem
1544*7f296bb3SBarry Smith
1545*7f296bb3SBarry Smith$$
1546*7f296bb3SBarry Smith\min_\tau f(x_k + \tau d_k).
1547*7f296bb3SBarry Smith$$
1548*7f296bb3SBarry Smith
1549*7f296bb3SBarry SmithThe current iterate and Hessian approximation are updated, and the
1550*7f296bb3SBarry Smithprocess is repeated until the method converges. This algorithm is the
1551*7f296bb3SBarry Smithdefault unconstrained minimization solver and can be selected by using
1552*7f296bb3SBarry Smiththe TAO solver `tao_lmvm`. For best efficiency, function and gradient
1553*7f296bb3SBarry Smithevaluations should be performed simultaneously when using this
1554*7f296bb3SBarry Smithalgorithm.
1555*7f296bb3SBarry Smith
1556*7f296bb3SBarry SmithThe primary factors determining the behavior of this algorithm are the
1557*7f296bb3SBarry Smithtype of Hessian approximation used, the number of vectors stored for the
1558*7f296bb3SBarry Smithapproximation and the initialization/scaling of the approximation. These
1559*7f296bb3SBarry Smithoptions can be configured using the `-tao_lmvm_mat_lmvm` prefix. For
1560*7f296bb3SBarry Smithfurther detail, we refer the reader to the `MATLMVM` matrix type
1561*7f296bb3SBarry Smithdefinitions in the PETSc Manual.
1562*7f296bb3SBarry Smith
1563*7f296bb3SBarry SmithThe LMVM algorithm also allows the user to define a custom initial
1564*7f296bb3SBarry SmithHessian matrix $H_{0,k}$ through the interface function
1565*7f296bb3SBarry Smith`TaoLMVMSetH0()`. This user-provided initialization overrides any
1566*7f296bb3SBarry Smithother scalar or diagonal initialization inherent to the LMVM
1567*7f296bb3SBarry Smithapproximation. The provided $H_{0,k}$ must be a PETSc `Mat` type
1568*7f296bb3SBarry Smithobject that represents a positive-definite matrix. The approximation
1569*7f296bb3SBarry Smithprefers `MatSolve()` if the provided matrix has `MATOP_SOLVE`
1570*7f296bb3SBarry Smithimplemented. Otherwise, `MatMult()` is used in a KSP solve to perform
1571*7f296bb3SBarry Smiththe inversion of the user-provided initial Hessian.
1572*7f296bb3SBarry Smith
1573*7f296bb3SBarry SmithIn applications where `TaoSolve()` on the LMVM algorithm is repeatedly
1574*7f296bb3SBarry Smithcalled to solve similar or related problems, `-tao_lmvm_recycle` flag
1575*7f296bb3SBarry Smithcan be used to prevent resetting the LMVM approximation between
1576*7f296bb3SBarry Smithsubsequent solutions. This recycling also avoids one extra function and
1577*7f296bb3SBarry Smithgradient evaluation, instead re-using the values already computed at the
1578*7f296bb3SBarry Smithend of the previous solution.
1579*7f296bb3SBarry Smith
1580*7f296bb3SBarry SmithThis algorithm will be deprecated in the next version and replaced by
1581*7f296bb3SBarry Smiththe Bounded Quasi-Newton Line Search (BQNLS) algorithm that can solve
1582*7f296bb3SBarry Smithboth bound constrained and unconstrained problems.
1583*7f296bb3SBarry Smith
1584*7f296bb3SBarry Smith#### Nonlinear Conjugate Gradient Method (CG)
1585*7f296bb3SBarry Smith
1586*7f296bb3SBarry SmithThe nonlinear conjugate gradient method can be viewed as an extension of
1587*7f296bb3SBarry Smiththe conjugate gradient method for solving symmetric, positive-definite
1588*7f296bb3SBarry Smithlinear systems of equations. This algorithm requires only function and
1589*7f296bb3SBarry Smithgradient evaluations as well as a line search. The TAO implementation
1590*7f296bb3SBarry Smithuses a Moré-Thuente line search to obtain the step length. The nonlinear
1591*7f296bb3SBarry Smithconjugate gradient method can be selected by using the TAO solver
1592*7f296bb3SBarry Smith`tao_cg`. For the best efficiency, function and gradient evaluations
1593*7f296bb3SBarry Smithshould be performed simultaneously when using this algorithm.
1594*7f296bb3SBarry Smith
1595*7f296bb3SBarry SmithFive variations are currently supported by the TAO implementation: the
1596*7f296bb3SBarry SmithFletcher-Reeves method, the Polak-Ribiére method, the Polak-Ribiére-Plus
1597*7f296bb3SBarry Smithmethod {cite}`nocedal2006numerical`, the Hestenes-Stiefel method, and the
1598*7f296bb3SBarry SmithDai-Yuan method. These conjugate gradient methods can be specified by
1599*7f296bb3SBarry Smithusing the command line argument `-tao_cg_type <fr,pr,prp,hs,dy>`,
1600*7f296bb3SBarry Smithrespectively. The default value is `prp`.
1601*7f296bb3SBarry Smith
1602*7f296bb3SBarry SmithThe conjugate gradient method incorporates automatic restarts when
1603*7f296bb3SBarry Smithsuccessive gradients are not sufficiently orthogonal. TAO measures the
1604*7f296bb3SBarry Smithorthogonality by dividing the inner product of the gradient at the
1605*7f296bb3SBarry Smithcurrent point and the gradient at the previous point by the square of
1606*7f296bb3SBarry Smiththe Euclidean norm of the gradient at the current point. When the
1607*7f296bb3SBarry Smithabsolute value of this ratio is greater than $\eta$, the algorithm
1608*7f296bb3SBarry Smithrestarts using the gradient direction. The parameter $\eta$ can be
1609*7f296bb3SBarry Smithset by using the command line argument `-tao_cg_eta <real>`; 0.1 is
1610*7f296bb3SBarry Smiththe default value.
1611*7f296bb3SBarry Smith
1612*7f296bb3SBarry SmithThis algorithm will be deprecated in the next version and replaced by
1613*7f296bb3SBarry Smiththe Bounded Nonlinear Conjugate Gradient (BNCG) algorithm that can solve
1614*7f296bb3SBarry Smithboth bound constrained and unconstrained problems.
1615*7f296bb3SBarry Smith
1616*7f296bb3SBarry Smith#### Nelder-Mead Simplex Method (NM)
1617*7f296bb3SBarry Smith
1618*7f296bb3SBarry SmithThe Nelder-Mead algorithm {cite}`nelder.mead:simplex` is a
1619*7f296bb3SBarry Smithdirect search method for finding a local minimum of a function
1620*7f296bb3SBarry Smith$f(x)$. This algorithm does not require any gradient or Hessian
1621*7f296bb3SBarry Smithinformation of $f$ and therefore has some expected advantages and
1622*7f296bb3SBarry Smithdisadvantages compared to the other TAO solvers. The obvious advantage
1623*7f296bb3SBarry Smithis that it is easier to write an application when no derivatives need to
1624*7f296bb3SBarry Smithbe calculated. The downside is that this algorithm can be slow to
1625*7f296bb3SBarry Smithconverge or can even stagnate, and it performs poorly for large numbers
1626*7f296bb3SBarry Smithof variables.
1627*7f296bb3SBarry Smith
1628*7f296bb3SBarry SmithThis solver keeps a set of $N+1$ sorted vectors
1629*7f296bb3SBarry Smith${x_1,x_2,\ldots,x_{N+1}}$ and their corresponding objective
1630*7f296bb3SBarry Smithfunction values $f_1 \leq f_2 \leq \ldots \leq f_{N+1}$. At each
1631*7f296bb3SBarry Smithiteration, $x_{N+1}$ is removed from the set and replaced with
1632*7f296bb3SBarry Smith
1633*7f296bb3SBarry Smith$$
1634*7f296bb3SBarry Smithx(\mu) = (1+\mu) \frac{1}{N} \sum_{i=1}^N x_i - \mu x_{N+1},
1635*7f296bb3SBarry Smith$$
1636*7f296bb3SBarry Smith
1637*7f296bb3SBarry Smithwhere $\mu$ can be one of
1638*7f296bb3SBarry Smith${\mu_0,2\mu_0,\frac{1}{2}\mu_0,-\frac{1}{2}\mu_0}$ depending on
1639*7f296bb3SBarry Smiththe values of each possible $f(x(\mu))$.
1640*7f296bb3SBarry Smith
1641*7f296bb3SBarry SmithThe algorithm terminates when the residual $f_{N+1} - f_1$ becomes
1642*7f296bb3SBarry Smithsufficiently small. Because of the way new vectors can be added to the
1643*7f296bb3SBarry Smithsorted set, the minimum function value and/or the residual may not be
1644*7f296bb3SBarry Smithimpacted at each iteration.
1645*7f296bb3SBarry Smith
1646*7f296bb3SBarry SmithTwo options can be set specifically for the Nelder-Mead algorithm:
1647*7f296bb3SBarry Smith
1648*7f296bb3SBarry Smith`-tao_nm_lambda <value>`
1649*7f296bb3SBarry Smith
1650*7f296bb3SBarry Smith: sets the initial set of vectors ($x_0$ plus `value` in each
1651*7f296bb3SBarry Smith  coordinate direction); the default value is $1$.
1652*7f296bb3SBarry Smith
1653*7f296bb3SBarry Smith`-tao_nm_mu <value>`
1654*7f296bb3SBarry Smith
1655*7f296bb3SBarry Smith: sets the value of $\mu_0$; the default is $\mu_0=1$.
1656*7f296bb3SBarry Smith
1657*7f296bb3SBarry Smith(sec_tao_bound)=
1658*7f296bb3SBarry Smith
1659*7f296bb3SBarry Smith### Bound-Constrained Optimization
1660*7f296bb3SBarry Smith
1661*7f296bb3SBarry SmithBound-constrained optimization algorithms solve optimization problems of
1662*7f296bb3SBarry Smiththe form
1663*7f296bb3SBarry Smith
1664*7f296bb3SBarry Smith$$
1665*7f296bb3SBarry Smith\begin{array}{ll} \displaystyle
1666*7f296bb3SBarry Smith\min_{x} & f(x) \\
1667*7f296bb3SBarry Smith\text{subject to} & l \leq x \leq u.
1668*7f296bb3SBarry Smith\end{array}
1669*7f296bb3SBarry Smith$$
1670*7f296bb3SBarry Smith
1671*7f296bb3SBarry SmithThese solvers use the bounds on the variables as well as objective
1672*7f296bb3SBarry Smithfunction, gradient, and possibly Hessian information.
1673*7f296bb3SBarry Smith
1674*7f296bb3SBarry SmithFor any unbounded variables, the bound value for the associated index
1675*7f296bb3SBarry Smithcan be set to `PETSC_INFINITY` for the upper bound and
1676*7f296bb3SBarry Smith`PETSC_NINFINITY` for the lower bound. If all bounds are set to
1677*7f296bb3SBarry Smithinfinity, then the bounded algorithms are equivalent to their
1678*7f296bb3SBarry Smithunconstrained counterparts.
1679*7f296bb3SBarry Smith
1680*7f296bb3SBarry SmithBefore introducing specific methods, we will first define two projection
1681*7f296bb3SBarry Smithoperations used by all bound constrained algorithms.
1682*7f296bb3SBarry Smith
1683*7f296bb3SBarry Smith- Gradient projection:
1684*7f296bb3SBarry Smith
1685*7f296bb3SBarry Smith  $$
1686*7f296bb3SBarry Smith  \mathfrak{P}(g) = \left\{\begin{array}{ll}
1687*7f296bb3SBarry Smith  0 & \text{if} \; (x \leq l_i \land g_i > 0) \lor (x \geq u_i \land g_i < 0) \\
1688*7f296bb3SBarry Smith  g_i & \text{otherwise}
1689*7f296bb3SBarry Smith  \end{array}
1690*7f296bb3SBarry Smith  \right.
1691*7f296bb3SBarry Smith  $$
1692*7f296bb3SBarry Smith
1693*7f296bb3SBarry Smith- Bound projection:
1694*7f296bb3SBarry Smith
1695*7f296bb3SBarry Smith  $$
1696*7f296bb3SBarry Smith  \mathfrak{B}(x) = \left\{\begin{array}{ll}
1697*7f296bb3SBarry Smith  l_i & \text{if} \; x_i < l_i \\
1698*7f296bb3SBarry Smith  u_i & \text{if} \; x_i > u_i \\
1699*7f296bb3SBarry Smith  x_i & \text{otherwise}
1700*7f296bb3SBarry Smith  \end{array}
1701*7f296bb3SBarry Smith  \right.
1702*7f296bb3SBarry Smith  $$
1703*7f296bb3SBarry Smith
1704*7f296bb3SBarry Smith(sec_tao_bnk)=
1705*7f296bb3SBarry Smith
1706*7f296bb3SBarry Smith#### Bounded Newton-Krylov Methods
1707*7f296bb3SBarry Smith
1708*7f296bb3SBarry SmithTAO features three bounded Newton-Krylov (BNK) class of algorithms,
1709*7f296bb3SBarry Smithseparated by their globalization methods: projected line search (BNLS),
1710*7f296bb3SBarry Smithtrust region (BNTR), and trust region with a projected line search
1711*7f296bb3SBarry Smithfall-back (BNTL). They are available via the TAO solvers `TAOBNLS`,
1712*7f296bb3SBarry Smith`TAOBNTR` and `TAOBNTL`, respectively, or the `-tao_type`
1713*7f296bb3SBarry Smith`bnls`/`bntr`/`bntl` flag.
1714*7f296bb3SBarry Smith
1715*7f296bb3SBarry SmithThe BNK class of methods use an active-set approach to solve the
1716*7f296bb3SBarry Smithsymmetric system of equations,
1717*7f296bb3SBarry Smith
1718*7f296bb3SBarry Smith$$
1719*7f296bb3SBarry SmithH_k p_k = -g_k,
1720*7f296bb3SBarry Smith$$
1721*7f296bb3SBarry Smith
1722*7f296bb3SBarry Smithonly for inactive variables in the interior of the bounds. The
1723*7f296bb3SBarry Smithactive-set estimation is based on Bertsekas
1724*7f296bb3SBarry Smith{cite}`bertsekas:projected` with the following variable
1725*7f296bb3SBarry Smithindex categories:
1726*7f296bb3SBarry Smith
1727*7f296bb3SBarry Smith$$
1728*7f296bb3SBarry Smith\begin{array}{rlll} \displaystyle
1729*7f296bb3SBarry Smith\text{lower bounded}: & \mathcal{L}(x) & = & \{ i \; : \; x_i \leq l_i + \epsilon \; \land \; g(x)_i > 0 \}, \\
1730*7f296bb3SBarry Smith\text{upper bounded}: & \mathcal{U}(x) & = & \{ i \; : \; x_i \geq u_i + \epsilon \; \land \; g(x)_i < 0 \}, \\
1731*7f296bb3SBarry Smith\text{fixed}: & \mathcal{F}(x) & = & \{ i \; : \; l_i = u_i \}, \\
1732*7f296bb3SBarry Smith\text{active-set}: & \mathcal{A}(x) & = & \{ \mathcal{L}(x) \; \bigcup \; \mathcal{U}(x) \; \bigcup \; \mathcal{F}(x) \}, \\
1733*7f296bb3SBarry Smith\text{inactive-set}: & \mathcal{I}(x) & = & \{ 1,2,\ldots,n \} \; \backslash \; \mathcal{A}(x).
1734*7f296bb3SBarry Smith\end{array}
1735*7f296bb3SBarry Smith$$
1736*7f296bb3SBarry Smith
1737*7f296bb3SBarry SmithAt each iteration, the bound tolerance is estimated as
1738*7f296bb3SBarry Smith$\epsilon_{k+1} = \text{min}(\epsilon_k, ||w_k||_2)$ with
1739*7f296bb3SBarry Smith$w_k = x_k - \mathfrak{B}(x_k - \beta D_k g_k)$, where the
1740*7f296bb3SBarry Smithdiagonal matrix $D_k$ is an approximation of the Hessian inverse
1741*7f296bb3SBarry Smith$H_k^{-1}$. The initial bound tolerance $\epsilon_0$ and the
1742*7f296bb3SBarry Smithstep length $\beta$ have default values of $0.001$ and can
1743*7f296bb3SBarry Smithbe adjusted using `-tao_bnk_as_tol` and `-tao_bnk_as_step` flags,
1744*7f296bb3SBarry Smithrespectively. The active-set estimation can be disabled using the option
1745*7f296bb3SBarry Smith`-tao_bnk_as_type none`, in which case the algorithm simply uses the
1746*7f296bb3SBarry Smithcurrent iterate with no bound tolerances to determine which variables
1747*7f296bb3SBarry Smithare actively bounded and which are free.
1748*7f296bb3SBarry Smith
1749*7f296bb3SBarry SmithBNK algorithms invert the reduced Hessian using a Krylov iterative
1750*7f296bb3SBarry Smithmethod. Trust-region conjugate gradient methods (`KSPNASH`,
1751*7f296bb3SBarry Smith`KSPSTCG`, and `KSPGLTR`) are required for the BNTR and BNTL
1752*7f296bb3SBarry Smithalgorithms, and recommended for the BNLS algorithm. The preconditioner
1753*7f296bb3SBarry Smithtype can be changed using the `-tao_bnk_pc_type`
1754*7f296bb3SBarry Smith`none`/`ilu`/`icc`/`jacobi`/`lmvm`. The `lmvm` option, which
1755*7f296bb3SBarry Smithis also the default, preconditions the Krylov solution with a
1756*7f296bb3SBarry Smith`MATLMVM` matrix. The remaining supported preconditioner types are
1757*7f296bb3SBarry Smithdefault PETSc types. If Jacobi is selected, the diagonal values are
1758*7f296bb3SBarry Smithsafeguarded to be positive. `icc` and `ilu` options produce good
1759*7f296bb3SBarry Smithresults for problems with dense Hessians. The LMVM and Jacobi
1760*7f296bb3SBarry Smithpreconditioners are also used as the approximate inverse-Hessian in the
1761*7f296bb3SBarry Smithactive-set estimation. If neither are available, or if the Hessian
1762*7f296bb3SBarry Smithmatrix does not have `MATOP_GET_DIAGONAL` defined, then the active-set
1763*7f296bb3SBarry Smithestimation falls back onto using an identity matrix in place of
1764*7f296bb3SBarry Smith$D_k$ (this is equivalent to estimating the active-set using a
1765*7f296bb3SBarry Smithgradient descent step).
1766*7f296bb3SBarry Smith
1767*7f296bb3SBarry SmithA special option is available to *accelerate* the convergence of the BNK
1768*7f296bb3SBarry Smithalgorithms by taking a finite number of BNCG iterations at each Newton
1769*7f296bb3SBarry Smithiteration. By default, the number of BNCG iterations is set to zero and
1770*7f296bb3SBarry Smiththe algorithms do not take any BNCG steps. This can be changed using the
1771*7f296bb3SBarry Smithoption flag `-tao_bnk_max_cg_its <i>`. While this reduces the number
1772*7f296bb3SBarry Smithof Newton iterations, in practice it simply trades off the Hessian
1773*7f296bb3SBarry Smithevaluations in the BNK solver for more function and gradient evaluations
1774*7f296bb3SBarry Smithin the BNCG solver. However, it may be useful for certain types of
1775*7f296bb3SBarry Smithproblems where the Hessian evaluation is disproportionately more
1776*7f296bb3SBarry Smithexpensive than the objective function or its gradient.
1777*7f296bb3SBarry Smith
1778*7f296bb3SBarry Smith(sec_tao_bnls)=
1779*7f296bb3SBarry Smith
1780*7f296bb3SBarry Smith##### Bounded Newton Line Search (BNLS)
1781*7f296bb3SBarry Smith
1782*7f296bb3SBarry SmithBNLS safeguards the Newton step by falling back onto a BFGS, scaled
1783*7f296bb3SBarry Smithgradient, or gradient steps based on descent direction verifications.
1784*7f296bb3SBarry SmithFor problems with indefinite Hessian matrices, the step direction is
1785*7f296bb3SBarry Smithcalculated using a perturbed system of equations,
1786*7f296bb3SBarry Smith
1787*7f296bb3SBarry Smith$$
1788*7f296bb3SBarry Smith(H_k + \rho_k I)p_k = -g_k,
1789*7f296bb3SBarry Smith$$
1790*7f296bb3SBarry Smith
1791*7f296bb3SBarry Smithwhere $\rho_k$ is a dynamically adjusted positive constant. The
1792*7f296bb3SBarry Smithstep is globalized using a projected Moré-Thuente line search. If a
1793*7f296bb3SBarry Smithtrust-region conjugate gradient method is used for the Hessian
1794*7f296bb3SBarry Smithinversion, the trust radius is modified based on the line search step
1795*7f296bb3SBarry Smithlength.
1796*7f296bb3SBarry Smith
1797*7f296bb3SBarry Smith(sec_tao_bntr)=
1798*7f296bb3SBarry Smith
1799*7f296bb3SBarry Smith##### Bounded Newton Trust Region (BNTR)
1800*7f296bb3SBarry Smith
1801*7f296bb3SBarry SmithBNTR globalizes the Newton step using a trust region method based on the
1802*7f296bb3SBarry Smithpredicted versus actual reduction in the cost function. The trust radius
1803*7f296bb3SBarry Smithis increased only if the accepted step is at the trust region boundary.
1804*7f296bb3SBarry SmithThe reduction check features a safeguard for numerical values below
1805*7f296bb3SBarry Smithmachine epsilon, scaled by the latest function value, where the full
1806*7f296bb3SBarry SmithNewton step is accepted without modification.
1807*7f296bb3SBarry Smith
1808*7f296bb3SBarry Smith(sec_tao_bntl)=
1809*7f296bb3SBarry Smith
1810*7f296bb3SBarry Smith##### Bounded Newton Trust Region with Line Search (BNTL)
1811*7f296bb3SBarry Smith
1812*7f296bb3SBarry SmithBNTL safeguards the trust-region globalization such that a line search
1813*7f296bb3SBarry Smithis used in the event that the step is initially rejected by the
1814*7f296bb3SBarry Smithpredicted versus actual decrease comparison. If the line search fails to
1815*7f296bb3SBarry Smithfind a viable step length for the Newton step, it falls back onto a
1816*7f296bb3SBarry Smithscaled gradient or a gradient descent step. The trust radius is then
1817*7f296bb3SBarry Smithmodified based on the line search step length.
1818*7f296bb3SBarry Smith
1819*7f296bb3SBarry Smith(sec_tao_bqnls)=
1820*7f296bb3SBarry Smith
1821*7f296bb3SBarry Smith#### Bounded Quasi-Newton Line Search (BQNLS)
1822*7f296bb3SBarry Smith
1823*7f296bb3SBarry SmithThe BQNLS algorithm uses the BNLS infrastructure, but replaces the step
1824*7f296bb3SBarry Smithcalculation with a direct inverse application of the approximate Hessian
1825*7f296bb3SBarry Smithbased on quasi-Newton update formulas. No Krylov solver is used in the
1826*7f296bb3SBarry Smithsolution, and therefore the quasi-Newton method chosen must guarantee a
1827*7f296bb3SBarry Smithpositive-definite Hessian approximation. This algorithm is available via
1828*7f296bb3SBarry Smith`tao_type bqnls`.
1829*7f296bb3SBarry Smith
1830*7f296bb3SBarry Smith(sec_tao_bqnk)=
1831*7f296bb3SBarry Smith
1832*7f296bb3SBarry Smith#### Bounded Quasi-Newton-Krylov
1833*7f296bb3SBarry Smith
1834*7f296bb3SBarry SmithBQNK algorithms use the BNK infrastructure, but replace the exact
1835*7f296bb3SBarry SmithHessian with a quasi-Newton approximation. The matrix-free forward
1836*7f296bb3SBarry Smithproduct operation based on quasi-Newton update formulas are used in
1837*7f296bb3SBarry Smithconjunction with Krylov solvers to compute step directions. The
1838*7f296bb3SBarry Smithquasi-Newton inverse application is used to precondition the Krylov
1839*7f296bb3SBarry Smithsolution, and typically helps converge to a step direction in
1840*7f296bb3SBarry Smith$\mathcal{O}(10)$ iterations. This approach is most useful with
1841*7f296bb3SBarry Smithquasi-Newton update types such as Symmetric Rank-1 that cannot strictly
1842*7f296bb3SBarry Smithguarantee positive-definiteness. The BNLS framework with Hessian
1843*7f296bb3SBarry Smithshifting, or the BNTR framework with trust region safeguards, can
1844*7f296bb3SBarry Smithsuccessfully compensate for the Hessian approximation becoming
1845*7f296bb3SBarry Smithindefinite.
1846*7f296bb3SBarry Smith
1847*7f296bb3SBarry SmithSimilar to the full Newton-Krylov counterpart, BQNK algorithms come in
1848*7f296bb3SBarry Smiththree forms separated by the globalization technique: line search
1849*7f296bb3SBarry Smith(BQNKLS), trust region (BQNKTR) and trust region w/ line search
1850*7f296bb3SBarry Smithfall-back (BQNKTL). These algorithms are available via
1851*7f296bb3SBarry Smith`tao_type <bqnkls, bqnktr, bqnktl>`.
1852*7f296bb3SBarry Smith
1853*7f296bb3SBarry Smith(sec_tao_bncg)=
1854*7f296bb3SBarry Smith
1855*7f296bb3SBarry Smith#### Bounded Nonlinear Conjugate Gradient (BNCG)
1856*7f296bb3SBarry Smith
1857*7f296bb3SBarry SmithBNCG extends the unconstrained nonlinear conjugate gradient algorithm to
1858*7f296bb3SBarry Smithbound constraints via gradient projections and a bounded Moré-Thuente
1859*7f296bb3SBarry Smithline search.
1860*7f296bb3SBarry Smith
1861*7f296bb3SBarry SmithLike its unconstrained counterpart, BNCG offers gradient descent and a
1862*7f296bb3SBarry Smithvariety of CG updates: Fletcher-Reeves, Polak-Ribiére,
1863*7f296bb3SBarry SmithPolak-Ribiére-Plus, Hestenes-Stiefel, Dai-Yuan, Hager-Zhang, Dai-Kou,
1864*7f296bb3SBarry SmithKou-Dai, and the Self-Scaling Memoryless (SSML) BFGS, DFP, and Broyden
1865*7f296bb3SBarry Smithmethods. These methods can be specified by using the command line
1866*7f296bb3SBarry Smithargument
1867*7f296bb3SBarry Smith`-tao_bncg_type <gd,fr,pr,prp,hs,dy,hz,dk,kd,ssml_bfgs,ssml_dfp,ssml_brdn>`,
1868*7f296bb3SBarry Smithrespectively. The default value is `ssml_bfgs`. We have scalar
1869*7f296bb3SBarry Smithpreconditioning for these methods, and it is controlled by the flag
1870*7f296bb3SBarry Smith`tao_bncg_alpha`. To disable rescaling, use $\alpha = -1.0$,
1871*7f296bb3SBarry Smithotherwise $\alpha \in [0, 1]$. BNCG is available via the TAO
1872*7f296bb3SBarry Smithsolver `TAOBNCG` or the `-tao_type bncg` flag.
1873*7f296bb3SBarry Smith
1874*7f296bb3SBarry SmithSome individual methods also contain their own parameters. The
1875*7f296bb3SBarry SmithHager-Zhang and Dou-Kai methods have a parameter that determines the
1876*7f296bb3SBarry Smithminimum amount of contribution the previous search direction gives to
1877*7f296bb3SBarry Smiththe next search direction. The flags are `-tao_bncg_hz_eta` and
1878*7f296bb3SBarry Smith`-tao_bncg_dk_eta`, and by default are set to $0.4$ and
1879*7f296bb3SBarry Smith$0.5$ respectively. The Kou-Dai method has multiple parameters.
1880*7f296bb3SBarry Smith`-tao_bncg_zeta` serves the same purpose as the previous two; set to
1881*7f296bb3SBarry Smith$0.1$ by default. There is also a parameter to scale the
1882*7f296bb3SBarry Smithcontribution of $y_k \equiv \nabla f(x_k) - \nabla f(x_{k-1})$ in
1883*7f296bb3SBarry Smiththe search direction update. It is controlled by `-tao_bncg_xi`, and
1884*7f296bb3SBarry Smithis equal to $1.0$ by default. There are also times where we want
1885*7f296bb3SBarry Smithto maximize the descent as measured by $\nabla f(x_k)^T d_k$, and
1886*7f296bb3SBarry Smiththat may be done by using a negative value of $\xi$; this achieves
1887*7f296bb3SBarry Smithbetter performance when not using the diagonal preconditioner described
1888*7f296bb3SBarry Smithnext. This is enabled by default, and is controlled by
1889*7f296bb3SBarry Smith`-tao_bncg_neg_xi`. Finally, the Broyden method has its convex
1890*7f296bb3SBarry Smithcombination parameter, set with `-tao_bncg_theta`. We have this as 1.0
1891*7f296bb3SBarry Smithby default, i.e. it is by default the BFGS method. One can also
1892*7f296bb3SBarry Smithindividually tweak the BFGS and DFP contributions using the
1893*7f296bb3SBarry Smithmultiplicative constants `-tao_bncg_scale`; both are set to $1$
1894*7f296bb3SBarry Smithby default.
1895*7f296bb3SBarry Smith
1896*7f296bb3SBarry SmithAll methods can be scaled using the parameter `-tao_bncg_alpha`, which
1897*7f296bb3SBarry Smithcontinuously varies in $[0, 1]$. The default value is set
1898*7f296bb3SBarry Smithdepending on the method from initial testing.
1899*7f296bb3SBarry Smith
1900*7f296bb3SBarry SmithBNCG also offers a special type of method scaling. It employs Broyden
1901*7f296bb3SBarry Smithdiagonal scaling as an option for its CG methods, turned on with the
1902*7f296bb3SBarry Smithflag `-tao_bncg_diag_scaling`. Formulations for both the forward
1903*7f296bb3SBarry Smith(regular) and inverse Broyden methods are developed, controlled by the
1904*7f296bb3SBarry Smithflag `-tao_bncg_mat_lmvm_forward`. It is set to True by default.
1905*7f296bb3SBarry SmithWhether one uses the forward or inverse formulations depends on the
1906*7f296bb3SBarry Smithmethod being used. For example, in our preliminary computations, the
1907*7f296bb3SBarry Smithforward formulation works better for the SSML_BFGS method, but the
1908*7f296bb3SBarry Smithinverse formulation works better for the Hestenes-Stiefel method. The
1909*7f296bb3SBarry Smithconvex combination parameter for the Broyden scaling is controlled by
1910*7f296bb3SBarry Smith`-tao_bncg_mat_lmvm_theta`, and is 0 by default. We also employ
1911*7f296bb3SBarry Smithrescaling of the Broyden diagonal, which aids the linesearch immensely.
1912*7f296bb3SBarry SmithThe rescaling parameter is controlled by `-tao_bncg_mat_lmvm_alpha`,
1913*7f296bb3SBarry Smithand should be $\in [0, 1]$. One can disable rescaling of the
1914*7f296bb3SBarry SmithBroyden diagonal entirely by setting
1915*7f296bb3SBarry Smith`-tao_bncg_mat_lmvm_sigma_hist 0`.
1916*7f296bb3SBarry Smith
1917*7f296bb3SBarry SmithOne can also supply their own preconditioner, serving as a Hessian
1918*7f296bb3SBarry Smithinitialization to the above diagonal scaling. The appropriate user
1919*7f296bb3SBarry Smithfunction in the code is `TaoBNCGSetH0(tao, H0)` where `H0` is the
1920*7f296bb3SBarry Smithuser-defined `Mat` object that serves as a preconditioner. For an
1921*7f296bb3SBarry Smithexample of similar usage, see `tao/tutorials/ex3.c`.
1922*7f296bb3SBarry Smith
1923*7f296bb3SBarry SmithThe active set estimation uses the Bertsekas-based method described in
1924*7f296bb3SBarry Smith{any}`sec_tao_bnk`, which can be deactivated using
1925*7f296bb3SBarry Smith`-tao_bncg_as_type none`, in which case the algorithm will use the
1926*7f296bb3SBarry Smithcurrent iterate to determine the bounded variables with no tolerances
1927*7f296bb3SBarry Smithand no look-ahead step. As in the BNK algorithm, the initial bound
1928*7f296bb3SBarry Smithtolerance and estimator step length used in the Bertsekas method can be
1929*7f296bb3SBarry Smithset via `-tao_bncg_as_tol` and `-tao_bncg_as_step`, respectively.
1930*7f296bb3SBarry Smith
1931*7f296bb3SBarry SmithIn addition to automatic scaled gradient descent restarts under certain
1932*7f296bb3SBarry Smithlocal curvature conditions, we also employ restarts based on a check on
1933*7f296bb3SBarry Smithdescent direction such that
1934*7f296bb3SBarry Smith$\nabla f(x_k)^T d_k \in [-10^{11}, -10^{-9}]$. Furthermore, we
1935*7f296bb3SBarry Smithallow for a variety of alternative restart strategies, all disabled by
1936*7f296bb3SBarry Smithdefault. The `-tao_bncg_unscaled_restart` flag allows one to disable
1937*7f296bb3SBarry Smithrescaling of the gradient for gradient descent steps. The
1938*7f296bb3SBarry Smith`-tao_bncg_spaced_restart` flag tells the solver to restart every
1939*7f296bb3SBarry Smith$Mn$ iterations, where $n$ is the problem dimension and
1940*7f296bb3SBarry Smith$M$ is a constant determined by `-tao_bncg_min_restart_num` and
1941*7f296bb3SBarry Smithis 6 by default. We also have dynamic restart strategies based on
1942*7f296bb3SBarry Smithchecking if a function is locally quadratic; if so, go do a gradient
1943*7f296bb3SBarry Smithdescent step. The flag is `-tao_bncg_dynamic_restart`, disabled by
1944*7f296bb3SBarry Smithdefault since the CG solver usually does better in those cases anyway.
1945*7f296bb3SBarry SmithThe minimum number of quadratic-like steps before a restart is set using
1946*7f296bb3SBarry Smith`-tao_bncg_min_quad` and is 6 by default.
1947*7f296bb3SBarry Smith
1948*7f296bb3SBarry Smith(sec_tao_constrained)=
1949*7f296bb3SBarry Smith
1950*7f296bb3SBarry Smith### Generally Constrained Solvers
1951*7f296bb3SBarry Smith
1952*7f296bb3SBarry SmithConstrained solvers solve optimization problems that incorporate either or both
1953*7f296bb3SBarry Smithequality and inequality constraints, and may optionally include bounds on
1954*7f296bb3SBarry Smithsolution variables.
1955*7f296bb3SBarry Smith
1956*7f296bb3SBarry Smith#### Alternating Direction Method of Multipliers (ADMM)
1957*7f296bb3SBarry Smith
1958*7f296bb3SBarry SmithThe TAOADMM algorithm is intended to blend the decomposability
1959*7f296bb3SBarry Smithof dual ascent with the superior convergence properties of the method of
1960*7f296bb3SBarry Smithmultipliers. {cite}`boyd` The algorithm solves problems in
1961*7f296bb3SBarry Smiththe form
1962*7f296bb3SBarry Smith
1963*7f296bb3SBarry Smith$$
1964*7f296bb3SBarry Smith\begin{array}{ll}
1965*7f296bb3SBarry Smith\displaystyle \min_{x} & f(x) + g(z) \\
1966*7f296bb3SBarry Smith\text{subject to} & Ax + Bz = c
1967*7f296bb3SBarry Smith\end{array}
1968*7f296bb3SBarry Smith$$
1969*7f296bb3SBarry Smith
1970*7f296bb3SBarry Smithwhere $x \in \mathbb R^n$, $z \in \mathbb R^m$,
1971*7f296bb3SBarry Smith$A \in \mathbb R^{p \times n}$,
1972*7f296bb3SBarry Smith$B \in \mathbb R^{p \times m}$, and $c \in \mathbb R^p$.
1973*7f296bb3SBarry SmithEssentially, ADMM is a wrapper over two TAO solver, one for
1974*7f296bb3SBarry Smith$f(x)$, and one for $g(z)$. With method of multipliers, one
1975*7f296bb3SBarry Smithcan form the augmented Lagrangian
1976*7f296bb3SBarry Smith
1977*7f296bb3SBarry Smith$$
1978*7f296bb3SBarry SmithL_{\rho}(x,z,y) = f(x) + g(z) + y^T(Ax+Bz-c) + (\rho/2)||Ax+Bz-c||_2^2
1979*7f296bb3SBarry Smith$$
1980*7f296bb3SBarry Smith
1981*7f296bb3SBarry SmithThen, ADMM consists of the iterations
1982*7f296bb3SBarry Smith
1983*7f296bb3SBarry Smith$$
1984*7f296bb3SBarry Smithx^{k+1} := \text{argmin}L_{\rho}(x,z^k,y^k)
1985*7f296bb3SBarry Smith$$
1986*7f296bb3SBarry Smith
1987*7f296bb3SBarry Smith$$
1988*7f296bb3SBarry Smithz^{k+1} := \text{argmin}L_{\rho}(x^{k+1},z,y^k)
1989*7f296bb3SBarry Smith$$
1990*7f296bb3SBarry Smith
1991*7f296bb3SBarry Smith$$
1992*7f296bb3SBarry Smithy^{k+1} := y^k + \rho(Ax^{k+1}+Bz^{k+1}-c)
1993*7f296bb3SBarry Smith$$
1994*7f296bb3SBarry Smith
1995*7f296bb3SBarry SmithIn certain formulation of ADMM, solution of $z^{k+1}$ may have
1996*7f296bb3SBarry Smithclosed-form solution. Currently ADMM provides one default implementation
1997*7f296bb3SBarry Smithfor $z^{k+1}$, which is soft-threshold. It can be used with either
1998*7f296bb3SBarry Smith`TaoADMMSetRegularizerType_ADMM()` or
1999*7f296bb3SBarry Smith`-tao_admm_regularizer_type <regularizer_soft_thresh>`. User can also
2000*7f296bb3SBarry Smithpass spectral penalty value, $\rho$, with either
2001*7f296bb3SBarry Smith`TaoADMMSetSpectralPenalty()` or `-tao_admm_spectral_penalty`.
2002*7f296bb3SBarry SmithCurrently, user can use
2003*7f296bb3SBarry Smith
2004*7f296bb3SBarry Smith- `TaoADMMSetMisfitObjectiveAndGradientRoutine()`
2005*7f296bb3SBarry Smith- `TaoADMMSetRegularizerObjectiveAndGradientRoutine()`
2006*7f296bb3SBarry Smith- `TaoADMMSetMisfitHessianRoutine()`
2007*7f296bb3SBarry Smith- `TaoADMMSetRegularizerHessianRoutine()`
2008*7f296bb3SBarry Smith
2009*7f296bb3SBarry SmithAny other combination of routines is currently not supported. Hessian
2010*7f296bb3SBarry Smithmatrices can either be constant or non-constant, of which fact can be
2011*7f296bb3SBarry Smithset via `TaoADMMSetMisfitHessianChangeStatus()`, and
2012*7f296bb3SBarry Smith`TaoADMMSetRegularizerHessianChangeStatus()`. Also, it may appear in
2013*7f296bb3SBarry Smithcertain cases where augmented Lagrangian’s Hessian may become nearly
2014*7f296bb3SBarry Smithsingular depending on the $\rho$, which may change in the case of
2015*7f296bb3SBarry Smith`-tao_admm_dual_update <update_adaptive>, <update_adaptive_relaxed>`.
2016*7f296bb3SBarry SmithThis issue can be prevented by `TaoADMMSetMinimumSpectralPenalty()`.
2017*7f296bb3SBarry Smith
2018*7f296bb3SBarry Smith#### Augmented Lagrangian Method of Multipliers (ALMM)
2019*7f296bb3SBarry Smith
2020*7f296bb3SBarry SmithThe TAOALMM method solves generally constrained problems of the form
2021*7f296bb3SBarry Smith
2022*7f296bb3SBarry Smith$$
2023*7f296bb3SBarry Smith\begin{array}{ll}
2024*7f296bb3SBarry Smith\displaystyle \min_{x} & f(x) \\
2025*7f296bb3SBarry Smith\text{subject to} & g(x) = 0\\
2026*7f296bb3SBarry Smith                  & h(x) \geq 0 \\
2027*7f296bb3SBarry Smith                  & l \leq x \leq u
2028*7f296bb3SBarry Smith\end{array}
2029*7f296bb3SBarry Smith$$
2030*7f296bb3SBarry Smith
2031*7f296bb3SBarry Smithwhere $g(x)$ are equality constraints, $h(x)$ are inequality
2032*7f296bb3SBarry Smithconstraints and $l$ and $u$ are lower and upper bounds on
2033*7f296bb3SBarry Smiththe optimization variables, respectively.
2034*7f296bb3SBarry Smith
2035*7f296bb3SBarry SmithTAOALMM converts the above general constrained problem into a sequence
2036*7f296bb3SBarry Smithof bound constrained problems at each outer iteration
2037*7f296bb3SBarry Smith$k = 1,2,\dots$
2038*7f296bb3SBarry Smith
2039*7f296bb3SBarry Smith$$
2040*7f296bb3SBarry Smith\begin{array}{ll}
2041*7f296bb3SBarry Smith\displaystyle \min_{x} & L(x, \lambda_k) \\
2042*7f296bb3SBarry Smith\text{subject to} & l \leq x \leq u
2043*7f296bb3SBarry Smith\end{array}
2044*7f296bb3SBarry Smith$$
2045*7f296bb3SBarry Smith
2046*7f296bb3SBarry Smithwhere $L(x, \lambda_k)$ is the augmented Lagrangian merit function
2047*7f296bb3SBarry Smithand $\lambda_k$ is the Lagrange multiplier estimates at outer
2048*7f296bb3SBarry Smithiteration $k$.
2049*7f296bb3SBarry Smith
2050*7f296bb3SBarry SmithTAOALMM offers two versions of the augmented Lagrangian formulation: the
2051*7f296bb3SBarry Smithcanonical Hestenes-Powell augmented
2052*7f296bb3SBarry SmithLagrangian {cite}`hestenes1969multiplier` {cite}`powell1969method`
2053*7f296bb3SBarry Smithwith inequality constrained converted to equality constraints via slack
2054*7f296bb3SBarry Smithvariables, and the slack-less Powell-Hestenes-Rockafellar
2055*7f296bb3SBarry Smithformulation {cite}`rockafellar1974augmented` that utilizes a
2056*7f296bb3SBarry Smithpointwise `max()` on the inequality constraints. For most
2057*7f296bb3SBarry Smithapplications, the canonical Hestenes-Powell formulation is likely to
2058*7f296bb3SBarry Smithperform better. However, the PHR formulation may be desirable for
2059*7f296bb3SBarry Smithproblems featuring very large numbers of inequality constraints as it
2060*7f296bb3SBarry Smithavoids inflating the dimension of the subproblem with slack variables.
2061*7f296bb3SBarry Smith
2062*7f296bb3SBarry SmithThe inner subproblem is solved using a nested bound-constrained
2063*7f296bb3SBarry Smithfirst-order TAO solver. By default, TAOALM uses a quasi-Newton-Krylov
2064*7f296bb3SBarry Smithtrust-region method (TAOBQNKTR). Other first-order methods such as
2065*7f296bb3SBarry SmithTAOBNCG and TAOBQNLS are also appropriate, but a trust-region
2066*7f296bb3SBarry Smithglobalization is strongly recommended for most applications.
2067*7f296bb3SBarry Smith
2068*7f296bb3SBarry Smith#### Primal-Dual Interior-Point Method (PDIPM)
2069*7f296bb3SBarry Smith
2070*7f296bb3SBarry SmithThe TAOPDIPM method (`-tao_type pdipm`) implements a primal-dual interior
2071*7f296bb3SBarry Smithpoint method for solving general nonlinear programming problems of the form
2072*7f296bb3SBarry Smith
2073*7f296bb3SBarry Smith$$
2074*7f296bb3SBarry Smith\begin{array}{ll}
2075*7f296bb3SBarry Smith\displaystyle \min_{x} & f(x) \\
2076*7f296bb3SBarry Smith\text{subject to} & g(x) = 0 \\
2077*7f296bb3SBarry Smith                  & h(x) \geq 0 \\
2078*7f296bb3SBarry Smith                  & x^- \leq x \leq x^+
2079*7f296bb3SBarry Smith\end{array}
2080*7f296bb3SBarry Smith$$ (eq_nlp_gen1)
2081*7f296bb3SBarry Smith
2082*7f296bb3SBarry SmithHere, $f(x)$ is the nonlinear objective function, $g(x)$,
2083*7f296bb3SBarry Smith$h(x)$ are the equality and inequality constraints, and
2084*7f296bb3SBarry Smith$x^-$ and $x^+$ are the lower and upper bounds on decision
2085*7f296bb3SBarry Smithvariables $x$.
2086*7f296bb3SBarry Smith
2087*7f296bb3SBarry SmithPDIPM converts the inequality constraints to equalities using slack variables
2088*7f296bb3SBarry Smith$z$ and a log-barrier term, which transforms {eq}`eq_nlp_gen1` to
2089*7f296bb3SBarry Smith
2090*7f296bb3SBarry Smith$$
2091*7f296bb3SBarry Smith\begin{aligned}
2092*7f296bb3SBarry Smith    \text{min}~&f(x) - \mu\sum_{i=1}^{nci}\ln z_i\\
2093*7f296bb3SBarry Smith    \text{s.t.}& \\
2094*7f296bb3SBarry Smith        &ce(x) = 0 \\
2095*7f296bb3SBarry Smith        &ci(x) - z = 0 \\
2096*7f296bb3SBarry Smith    \end{aligned}
2097*7f296bb3SBarry Smith$$ (eq_nlp_gen2)
2098*7f296bb3SBarry Smith
2099*7f296bb3SBarry SmithHere, $ce(x)$ is set of equality constraints that include
2100*7f296bb3SBarry Smith$g(x)$ and fixed decision variables, i.e., $x^- = x = x^+$.
2101*7f296bb3SBarry SmithSimilarly, $ci(x)$ are inequality constraints including
2102*7f296bb3SBarry Smith$h(x)$ and lower/upper/box-constraints on $x$. $\mu$
2103*7f296bb3SBarry Smithis a parameter that is driven to zero as the optimization progresses.
2104*7f296bb3SBarry Smith
2105*7f296bb3SBarry SmithThe Lagrangian for {eq}`eq_nlp_gen2`) is
2106*7f296bb3SBarry Smith
2107*7f296bb3SBarry Smith$$
2108*7f296bb3SBarry SmithL_{\mu}(x,\lambda_{ce},\lambda_{ci},z) = f(x) + \lambda_{ce}^Tce(x) - \lambda_{ci}^T(ci(x) - z) - \mu\sum_{i=1}^{nci}\ln z_i
2109*7f296bb3SBarry Smith$$ (eq_lagrangian)
2110*7f296bb3SBarry Smith
2111*7f296bb3SBarry Smithwhere, $\lambda_{ce}$ and $\lambda_{ci}$ are the Lagrangian
2112*7f296bb3SBarry Smithmultipliers for the equality and inequality constraints, respectively.
2113*7f296bb3SBarry Smith
2114*7f296bb3SBarry SmithThe first order KKT conditions for optimality are as follows
2115*7f296bb3SBarry Smith
2116*7f296bb3SBarry Smith$$
2117*7f296bb3SBarry Smith\nabla L_{\mu}(x,\lambda_{ce},\lambda_{ci},z)    =
2118*7f296bb3SBarry Smith    \begin{bmatrix}
2119*7f296bb3SBarry Smith        \nabla f(x) + \nabla ce(x)^T\lambda_{ce} -  \nabla ci(x)^T \lambda_{ci} \\
2120*7f296bb3SBarry Smith        ce(x) \\
2121*7f296bb3SBarry Smith        ci(x) - z \\
2122*7f296bb3SBarry Smith        Z\Lambda_{ci}e - \mu e
2123*7f296bb3SBarry Smith    \end{bmatrix}
2124*7f296bb3SBarry Smith= 0
2125*7f296bb3SBarry Smith$$ (eq_nlp_kkt)
2126*7f296bb3SBarry Smith
2127*7f296bb3SBarry Smith{eq}`eq_nlp_kkt` is solved iteratively using Newton’s
2128*7f296bb3SBarry Smithmethod using PETSc’s SNES object. After each Newton iteration, a
2129*7f296bb3SBarry Smithline-search is performed to update $x$ and enforce
2130*7f296bb3SBarry Smith$z,\lambda_{ci} \geq 0$. The barrier parameter $\mu$ is also
2131*7f296bb3SBarry Smithupdated after each Newton iteration. The Newton update is obtained by
2132*7f296bb3SBarry Smithsolving the second-order KKT system $Hd = -\nabla L_{\mu}$.
2133*7f296bb3SBarry SmithHere,$H$ is the Hessian matrix of the KKT system. For
2134*7f296bb3SBarry Smithinterior-point methods such as PDIPM, the Hessian matrix tends to be
2135*7f296bb3SBarry Smithill-conditioned, thus necessitating the use of a direct solver. We
2136*7f296bb3SBarry Smithrecommend using LU preconditioner `-pc_type lu` and using direct
2137*7f296bb3SBarry Smithlinear solver packages such `SuperLU_Dist` or `MUMPS`.
2138*7f296bb3SBarry Smith
2139*7f296bb3SBarry Smith### PDE-Constrained Optimization
2140*7f296bb3SBarry Smith
2141*7f296bb3SBarry SmithTAO solves PDE-constrained optimization problems of the form
2142*7f296bb3SBarry Smith
2143*7f296bb3SBarry Smith$$
2144*7f296bb3SBarry Smith\begin{array}{ll}
2145*7f296bb3SBarry Smith\displaystyle \min_{u,v} & f(u,v) \\
2146*7f296bb3SBarry Smith\text{subject to} & g(u,v) = 0,
2147*7f296bb3SBarry Smith\end{array}
2148*7f296bb3SBarry Smith$$
2149*7f296bb3SBarry Smith
2150*7f296bb3SBarry Smithwhere the state variable $u$ is the solution to the discretized
2151*7f296bb3SBarry Smithpartial differential equation defined by $g$ and parametrized by
2152*7f296bb3SBarry Smiththe design variable $v$, and $f$ is an objective function.
2153*7f296bb3SBarry SmithThe Lagrange multipliers on the constraint are denoted by $y$.
2154*7f296bb3SBarry SmithThis method is set by using the linearly constrained augmented
2155*7f296bb3SBarry SmithLagrangian TAO solver `tao_lcl`.
2156*7f296bb3SBarry Smith
2157*7f296bb3SBarry SmithWe make two main assumptions when solving these problems: the objective
2158*7f296bb3SBarry Smithfunction and PDE constraints have been discretized so that we can treat
2159*7f296bb3SBarry Smiththe optimization problem as finite dimensional and
2160*7f296bb3SBarry Smith$\nabla_u g(u,v)$ is invertible for all $u$ and $v$.
2161*7f296bb3SBarry Smith
2162*7f296bb3SBarry Smith(sec_tao_lcl)=
2163*7f296bb3SBarry Smith
2164*7f296bb3SBarry Smith#### Linearly-Constrained Augmented Lagrangian Method (LCL)
2165*7f296bb3SBarry Smith
2166*7f296bb3SBarry SmithGiven the current iterate $(u_k, v_k, y_k)$, the linearly
2167*7f296bb3SBarry Smithconstrained augmented Lagrangian method approximately solves the
2168*7f296bb3SBarry Smithoptimization problem
2169*7f296bb3SBarry Smith
2170*7f296bb3SBarry Smith$$
2171*7f296bb3SBarry Smith\begin{array}{ll}
2172*7f296bb3SBarry Smith\displaystyle \min_{u,v} & \tilde{f}_k(u, v) \\
2173*7f296bb3SBarry Smith\text{subject to} & A_k (u-u_k) + B_k (v-v_k) + g_k = 0,
2174*7f296bb3SBarry Smith\end{array}
2175*7f296bb3SBarry Smith$$
2176*7f296bb3SBarry Smith
2177*7f296bb3SBarry Smithwhere $A_k = \nabla_u g(u_k,v_k)$,
2178*7f296bb3SBarry Smith$B_k = \nabla_v g(u_k,v_k)$, and $g_k = g(u_k, v_k)$ and
2179*7f296bb3SBarry Smith
2180*7f296bb3SBarry Smith$$
2181*7f296bb3SBarry Smith\tilde{f}_k(u,v) = f(u,v) - g(u,v)^T y^k + \frac{\rho_k}{2} \| g(u,v) \|^2
2182*7f296bb3SBarry Smith$$
2183*7f296bb3SBarry Smith
2184*7f296bb3SBarry Smithis the augmented Lagrangian function. This optimization problem is
2185*7f296bb3SBarry Smithsolved in two stages. The first computes the Newton direction and finds
2186*7f296bb3SBarry Smitha feasible point for the linear constraints. The second computes a
2187*7f296bb3SBarry Smithreduced-space direction that maintains feasibility with respect to the
2188*7f296bb3SBarry Smithlinearized constraints and improves the augmented Lagrangian merit
2189*7f296bb3SBarry Smithfunction.
2190*7f296bb3SBarry Smith
2191*7f296bb3SBarry Smith##### Newton Step
2192*7f296bb3SBarry Smith
2193*7f296bb3SBarry SmithThe Newton direction is obtained by fixing the design variables at their
2194*7f296bb3SBarry Smithcurrent value and solving the linearized constraint for the state
2195*7f296bb3SBarry Smithvariables. In particular, we solve the system of equations
2196*7f296bb3SBarry Smith
2197*7f296bb3SBarry Smith$$
2198*7f296bb3SBarry SmithA_k du = -g_k
2199*7f296bb3SBarry Smith$$
2200*7f296bb3SBarry Smith
2201*7f296bb3SBarry Smithto obtain a direction $du$. We need a direction that provides
2202*7f296bb3SBarry Smithsufficient descent for the merit function
2203*7f296bb3SBarry Smith
2204*7f296bb3SBarry Smith$$
2205*7f296bb3SBarry Smith\frac{1}{2} \|g(u,v)\|^2.
2206*7f296bb3SBarry Smith$$
2207*7f296bb3SBarry Smith
2208*7f296bb3SBarry SmithThat is, we require $g_k^T A_k du < 0$.
2209*7f296bb3SBarry Smith
2210*7f296bb3SBarry SmithIf the Newton direction is a descent direction, then we choose a penalty
2211*7f296bb3SBarry Smithparameter $\rho_k$ so that $du$ is also a sufficient descent
2212*7f296bb3SBarry Smithdirection for the augmented Lagrangian merit function. We then find
2213*7f296bb3SBarry Smith$\alpha$ to approximately minimize the augmented Lagrangian merit
2214*7f296bb3SBarry Smithfunction along the Newton direction.
2215*7f296bb3SBarry Smith
2216*7f296bb3SBarry Smith$$
2217*7f296bb3SBarry Smith\displaystyle \min_{\alpha \geq 0} \; \tilde{f}_k(u_k + \alpha du, v_k).
2218*7f296bb3SBarry Smith$$
2219*7f296bb3SBarry Smith
2220*7f296bb3SBarry SmithWe can enforce either the sufficient decrease condition or the Wolfe
2221*7f296bb3SBarry Smithconditions during the search procedure. The new point,
2222*7f296bb3SBarry Smith
2223*7f296bb3SBarry Smith$$
2224*7f296bb3SBarry Smith\begin{array}{lcl}
2225*7f296bb3SBarry Smithu_{k+\frac{1}{2}} & = & u_k + \alpha_k du \\
2226*7f296bb3SBarry Smithv_{k+\frac{1}{2}} & = & v_k,
2227*7f296bb3SBarry Smith\end{array}
2228*7f296bb3SBarry Smith$$
2229*7f296bb3SBarry Smith
2230*7f296bb3SBarry Smithsatisfies the linear constraint
2231*7f296bb3SBarry Smith
2232*7f296bb3SBarry Smith$$
2233*7f296bb3SBarry SmithA_k (u_{k+\frac{1}{2}} - u_k) + B_k (v_{k+\frac{1}{2}} - v_k) + \alpha_k g_k = 0.
2234*7f296bb3SBarry Smith$$
2235*7f296bb3SBarry Smith
2236*7f296bb3SBarry SmithIf the Newton direction computed does not provide descent for the merit
2237*7f296bb3SBarry Smithfunction, then we can use the steepest descent direction
2238*7f296bb3SBarry Smith$du = -A_k^T g_k$ during the search procedure. However, the
2239*7f296bb3SBarry Smithimplication that the intermediate point approximately satisfies the
2240*7f296bb3SBarry Smithlinear constraint is no longer true.
2241*7f296bb3SBarry Smith
2242*7f296bb3SBarry Smith##### Modified Reduced-Space Step
2243*7f296bb3SBarry Smith
2244*7f296bb3SBarry SmithWe are now ready to compute a reduced-space step for the modified
2245*7f296bb3SBarry Smithoptimization problem:
2246*7f296bb3SBarry Smith
2247*7f296bb3SBarry Smith$$
2248*7f296bb3SBarry Smith\begin{array}{ll}
2249*7f296bb3SBarry Smith\displaystyle \min_{u,v} & \tilde{f}_k(u, v) \\
2250*7f296bb3SBarry Smith\text{subject to} & A_k (u-u_k) + B_k (v-v_k) + \alpha_k g_k = 0.
2251*7f296bb3SBarry Smith\end{array}
2252*7f296bb3SBarry Smith$$
2253*7f296bb3SBarry Smith
2254*7f296bb3SBarry SmithWe begin with the change of variables
2255*7f296bb3SBarry Smith
2256*7f296bb3SBarry Smith$$
2257*7f296bb3SBarry Smith\begin{array}{ll}
2258*7f296bb3SBarry Smith\displaystyle \min_{du,dv} & \tilde{f}_k(u_k+du, v_k+dv) \\
2259*7f296bb3SBarry Smith\text{subject to} & A_k du + B_k dv + \alpha_k g_k = 0
2260*7f296bb3SBarry Smith\end{array}
2261*7f296bb3SBarry Smith$$
2262*7f296bb3SBarry Smith
2263*7f296bb3SBarry Smithand make the substitution
2264*7f296bb3SBarry Smith
2265*7f296bb3SBarry Smith$$
2266*7f296bb3SBarry Smithdu = -A_k^{-1}(B_k dv + \alpha_k g_k).
2267*7f296bb3SBarry Smith$$
2268*7f296bb3SBarry Smith
2269*7f296bb3SBarry SmithHence, the unconstrained optimization problem we need to solve is
2270*7f296bb3SBarry Smith
2271*7f296bb3SBarry Smith$$
2272*7f296bb3SBarry Smith\begin{array}{ll}
2273*7f296bb3SBarry Smith\displaystyle \min_{dv} & \tilde{f}_k(u_k-A_k^{-1}(B_k dv + \alpha_k g_k), v_k+dv), \\
2274*7f296bb3SBarry Smith\end{array}
2275*7f296bb3SBarry Smith$$
2276*7f296bb3SBarry Smith
2277*7f296bb3SBarry Smithwhich is equivalent to
2278*7f296bb3SBarry Smith
2279*7f296bb3SBarry Smith$$
2280*7f296bb3SBarry Smith\begin{array}{ll}
2281*7f296bb3SBarry Smith\displaystyle \min_{dv} & \tilde{f}_k(u_{k+\frac{1}{2}} - A_k^{-1} B_k dv, v_{k+\frac{1}{2}}+dv). \\
2282*7f296bb3SBarry Smith\end{array}
2283*7f296bb3SBarry Smith$$
2284*7f296bb3SBarry Smith
2285*7f296bb3SBarry SmithWe apply one step of a limited-memory quasi-Newton method to this
2286*7f296bb3SBarry Smithproblem. The direction is obtain by solving the quadratic problem
2287*7f296bb3SBarry Smith
2288*7f296bb3SBarry Smith$$
2289*7f296bb3SBarry Smith\begin{array}{ll}
2290*7f296bb3SBarry Smith\displaystyle \min_{dv} & \frac{1}{2} dv^T \tilde{H}_k dv + \tilde{g}_{k+\frac{1}{2}}^T dv,
2291*7f296bb3SBarry Smith\end{array}
2292*7f296bb3SBarry Smith$$
2293*7f296bb3SBarry Smith
2294*7f296bb3SBarry Smithwhere $\tilde{H}_k$ is the limited-memory quasi-Newton
2295*7f296bb3SBarry Smithapproximation to the reduced Hessian matrix, a positive-definite matrix,
2296*7f296bb3SBarry Smithand $\tilde{g}_{k+\frac{1}{2}}$ is the reduced gradient.
2297*7f296bb3SBarry Smith
2298*7f296bb3SBarry Smith$$
2299*7f296bb3SBarry Smith\begin{array}{lcl}
2300*7f296bb3SBarry Smith\tilde{g}_{k+\frac{1}{2}} & = & \nabla_v \tilde{f}_k(u_{k+\frac{1}{2}}, v_{k+\frac{1}{2}}) -
2301*7f296bb3SBarry Smith          \nabla_u \tilde{f}_k(u_{k+\frac{1}{2}}, v_{k+\frac{1}{2}}) A_k^{-1} B_k \\
2302*7f296bb3SBarry Smith       & = & d_{k+\frac{1}{2}} + c_{k+\frac{1}{2}} A_k^{-1} B_k
2303*7f296bb3SBarry Smith\end{array}
2304*7f296bb3SBarry Smith$$
2305*7f296bb3SBarry Smith
2306*7f296bb3SBarry SmithThe reduced gradient is obtained from one linearized adjoint solve
2307*7f296bb3SBarry Smith
2308*7f296bb3SBarry Smith$$
2309*7f296bb3SBarry Smithy_{k+\frac{1}{2}} = A_k^{-T}c_{k+\frac{1}{2}}
2310*7f296bb3SBarry Smith$$
2311*7f296bb3SBarry Smith
2312*7f296bb3SBarry Smithand some linear algebra
2313*7f296bb3SBarry Smith
2314*7f296bb3SBarry Smith$$
2315*7f296bb3SBarry Smith\tilde{g}_{k+\frac{1}{2}} = d_{k+\frac{1}{2}} + y_{k+\frac{1}{2}}^T B_k.
2316*7f296bb3SBarry Smith$$
2317*7f296bb3SBarry Smith
2318*7f296bb3SBarry SmithBecause the Hessian approximation is positive definite and we know its
2319*7f296bb3SBarry Smithinverse, we obtain the direction
2320*7f296bb3SBarry Smith
2321*7f296bb3SBarry Smith$$
2322*7f296bb3SBarry Smithdv = -H_k^{-1} \tilde{g}_{k+\frac{1}{2}}
2323*7f296bb3SBarry Smith$$
2324*7f296bb3SBarry Smith
2325*7f296bb3SBarry Smithand recover the full-space direction from one linearized forward solve,
2326*7f296bb3SBarry Smith
2327*7f296bb3SBarry Smith$$
2328*7f296bb3SBarry Smithdu = -A_k^{-1} B_k dv.
2329*7f296bb3SBarry Smith$$
2330*7f296bb3SBarry Smith
2331*7f296bb3SBarry SmithHaving the full-space direction, which satisfies the linear constraint,
2332*7f296bb3SBarry Smithwe now approximately minimize the augmented Lagrangian merit function
2333*7f296bb3SBarry Smithalong the direction.
2334*7f296bb3SBarry Smith
2335*7f296bb3SBarry Smith$$
2336*7f296bb3SBarry Smith\begin{array}{lcl}
2337*7f296bb3SBarry Smith\displaystyle \min_{\beta \geq 0} & \tilde{f_k}(u_{k+\frac{1}{2}} + \beta du, v_{k+\frac{1}{2}} + \beta dv)
2338*7f296bb3SBarry Smith\end{array}
2339*7f296bb3SBarry Smith$$
2340*7f296bb3SBarry Smith
2341*7f296bb3SBarry SmithWe enforce the Wolfe conditions during the search procedure. The new
2342*7f296bb3SBarry Smithpoint is
2343*7f296bb3SBarry Smith
2344*7f296bb3SBarry Smith$$
2345*7f296bb3SBarry Smith\begin{array}{lcl}
2346*7f296bb3SBarry Smithu_{k+1} & = & u_{k+\frac{1}{2}} + \beta_k du \\
2347*7f296bb3SBarry Smithv_{k+1} & = & v_{k+\frac{1}{2}} + \beta_k dv.
2348*7f296bb3SBarry Smith\end{array}
2349*7f296bb3SBarry Smith$$
2350*7f296bb3SBarry Smith
2351*7f296bb3SBarry SmithThe reduced gradient at the new point is computed from
2352*7f296bb3SBarry Smith
2353*7f296bb3SBarry Smith$$
2354*7f296bb3SBarry Smith\begin{array}{lcl}
2355*7f296bb3SBarry Smithy_{k+1} & = & A_k^{-T}c_{k+1} \\
2356*7f296bb3SBarry Smith\tilde{g}_{k+1} & = & d_{k+1} - y_{k+1}^T B_k,
2357*7f296bb3SBarry Smith\end{array}
2358*7f296bb3SBarry Smith$$
2359*7f296bb3SBarry Smith
2360*7f296bb3SBarry Smithwhere $c_{k+1} = \nabla_u \tilde{f}_k (u_{k+1},v_{k+1})$ and
2361*7f296bb3SBarry Smith$d_{k+1} = \nabla_v \tilde{f}_k (u_{k+1},v_{k+1})$. The
2362*7f296bb3SBarry Smithmultipliers $y_{k+1}$ become the multipliers used in the next
2363*7f296bb3SBarry Smithiteration of the code. The quantities $v_{k+\frac{1}{2}}$,
2364*7f296bb3SBarry Smith$v_{k+1}$, $\tilde{g}_{k+\frac{1}{2}}$, and
2365*7f296bb3SBarry Smith$\tilde{g}_{k+1}$ are used to update $H_k$ to obtain the
2366*7f296bb3SBarry Smithlimited-memory quasi-Newton approximation to the reduced Hessian matrix
2367*7f296bb3SBarry Smithused in the next iteration of the code. The update is skipped if it
2368*7f296bb3SBarry Smithcannot be performed.
2369*7f296bb3SBarry Smith
2370*7f296bb3SBarry Smith(sec_tao_leastsquares)=
2371*7f296bb3SBarry Smith
2372*7f296bb3SBarry Smith### Nonlinear Least-Squares
2373*7f296bb3SBarry Smith
2374*7f296bb3SBarry SmithGiven a function $F: \mathbb R^n \to \mathbb R^m$, the nonlinear
2375*7f296bb3SBarry Smithleast-squares problem minimizes
2376*7f296bb3SBarry Smith
2377*7f296bb3SBarry Smith$$
2378*7f296bb3SBarry Smithf(x)= \| F(x) \|_2^2 = \sum_{i=1}^m F_i(x)^2.
2379*7f296bb3SBarry Smith$$ (eq_nlsf)
2380*7f296bb3SBarry Smith
2381*7f296bb3SBarry SmithThe nonlinear equations $F$ should be specified with the function
2382*7f296bb3SBarry Smith`TaoSetResidual()`.
2383*7f296bb3SBarry Smith
2384*7f296bb3SBarry Smith(sec_tao_pounders)=
2385*7f296bb3SBarry Smith
2386*7f296bb3SBarry Smith#### Bound-constrained Regularized Gauss-Newton (BRGN)
2387*7f296bb3SBarry Smith
2388*7f296bb3SBarry SmithThe TAOBRGN algorithms is a Gauss-Newton method is used to iteratively solve nonlinear least
2389*7f296bb3SBarry Smithsquares problem with the iterations
2390*7f296bb3SBarry Smith
2391*7f296bb3SBarry Smith$$
2392*7f296bb3SBarry Smithx_{k+1} = x_k - \alpha_k(J_k^T J_k)^{-1} J_k^T r(x_k)
2393*7f296bb3SBarry Smith$$
2394*7f296bb3SBarry Smith
2395*7f296bb3SBarry Smithwhere $r(x)$ is the least-squares residual vector,
2396*7f296bb3SBarry Smith$J_k = \partial r(x_k)/\partial x$ is the Jacobian of the
2397*7f296bb3SBarry Smithresidual, and $\alpha_k$ is the step length parameter. In other
2398*7f296bb3SBarry Smithwords, the Gauss-Newton method approximates the Hessian of the objective
2399*7f296bb3SBarry Smithas $H_k \approx (J_k^T J_k)$ and the gradient of the objective as
2400*7f296bb3SBarry Smith$g_k \approx -J_k r(x_k)$. The least-squares Jacobian, $J$,
2401*7f296bb3SBarry Smithshould be provided to Tao using `TaoSetJacobianResidual()` routine.
2402*7f296bb3SBarry Smith
2403*7f296bb3SBarry SmithThe BRGN (`-tao_type brgn`) implementation adds a regularization term $\beta(x)$ such
2404*7f296bb3SBarry Smiththat
2405*7f296bb3SBarry Smith
2406*7f296bb3SBarry Smith$$
2407*7f296bb3SBarry Smith\min_{x} \; \frac{1}{2}||R(x)||_2^2 + \lambda\beta(x),
2408*7f296bb3SBarry Smith$$
2409*7f296bb3SBarry Smith
2410*7f296bb3SBarry Smithwhere $\lambda$ is the scalar weight of the regularizer. BRGN
2411*7f296bb3SBarry Smithprovides two default implementations for $\beta(x)$:
2412*7f296bb3SBarry Smith
2413*7f296bb3SBarry Smith- **L2-norm** - $\beta(x) = \frac{1}{2}||x_k||_2^2$
2414*7f296bb3SBarry Smith- **L2-norm Proximal Point** -
2415*7f296bb3SBarry Smith  $\beta(x) = \frac{1}{2}||x_k - x_{k-1}||_2^2$
2416*7f296bb3SBarry Smith- **L1-norm with Dictionary** -
2417*7f296bb3SBarry Smith  $\beta(x) = ||Dx||_1 \approx \sum_{i} \sqrt{y_i^2 + \epsilon^2}-\epsilon$
2418*7f296bb3SBarry Smith  where $y = Dx$ and $\epsilon$ is the smooth approximation
2419*7f296bb3SBarry Smith  parameter.
2420*7f296bb3SBarry Smith
2421*7f296bb3SBarry SmithThe regularizer weight can be controlled with either
2422*7f296bb3SBarry Smith`TaoBRGNSetRegularizerWeight()` or `-tao_brgn_regularizer_weight`
2423*7f296bb3SBarry Smithcommand line option, while the smooth approximation parameter can be set
2424*7f296bb3SBarry Smithwith either `TaoBRGNSetL1SmoothEpsilon()` or
2425*7f296bb3SBarry Smith`-tao_brgn_l1_smooth_epsilon`. For the L1-norm term, the user can
2426*7f296bb3SBarry Smithsupply a dictionary matrix with `TaoBRGNSetDictionaryMatrix()`. If no
2427*7f296bb3SBarry Smithdictionary is provided, the dictionary is assumed to be an identity
2428*7f296bb3SBarry Smithmatrix and the regularizer reduces to a sparse solution term.
2429*7f296bb3SBarry Smith
2430*7f296bb3SBarry SmithThe regularization selection can be made using the command line option
2431*7f296bb3SBarry Smith`-tao_brgn_regularization_type <l2pure, l2prox, l1dict, user>` where the `user` option allows
2432*7f296bb3SBarry Smiththe user to define a custom $\mathcal{C}2$-continuous
2433*7f296bb3SBarry Smithregularization term. This custom term can be defined by using the
2434*7f296bb3SBarry Smithinterface functions:
2435*7f296bb3SBarry Smith
2436*7f296bb3SBarry Smith- `TaoBRGNSetRegularizerObjectiveAndGradientRoutine()` - Provide
2437*7f296bb3SBarry Smith  user-call back for evaluating the function value and gradient
2438*7f296bb3SBarry Smith  evaluation for the regularization term.
2439*7f296bb3SBarry Smith- `TaoBRGNSetRegularizerHessianRoutine()` - Provide user call-back
2440*7f296bb3SBarry Smith  for evaluating the Hessian of the regularization term.
2441*7f296bb3SBarry Smith
2442*7f296bb3SBarry Smith#### POUNDERS
2443*7f296bb3SBarry Smith
2444*7f296bb3SBarry SmithOne algorithm for solving the least squares problem
2445*7f296bb3SBarry Smith({eq}`eq_nlsf`) when the Jacobian of the residual vector
2446*7f296bb3SBarry Smith$F$ is unavailable is the model-based POUNDERS (Practical
2447*7f296bb3SBarry SmithOptimization Using No Derivatives for sums of Squares) algorithm
2448*7f296bb3SBarry Smith(`tao_pounders`). POUNDERS employs a derivative-free trust-region
2449*7f296bb3SBarry Smithframework as described in {cite}`dfobook` in order to
2450*7f296bb3SBarry Smithconverge to local minimizers. An example of this version of POUNDERS
2451*7f296bb3SBarry Smithapplied to a practical least-squares problem can be found in
2452*7f296bb3SBarry Smith{cite}`unedf0`.
2453*7f296bb3SBarry Smith
2454*7f296bb3SBarry Smith##### Derivative-Free Trust-Region Algorithm
2455*7f296bb3SBarry Smith
2456*7f296bb3SBarry SmithIn each iteration $k$, the algorithm maintains a model
2457*7f296bb3SBarry Smith$m_k(x)$, described below, of the nonlinear least squares function
2458*7f296bb3SBarry Smith$f$ centered about the current iterate $x_k$.
2459*7f296bb3SBarry Smith
2460*7f296bb3SBarry SmithIf one assumes that the maximum number of function evaluations has not
2461*7f296bb3SBarry Smithbeen reached and that $\|\nabla m_k(x_k)\|_2>$`gtol`, the next
2462*7f296bb3SBarry Smithpoint $x_+$ to be evaluated is obtained by solving the
2463*7f296bb3SBarry Smithtrust-region subproblem
2464*7f296bb3SBarry Smith
2465*7f296bb3SBarry Smith$$
2466*7f296bb3SBarry Smith\min\left\{
2467*7f296bb3SBarry Smith m_k(x) :
2468*7f296bb3SBarry Smith \|x-x_k\|_{p} \leq \Delta_k,
2469*7f296bb3SBarry Smith \right \},
2470*7f296bb3SBarry Smith$$ (eq_poundersp)
2471*7f296bb3SBarry Smith
2472*7f296bb3SBarry Smithwhere $\Delta_k$ is the current trust-region radius. By default we
2473*7f296bb3SBarry Smithuse a trust-region norm with $p=\infty$ and solve
2474*7f296bb3SBarry Smith({eq}`eq_poundersp`) with the BLMVM method described in
2475*7f296bb3SBarry Smith{any}`sec_tao_blmvm`. While the subproblem is a
2476*7f296bb3SBarry Smithbound-constrained quadratic program, it may not be convex and the BQPIP
2477*7f296bb3SBarry Smithand GPCG methods may not solve the subproblem. Therefore, a bounded
2478*7f296bb3SBarry SmithNewton-Krylov Method should be used; the default is the BNTR
2479*7f296bb3SBarry Smithalgorithm. Note: BNTR uses its own internal
2480*7f296bb3SBarry Smithtrust region that may interfere with the infinity-norm trust region used
2481*7f296bb3SBarry Smithin the model problem ({eq}`eq_poundersp`).
2482*7f296bb3SBarry Smith
2483*7f296bb3SBarry SmithThe residual vector is then evaluated to obtain $F(x_+)$ and hence
2484*7f296bb3SBarry Smith$f(x_+)$. The ratio of actual decrease to predicted decrease,
2485*7f296bb3SBarry Smith
2486*7f296bb3SBarry Smith$$
2487*7f296bb3SBarry Smith\rho_k = \frac{f(x_k)-f(x_+)}{m_k(x_k)-m_k(x_+)},
2488*7f296bb3SBarry Smith$$
2489*7f296bb3SBarry Smith
2490*7f296bb3SBarry Smithas well as an indicator, `valid`, on the model’s quality of
2491*7f296bb3SBarry Smithapproximation on the trust region is then used to update the iterate,
2492*7f296bb3SBarry Smith
2493*7f296bb3SBarry Smith$$
2494*7f296bb3SBarry Smithx_{k+1} = \left\{\begin{array}{ll}
2495*7f296bb3SBarry Smithx_+ & \text{if } \rho_k \geq \eta_1 \\
2496*7f296bb3SBarry Smithx_+ & \text{if } 0<\rho_k <\eta_1  \text{ and \texttt{valid}=\texttt{true}}
2497*7f296bb3SBarry Smith\\
2498*7f296bb3SBarry Smithx_k & \text{else},
2499*7f296bb3SBarry Smith\end{array}
2500*7f296bb3SBarry Smith\right.
2501*7f296bb3SBarry Smith$$
2502*7f296bb3SBarry Smith
2503*7f296bb3SBarry Smithand trust-region radius,
2504*7f296bb3SBarry Smith
2505*7f296bb3SBarry Smith$$
2506*7f296bb3SBarry Smith\Delta_{k+1} = \left\{\begin{array}{ll}
2507*7f296bb3SBarry Smith \text{min}(\gamma_1\Delta_k, \Delta_{\max}) & \text{if } \rho_k \geq
2508*7f296bb3SBarry Smith\eta_1 \text{ and } \|x_+-x_k\|_p\geq \omega_1\Delta_k \\
2509*7f296bb3SBarry Smith\gamma_0\Delta_k & \text{if } \rho_k < \eta_1 \text{ and
2510*7f296bb3SBarry Smith\texttt{valid}=\texttt{true}} \\
2511*7f296bb3SBarry Smith\Delta_k &  \text{else,}
2512*7f296bb3SBarry Smith\end{array}
2513*7f296bb3SBarry Smith\right.
2514*7f296bb3SBarry Smith$$
2515*7f296bb3SBarry Smith
2516*7f296bb3SBarry Smithwhere $0 < \eta_1 < 1$, $0 < \gamma_0 < 1 < \gamma_1$,
2517*7f296bb3SBarry Smith$0<\omega_1<1$, and $\Delta_{\max}$ are constants.
2518*7f296bb3SBarry Smith
2519*7f296bb3SBarry SmithIf $\rho_k\leq 0$ and `valid` is `false`, the iterate and
2520*7f296bb3SBarry Smithtrust-region radius remain unchanged after the above updates, and the
2521*7f296bb3SBarry Smithalgorithm tests whether the direction $x_+-x_k$ improves the
2522*7f296bb3SBarry Smithmodel. If not, the algorithm performs an additional evaluation to obtain
2523*7f296bb3SBarry Smith$F(x_k+d_k)$, where $d_k$ is a model-improving direction.
2524*7f296bb3SBarry Smith
2525*7f296bb3SBarry SmithThe iteration counter is then updated, and the next model $m_{k}$
2526*7f296bb3SBarry Smithis obtained as described next.
2527*7f296bb3SBarry Smith
2528*7f296bb3SBarry Smith##### Forming the Trust-Region Model
2529*7f296bb3SBarry Smith
2530*7f296bb3SBarry SmithIn each iteration, POUNDERS uses a subset of the available evaluated
2531*7f296bb3SBarry Smithresidual vectors $\{ F(y_1), F(y_2), \cdots \}$ to form an
2532*7f296bb3SBarry Smithinterpolatory quadratic model of each residual component. The $m$
2533*7f296bb3SBarry Smithquadratic models
2534*7f296bb3SBarry Smith
2535*7f296bb3SBarry Smith$$
2536*7f296bb3SBarry Smithq_k^{(i)}(x) =
2537*7f296bb3SBarry Smith F_i(x_k) + (x-x_k)^T g_k^{(i)} + \frac{1}{2} (x-x_k)^T H_k^{(i)} (x-x_k),
2538*7f296bb3SBarry Smith \qquad i = 1, \ldots, m
2539*7f296bb3SBarry Smith$$ (eq_models)
2540*7f296bb3SBarry Smith
2541*7f296bb3SBarry Smiththus satisfy the interpolation conditions
2542*7f296bb3SBarry Smith
2543*7f296bb3SBarry Smith$$
2544*7f296bb3SBarry Smithq_k^{(i)}(y_j) = F_i(y_j), \qquad i=1, \ldots, m; \, j=1,\ldots , l_k
2545*7f296bb3SBarry Smith$$
2546*7f296bb3SBarry Smith
2547*7f296bb3SBarry Smithon a common interpolation set $\{y_1, \cdots , y_{l_k}\}$ of size
2548*7f296bb3SBarry Smith$l_k\in[n+1,$`npmax`$]$.
2549*7f296bb3SBarry Smith
2550*7f296bb3SBarry SmithThe gradients and Hessians of the models in
2551*7f296bb3SBarry Smith{any}`eq_models` are then used to construct the main
2552*7f296bb3SBarry Smithmodel,
2553*7f296bb3SBarry Smith
2554*7f296bb3SBarry Smith$$
2555*7f296bb3SBarry Smithm_k(x) = f(x_k) +
2556*7f296bb3SBarry Smith$$ (eq_newton2)
2557*7f296bb3SBarry Smith
2558*7f296bb3SBarry Smith$$
2559*7f296bb3SBarry Smith2(x-x_k)^T \sum_{i=1}^{m} F_i(x_k) g_k^{(i)} + (x-x_k)^T \sum_{i=1}^{m} \left( g_k^{(i)} \left(g_k^{(i)}\right)^T +  F_i(x_k) H_k^{(i)}\right) (x-x_k).
2560*7f296bb3SBarry Smith$$
2561*7f296bb3SBarry Smith
2562*7f296bb3SBarry SmithThe process of forming these models also computes the indicator
2563*7f296bb3SBarry Smith`valid` of the model’s local quality.
2564*7f296bb3SBarry Smith
2565*7f296bb3SBarry Smith##### Parameters
2566*7f296bb3SBarry Smith
2567*7f296bb3SBarry SmithPOUNDERS supports the following parameters that can be set from the
2568*7f296bb3SBarry Smithcommand line or PETSc options file:
2569*7f296bb3SBarry Smith
2570*7f296bb3SBarry Smith`-tao_pounders_delta <delta>`
2571*7f296bb3SBarry Smith
2572*7f296bb3SBarry Smith: The initial trust-region radius ($>0$, real). This is used to
2573*7f296bb3SBarry Smith  determine the size of the initial neighborhood within which the
2574*7f296bb3SBarry Smith  algorithm should look.
2575*7f296bb3SBarry Smith
2576*7f296bb3SBarry Smith`-tao_pounders_npmax <npmax>`
2577*7f296bb3SBarry Smith
2578*7f296bb3SBarry Smith: The maximum number of interpolation points used ($n+2\leq$
2579*7f296bb3SBarry Smith  `npmax` $\leq 0.5(n+1)(n+2)$). This input is made available
2580*7f296bb3SBarry Smith  to advanced users. We recommend the default value
2581*7f296bb3SBarry Smith  (`npmax`$=2n+1$) be used by others.
2582*7f296bb3SBarry Smith
2583*7f296bb3SBarry Smith`-tao_pounders_gqt`
2584*7f296bb3SBarry Smith
2585*7f296bb3SBarry Smith: Use the gqt algorithm to solve the
2586*7f296bb3SBarry Smith  subproblem ({eq}`eq_poundersp`) (uses $p=2$)
2587*7f296bb3SBarry Smith  instead of BQPIP.
2588*7f296bb3SBarry Smith
2589*7f296bb3SBarry Smith`-pounders_subsolver`
2590*7f296bb3SBarry Smith
2591*7f296bb3SBarry Smith: If the default BQPIP algorithm is used to solve the
2592*7f296bb3SBarry Smith  subproblem ({eq}`eq_poundersp`), the parameters of
2593*7f296bb3SBarry Smith  the subproblem solver can be accessed using the command line options
2594*7f296bb3SBarry Smith  prefix `-pounders_subsolver_`. For example,
2595*7f296bb3SBarry Smith
2596*7f296bb3SBarry Smith  ```
2597*7f296bb3SBarry Smith  -pounders_subsolver_tao_gatol 1.0e-5
2598*7f296bb3SBarry Smith  ```
2599*7f296bb3SBarry Smith
2600*7f296bb3SBarry Smith  sets the gradient tolerance of the subproblem solver to
2601*7f296bb3SBarry Smith  $10^{-5}$.
2602*7f296bb3SBarry Smith
2603*7f296bb3SBarry SmithAdditionally, the user provides an initial solution vector, a vector for
2604*7f296bb3SBarry Smithstoring the separable objective function, and a routine for evaluating
2605*7f296bb3SBarry Smiththe residual vector $F$. These are described in detail in
2606*7f296bb3SBarry Smith{any}`sec_tao_fghj` and
2607*7f296bb3SBarry Smith{any}`sec_tao_evalsof`. Here we remark that because gradient
2608*7f296bb3SBarry Smithinformation is not available for scaling purposes, it can be useful to
2609*7f296bb3SBarry Smithensure that the problem is reasonably well scaled. A simple way to do so
2610*7f296bb3SBarry Smithis to rescale the decision variables $x$ so that their typical
2611*7f296bb3SBarry Smithvalues are expected to lie within the unit hypercube $[0,1]^n$.
2612*7f296bb3SBarry Smith
2613*7f296bb3SBarry Smith##### Convergence Notes
2614*7f296bb3SBarry Smith
2615*7f296bb3SBarry SmithBecause the gradient function is not provided to POUNDERS, the norm of
2616*7f296bb3SBarry Smiththe gradient of the objective function is not available. Therefore, for
2617*7f296bb3SBarry Smithconvergence criteria, this norm is approximated by the norm of the model
2618*7f296bb3SBarry Smithgradient and used only when the model gradient is deemed to be a
2619*7f296bb3SBarry Smithreasonable approximation of the gradient of the objective. In practice,
2620*7f296bb3SBarry Smiththe typical grounds for termination for expensive derivative-free
2621*7f296bb3SBarry Smithproblems is the maximum number of function evaluations allowed.
2622*7f296bb3SBarry Smith
2623*7f296bb3SBarry Smith(sec_tao_complementarity)=
2624*7f296bb3SBarry Smith
2625*7f296bb3SBarry Smith### Complementarity
2626*7f296bb3SBarry Smith
2627*7f296bb3SBarry SmithMixed complementarity problems, or box-constrained variational
2628*7f296bb3SBarry Smithinequalities, are related to nonlinear systems of equations. They are
2629*7f296bb3SBarry Smithdefined by a continuously differentiable function,
2630*7f296bb3SBarry Smith$F:\mathbb R^n \to \mathbb R^n$, and bounds,
2631*7f296bb3SBarry Smith$\ell \in \{\mathbb R\cup \{-\infty\}\}^n$ and
2632*7f296bb3SBarry Smith$u \in \{\mathbb R\cup \{\infty\}\}^n$, on the variables such that
2633*7f296bb3SBarry Smith$\ell \leq u$. Given this information,
2634*7f296bb3SBarry Smith$\mathbf{x}^* \in [\ell,u]$ is a solution to
2635*7f296bb3SBarry SmithMCP($F$, $\ell$, $u$) if for each
2636*7f296bb3SBarry Smith$i \in \{1, \ldots, n\}$ we have at least one of the following:
2637*7f296bb3SBarry Smith
2638*7f296bb3SBarry Smith$$
2639*7f296bb3SBarry Smith\begin{aligned}
2640*7f296bb3SBarry Smith\begin{array}{ll}
2641*7f296bb3SBarry SmithF_i(x^*) \geq 0 & \text{if } x^*_i = \ell_i \\
2642*7f296bb3SBarry SmithF_i(x^*) = 0 & \text{if } \ell_i < x^*_i < u_i \\
2643*7f296bb3SBarry SmithF_i(x^*) \leq 0 & \text{if } x^*_i = u_i.
2644*7f296bb3SBarry Smith\end{array}\end{aligned}
2645*7f296bb3SBarry Smith$$
2646*7f296bb3SBarry Smith
2647*7f296bb3SBarry SmithNote that when $\ell = \{-\infty\}^n$ and
2648*7f296bb3SBarry Smith$u = \{\infty\}^n$, we have a nonlinear system of equations, and
2649*7f296bb3SBarry Smith$\ell = \{0\}^n$ and $u = \{\infty\}^n$ correspond to the
2650*7f296bb3SBarry Smithnonlinear complementarity problem {cite}`cottle:nonlinear`.
2651*7f296bb3SBarry Smith
2652*7f296bb3SBarry SmithSimple complementarity conditions arise from the first-order optimality
2653*7f296bb3SBarry Smithconditions from optimization
2654*7f296bb3SBarry Smith{cite}`karush:minima` {cite}`kuhn.tucker:nonlinear`. In the simple
2655*7f296bb3SBarry Smithbound-constrained optimization case, these conditions correspond to
2656*7f296bb3SBarry SmithMCP($\nabla f$, $\ell$, $u$), where
2657*7f296bb3SBarry Smith$f: \mathbb R^n \to \mathbb R$ is the objective function. In a
2658*7f296bb3SBarry Smithone-dimensional setting these conditions are intuitive. If the solution
2659*7f296bb3SBarry Smithis at the lower bound, then the function must be increasing and
2660*7f296bb3SBarry Smith$\nabla f \geq 0$. If the solution is at the upper bound, then the
2661*7f296bb3SBarry Smithfunction must be decreasing and $\nabla f \leq 0$. If the solution
2662*7f296bb3SBarry Smithis strictly between the bounds, we must be at a stationary point and
2663*7f296bb3SBarry Smith$\nabla f = 0$. Other complementarity problems arise in economics
2664*7f296bb3SBarry Smithand engineering {cite}`ferris.pang:engineering`, game theory
2665*7f296bb3SBarry Smith{cite}`nash:equilibrium`, and finance
2666*7f296bb3SBarry Smith{cite}`huang.pang:option`.
2667*7f296bb3SBarry Smith
2668*7f296bb3SBarry SmithEvaluation routines for $F$ and its Jacobian must be supplied
2669*7f296bb3SBarry Smithprior to solving the application. The bounds, $[\ell,u]$, on the
2670*7f296bb3SBarry Smithvariables must also be provided. If no starting point is supplied, a
2671*7f296bb3SBarry Smithdefault starting point of all zeros is used.
2672*7f296bb3SBarry Smith
2673*7f296bb3SBarry Smith#### Semismooth Methods
2674*7f296bb3SBarry Smith
2675*7f296bb3SBarry SmithTAO has two implementations of semismooth algorithms
2676*7f296bb3SBarry Smith{cite}`munson.facchinei.ea:semismooth` {cite}`deluca.facchinei.ea:semismooth`
2677*7f296bb3SBarry Smith{cite}`facchinei.fischer.ea:semismooth` for solving mixed complementarity
2678*7f296bb3SBarry Smithproblems. Both are based on a reformulation of the mixed complementarity
2679*7f296bb3SBarry Smithproblem as a nonsmooth system of equations using the Fischer-Burmeister
2680*7f296bb3SBarry Smithfunction {cite}`fischer:special`. A nonsmooth Newton method
2681*7f296bb3SBarry Smithis applied to the reformulated system to calculate a solution. The
2682*7f296bb3SBarry Smiththeoretical properties of such methods are detailed in the
2683*7f296bb3SBarry Smithaforementioned references.
2684*7f296bb3SBarry Smith
2685*7f296bb3SBarry SmithThe Fischer-Burmeister function, $\phi:\mathbb R^2 \to \mathbb R$,
2686*7f296bb3SBarry Smithis defined as
2687*7f296bb3SBarry Smith
2688*7f296bb3SBarry Smith$$
2689*7f296bb3SBarry Smith\begin{aligned}
2690*7f296bb3SBarry Smith\phi(a,b) := \sqrt{a^2 + b^2} - a - b.\end{aligned}
2691*7f296bb3SBarry Smith$$
2692*7f296bb3SBarry Smith
2693*7f296bb3SBarry SmithThis function has the following key property,
2694*7f296bb3SBarry Smith
2695*7f296bb3SBarry Smith$$
2696*7f296bb3SBarry Smith\begin{aligned}
2697*7f296bb3SBarry Smith\begin{array}{lcr}
2698*7f296bb3SBarry Smith        \phi(a,b) = 0 & \Leftrightarrow & a \geq 0,\; b \geq 0,\; ab = 0,
2699*7f296bb3SBarry Smith\end{array}\end{aligned}
2700*7f296bb3SBarry Smith$$
2701*7f296bb3SBarry Smith
2702*7f296bb3SBarry Smithused when reformulating the mixed complementarity problem as the system
2703*7f296bb3SBarry Smithof equations $\Phi(x) = 0$, where
2704*7f296bb3SBarry Smith$\Phi:\mathbb R^n \to \mathbb R^n$. The reformulation is defined
2705*7f296bb3SBarry Smithcomponentwise as
2706*7f296bb3SBarry Smith
2707*7f296bb3SBarry Smith$$
2708*7f296bb3SBarry Smith\begin{aligned}
2709*7f296bb3SBarry Smith\Phi_i(x) := \left\{ \begin{array}{ll}
2710*7f296bb3SBarry Smith   \phi(x_i - l_i, F_i(x)) & \text{if } -\infty < l_i < u_i = \infty, \\
2711*7f296bb3SBarry Smith   -\phi(u_i-x_i, -F_i(x)) & \text{if } -\infty = l_i < u_i < \infty, \\
2712*7f296bb3SBarry Smith   \phi(x_i - l_i, \phi(u_i - x_i, - F_i(x))) & \text{if } -\infty < l_i < u_i < \infty, \\
2713*7f296bb3SBarry Smith   -F_i(x) & \text{if } -\infty = l_i < u_i = \infty, \\
2714*7f296bb3SBarry Smith   l_i - x_i & \text{if } -\infty < l_i = u_i < \infty.
2715*7f296bb3SBarry Smith   \end{array} \right.\end{aligned}
2716*7f296bb3SBarry Smith$$
2717*7f296bb3SBarry Smith
2718*7f296bb3SBarry SmithWe note that $\Phi$ is not differentiable everywhere but satisfies
2719*7f296bb3SBarry Smitha semismoothness property
2720*7f296bb3SBarry Smith{cite}`mifflin:semismooth` {cite}`qi:convergence` {cite}`qi.sun:nonsmooth`.
2721*7f296bb3SBarry SmithFurthermore, the natural merit function,
2722*7f296bb3SBarry Smith$\Psi(x) := \frac{1}{2} \| \Phi(x) \|_2^2$, is continuously
2723*7f296bb3SBarry Smithdifferentiable.
2724*7f296bb3SBarry Smith
2725*7f296bb3SBarry SmithThe two semismooth TAO solvers both solve the system $\Phi(x) = 0$
2726*7f296bb3SBarry Smithby applying a nonsmooth Newton method with a line search. We calculate a
2727*7f296bb3SBarry Smithdirection, $d^k$, by solving the system
2728*7f296bb3SBarry Smith$H^kd^k = -\Phi(x^k)$, where $H^k$ is an element of the
2729*7f296bb3SBarry Smith$B$-subdifferential {cite}`qi.sun:nonsmooth` of
2730*7f296bb3SBarry Smith$\Phi$ at $x^k$. If the direction calculated does not
2731*7f296bb3SBarry Smithsatisfy a suitable descent condition, then we use the negative gradient
2732*7f296bb3SBarry Smithof the merit function, $-\nabla \Psi(x^k)$, as the search
2733*7f296bb3SBarry Smithdirection. A standard Armijo search
2734*7f296bb3SBarry Smith{cite}`armijo:minimization` is used to find the new
2735*7f296bb3SBarry Smithiteration. Nonmonotone searches
2736*7f296bb3SBarry Smith{cite}`grippo.lampariello.ea:nonmonotone` are also available
2737*7f296bb3SBarry Smithby setting appropriate runtime options. See
2738*7f296bb3SBarry Smith{any}`sec_tao_linesearch` for further details.
2739*7f296bb3SBarry Smith
2740*7f296bb3SBarry SmithThe first semismooth algorithm available in TAO is not guaranteed to
2741*7f296bb3SBarry Smithremain feasible with respect to the bounds, $[\ell, u]$, and is
2742*7f296bb3SBarry Smithtermed an infeasible semismooth method. This method can be specified by
2743*7f296bb3SBarry Smithusing the `tao_ssils` solver. In this case, the descent test used is
2744*7f296bb3SBarry Smiththat
2745*7f296bb3SBarry Smith
2746*7f296bb3SBarry Smith$$
2747*7f296bb3SBarry Smith\begin{aligned}
2748*7f296bb3SBarry Smith\nabla \Psi(x^k)^Td^k \leq -\delta\| d^k \|^\rho.\end{aligned}
2749*7f296bb3SBarry Smith$$
2750*7f296bb3SBarry Smith
2751*7f296bb3SBarry SmithBoth $\delta > 0$ and $\rho > 2$ can be modified by using
2752*7f296bb3SBarry Smiththe runtime options `-tao_ssils_delta <delta>` and
2753*7f296bb3SBarry Smith`-tao_ssils_rho <rho>`, respectively. By default,
2754*7f296bb3SBarry Smith$\delta = 10^{-10}$ and $\rho = 2.1$.
2755*7f296bb3SBarry Smith
2756*7f296bb3SBarry SmithAn alternative is to remain feasible with respect to the bounds by using
2757*7f296bb3SBarry Smitha projected Armijo line search. This method can be specified by using
2758*7f296bb3SBarry Smiththe `tao_ssfls` solver. The descent test used is the same as above
2759*7f296bb3SBarry Smithwhere the direction in this case corresponds to the first part of the
2760*7f296bb3SBarry Smithpiecewise linear arc searched by the projected line search. Both
2761*7f296bb3SBarry Smith$\delta > 0$ and $\rho > 2$ can be modified by using the
2762*7f296bb3SBarry Smithruntime options `-tao_ssfls_delta <delta>` and
2763*7f296bb3SBarry Smith`-tao_ssfls_rho <rho>` respectively. By default,
2764*7f296bb3SBarry Smith$\delta = 10^{-10}$ and $\rho = 2.1$.
2765*7f296bb3SBarry Smith
2766*7f296bb3SBarry SmithThe recommended algorithm is the infeasible semismooth method,
2767*7f296bb3SBarry Smith`tao_ssils`, because of its strong global and local convergence
2768*7f296bb3SBarry Smithproperties. However, if it is known that $F$ is not defined
2769*7f296bb3SBarry Smithoutside of the box, $[\ell,u]$, perhaps because of the presence of
2770*7f296bb3SBarry Smith$\log$ functions, the feasibility-enforcing version of the
2771*7f296bb3SBarry Smithalgorithm, `tao_ssfls`, is a reasonable alternative.
2772*7f296bb3SBarry Smith
2773*7f296bb3SBarry Smith#### Active-Set Methods
2774*7f296bb3SBarry Smith
2775*7f296bb3SBarry SmithTAO also contained two active-set semismooth methods for solving
2776*7f296bb3SBarry Smithcomplementarity problems. These methods solve a reduced system
2777*7f296bb3SBarry Smithconstructed by block elimination of active constraints. The
2778*7f296bb3SBarry Smithsubdifferential in these cases enables this block elimination.
2779*7f296bb3SBarry Smith
2780*7f296bb3SBarry SmithThe first active-set semismooth algorithm available in TAO is not guaranteed to
2781*7f296bb3SBarry Smithremain feasible with respect to the bounds, $[\ell, u]$, and is
2782*7f296bb3SBarry Smithtermed an infeasible active-set semismooth method. This method can be
2783*7f296bb3SBarry Smithspecified by using the `tao_asils` solver.
2784*7f296bb3SBarry Smith
2785*7f296bb3SBarry SmithAn alternative is to remain feasible with respect to the bounds by using
2786*7f296bb3SBarry Smitha projected Armijo line search. This method can be specified by using
2787*7f296bb3SBarry Smiththe `tao_asfls` solver.
2788*7f296bb3SBarry Smith
2789*7f296bb3SBarry Smith(sec_tao_quadratic)=
2790*7f296bb3SBarry Smith
2791*7f296bb3SBarry Smith### Quadratic Solvers
2792*7f296bb3SBarry Smith
2793*7f296bb3SBarry SmithQuadratic solvers solve optimization problems of the form
2794*7f296bb3SBarry Smith
2795*7f296bb3SBarry Smith$$
2796*7f296bb3SBarry Smith\begin{array}{ll}
2797*7f296bb3SBarry Smith\displaystyle \min_{x} & \frac{1}{2}x^T Q x + c^T x \\
2798*7f296bb3SBarry Smith\text{subject to} & l \geq x \geq u
2799*7f296bb3SBarry Smith\end{array}
2800*7f296bb3SBarry Smith$$
2801*7f296bb3SBarry Smith
2802*7f296bb3SBarry Smithwhere the gradient and the Hessian of the objective are both constant.
2803*7f296bb3SBarry Smith
2804*7f296bb3SBarry Smith#### Gradient Projection Conjugate Gradient Method (GPCG)
2805*7f296bb3SBarry Smith
2806*7f296bb3SBarry SmithThe GPCG {cite}`more-toraldo` algorithm is much like the
2807*7f296bb3SBarry SmithTRON algorithm, discussed in Section {any}`sec_tao_tron`, except that
2808*7f296bb3SBarry Smithit assumes that the objective function is quadratic and convex.
2809*7f296bb3SBarry SmithTherefore, it evaluates the function, gradient, and Hessian only once.
2810*7f296bb3SBarry SmithSince the objective function is quadratic, the algorithm does not use a
2811*7f296bb3SBarry Smithtrust region. All the options that apply to TRON except for trust-region
2812*7f296bb3SBarry Smithoptions also apply to GPCG. It can be set by using the TAO solver
2813*7f296bb3SBarry Smith`tao_gpcg` or via the optio flag `-tao_type gpcg`.
2814*7f296bb3SBarry Smith
2815*7f296bb3SBarry Smith(sec_tao_bqpip)=
2816*7f296bb3SBarry Smith
2817*7f296bb3SBarry Smith#### Interior-Point Newton’s Method (BQPIP)
2818*7f296bb3SBarry Smith
2819*7f296bb3SBarry SmithThe BQPIP algorithm is an interior-point method for bound constrained
2820*7f296bb3SBarry Smithquadratic optimization. It can be set by using the TAO solver of
2821*7f296bb3SBarry Smith`tao_bqpip` or via the option flag `-tao_type bgpip`. Since it
2822*7f296bb3SBarry Smithassumes the objective function is quadratic, it evaluates the function,
2823*7f296bb3SBarry Smithgradient, and Hessian only once. This method also requires the solution
2824*7f296bb3SBarry Smithof systems of linear equations, whose solver can be accessed and
2825*7f296bb3SBarry Smithmodified with the command `TaoGetKSP()`.
2826*7f296bb3SBarry Smith
2827*7f296bb3SBarry Smith### Legacy and Contributed Solvers
2828*7f296bb3SBarry Smith
2829*7f296bb3SBarry Smith#### Bundle Method for Regularized Risk Minimization (BMRM)
2830*7f296bb3SBarry Smith
2831*7f296bb3SBarry SmithBMRM is a numerical approach to optimizing an
2832*7f296bb3SBarry Smithunconstrained objective in the form of
2833*7f296bb3SBarry Smith$f(x) + 0.5 * \lambda \| x \|^2$. Here $f$ is a convex
2834*7f296bb3SBarry Smithfunction that is finite on the whole space. $\lambda$ is a
2835*7f296bb3SBarry Smithpositive weight parameter, and $\| x \|$ is the Euclidean norm of
2836*7f296bb3SBarry Smith$x$. The algorithm only requires a routine which, given an
2837*7f296bb3SBarry Smith$x$, returns the value of $f(x)$ and the gradient of
2838*7f296bb3SBarry Smith$f$ at $x$.
2839*7f296bb3SBarry Smith
2840*7f296bb3SBarry Smith#### Orthant-Wise Limited-memory Quasi-Newton (OWLQN)
2841*7f296bb3SBarry Smith
2842*7f296bb3SBarry SmithOWLQN {cite}`owlqn` is a numerical approach to optimizing
2843*7f296bb3SBarry Smithan unconstrained objective in the form of
2844*7f296bb3SBarry Smith$f(x) + \lambda \|x\|_1$. Here f is a convex and differentiable
2845*7f296bb3SBarry Smithfunction, $\lambda$ is a positive weight parameter, and
2846*7f296bb3SBarry Smith$\| x \|_1$ is the $\ell_1$ norm of $x$:
2847*7f296bb3SBarry Smith$\sum_i |x_i|$. The algorithm only requires evaluating the value
2848*7f296bb3SBarry Smithof $f$ and its gradient.
2849*7f296bb3SBarry Smith
2850*7f296bb3SBarry Smith(sec_tao_tron)=
2851*7f296bb3SBarry Smith
2852*7f296bb3SBarry Smith#### Trust-Region Newton Method (TRON)
2853*7f296bb3SBarry Smith
2854*7f296bb3SBarry SmithThe TRON {cite}`lin_c3` algorithm is an active-set method
2855*7f296bb3SBarry Smiththat uses a combination of gradient projections and a preconditioned
2856*7f296bb3SBarry Smithconjugate gradient method to minimize an objective function. Each
2857*7f296bb3SBarry Smithiteration of the TRON algorithm requires function, gradient, and Hessian
2858*7f296bb3SBarry Smithevaluations. In each iteration, the algorithm first applies several
2859*7f296bb3SBarry Smithconjugate gradient iterations. After these iterates, the TRON solver
2860*7f296bb3SBarry Smithmomentarily ignores the variables that equal one of its bounds and
2861*7f296bb3SBarry Smithapplies a preconditioned conjugate gradient method to a quadratic model
2862*7f296bb3SBarry Smithof the remaining set of *free* variables.
2863*7f296bb3SBarry Smith
2864*7f296bb3SBarry SmithThe TRON algorithm solves a reduced linear system defined by the rows
2865*7f296bb3SBarry Smithand columns corresponding to the variables that lie between the upper
2866*7f296bb3SBarry Smithand lower bounds. The TRON algorithm applies a trust region to the
2867*7f296bb3SBarry Smithconjugate gradients to ensure convergence. The initial trust-region
2868*7f296bb3SBarry Smithradius can be set by using the command
2869*7f296bb3SBarry Smith`TaoSetInitialTrustRegionRadius()`, and the current trust region size
2870*7f296bb3SBarry Smithcan be found by using the command `TaoGetCurrentTrustRegionRadius()`.
2871*7f296bb3SBarry SmithThe initial trust region can significantly alter the rate of convergence
2872*7f296bb3SBarry Smithfor the algorithm and should be tuned and adjusted for optimal
2873*7f296bb3SBarry Smithperformance.
2874*7f296bb3SBarry Smith
2875*7f296bb3SBarry SmithThis algorithm will be deprecated in the next version in favor of the
2876*7f296bb3SBarry SmithBounded Newton Trust Region (BNTR) algorithm.
2877*7f296bb3SBarry Smith
2878*7f296bb3SBarry Smith(sec_tao_blmvm)=
2879*7f296bb3SBarry Smith
2880*7f296bb3SBarry Smith#### Bound-constrained Limited-Memory Variable-Metric Method (BLMVM)
2881*7f296bb3SBarry Smith
2882*7f296bb3SBarry SmithBLMVM is a limited-memory, variable-metric method and is the
2883*7f296bb3SBarry Smithbound-constrained variant of the LMVM method for unconstrained
2884*7f296bb3SBarry Smithoptimization. It uses projected gradients to approximate the Hessian,
2885*7f296bb3SBarry Smitheliminating the need for Hessian evaluations. The method can be set by
2886*7f296bb3SBarry Smithusing the TAO solver `tao_blmvm`. For more details, please see the
2887*7f296bb3SBarry SmithLMVM section in the unconstrained algorithms as well as the LMVM matrix
2888*7f296bb3SBarry Smithdocumentation in the PETSc manual.
2889*7f296bb3SBarry Smith
2890*7f296bb3SBarry SmithThis algorithm will be deprecated in the next version in favor of the
2891*7f296bb3SBarry SmithBounded Quasi-Newton Line Search (BQNLS) algorithm.
2892*7f296bb3SBarry Smith
2893*7f296bb3SBarry Smith## Advanced Options
2894*7f296bb3SBarry Smith
2895*7f296bb3SBarry SmithThis section discusses options and routines that apply to most TAO
2896*7f296bb3SBarry Smithsolvers and problem classes. In particular, we focus on linear solvers,
2897*7f296bb3SBarry Smithconvergence tests, and line searches.
2898*7f296bb3SBarry Smith
2899*7f296bb3SBarry Smith(sec_tao_linearsolvers)=
2900*7f296bb3SBarry Smith
2901*7f296bb3SBarry Smith### Linear Solvers
2902*7f296bb3SBarry Smith
2903*7f296bb3SBarry SmithOne of the most computationally intensive phases of many optimization
2904*7f296bb3SBarry Smithalgorithms involves the solution of linear systems of equations. The
2905*7f296bb3SBarry Smithperformance of the linear solver may be critical to an efficient
2906*7f296bb3SBarry Smithcomputation of the solution. Since linear equation solvers often have a
2907*7f296bb3SBarry Smithwide variety of options associated with them, TAO allows the user to
2908*7f296bb3SBarry Smithaccess the linear solver with the
2909*7f296bb3SBarry Smith
2910*7f296bb3SBarry Smith```
2911*7f296bb3SBarry SmithTaoGetKSP(Tao, KSP *);
2912*7f296bb3SBarry Smith```
2913*7f296bb3SBarry Smith
2914*7f296bb3SBarry Smithcommand. With access to the KSP object, users can customize it for their
2915*7f296bb3SBarry Smithapplication to achieve improved performance. Additional details on the
2916*7f296bb3SBarry SmithKSP options in PETSc can be found in the {doc}`/manual/index`.
2917*7f296bb3SBarry Smith
2918*7f296bb3SBarry Smith### Monitors
2919*7f296bb3SBarry Smith
2920*7f296bb3SBarry SmithBy default the TAO solvers run silently without displaying information
2921*7f296bb3SBarry Smithabout the iterations. The user can initiate monitoring with the command
2922*7f296bb3SBarry Smith
2923*7f296bb3SBarry Smith```
2924*7f296bb3SBarry SmithTaoMonitorSet(Tao, PetscErrorCode (*mon)(Tao,void*), void*);
2925*7f296bb3SBarry Smith```
2926*7f296bb3SBarry Smith
2927*7f296bb3SBarry SmithThe routine `mon` indicates a user-defined monitoring routine, and
2928*7f296bb3SBarry Smith`void*` denotes an optional user-defined context for private data for
2929*7f296bb3SBarry Smiththe monitor routine.
2930*7f296bb3SBarry Smith
2931*7f296bb3SBarry SmithThe routine set by `TaoMonitorSet()` is called once during each
2932*7f296bb3SBarry Smithiteration of the optimization solver. Hence, the user can employ this
2933*7f296bb3SBarry Smithroutine for any application-specific computations that should be done
2934*7f296bb3SBarry Smithafter the solution update.
2935*7f296bb3SBarry Smith
2936*7f296bb3SBarry Smith(sec_tao_convergence)=
2937*7f296bb3SBarry Smith
2938*7f296bb3SBarry Smith### Convergence Tests
2939*7f296bb3SBarry Smith
2940*7f296bb3SBarry SmithConvergence of a solver can be defined in many ways. The methods TAO
2941*7f296bb3SBarry Smithuses by default are mentioned in {any}`sec_tao_customize`.
2942*7f296bb3SBarry SmithThese methods include absolute and relative convergence tolerances as
2943*7f296bb3SBarry Smithwell as a maximum number of iterations of function evaluations. If these
2944*7f296bb3SBarry Smithchoices are not sufficient, the user can specify a customized test
2945*7f296bb3SBarry Smith
2946*7f296bb3SBarry SmithUsers can set their own customized convergence tests of the form
2947*7f296bb3SBarry Smith
2948*7f296bb3SBarry Smith```
2949*7f296bb3SBarry SmithPetscErrorCode  conv(Tao, void*);
2950*7f296bb3SBarry Smith```
2951*7f296bb3SBarry Smith
2952*7f296bb3SBarry SmithThe second argument is a pointer to a structure defined by the user.
2953*7f296bb3SBarry SmithWithin this routine, the solver can be queried for the solution vector,
2954*7f296bb3SBarry Smithgradient vector, or other statistic at the current iteration through
2955*7f296bb3SBarry Smithroutines such as `TaoGetSolutionStatus()` and `TaoGetTolerances()`.
2956*7f296bb3SBarry Smith
2957*7f296bb3SBarry SmithTo use this convergence test within a TAO solver, one uses the command
2958*7f296bb3SBarry Smith
2959*7f296bb3SBarry Smith```
2960*7f296bb3SBarry SmithTaoSetConvergenceTest(Tao, PetscErrorCode (*conv)(Tao,void*), void*);
2961*7f296bb3SBarry Smith```
2962*7f296bb3SBarry Smith
2963*7f296bb3SBarry SmithThe second argument of this command is the convergence routine, and the
2964*7f296bb3SBarry Smithfinal argument of the convergence test routine denotes an optional
2965*7f296bb3SBarry Smithuser-defined context for private data. The convergence routine receives
2966*7f296bb3SBarry Smiththe TAO solver and this private data structure. The termination flag can
2967*7f296bb3SBarry Smithbe set by using the routine
2968*7f296bb3SBarry Smith
2969*7f296bb3SBarry Smith```
2970*7f296bb3SBarry SmithTaoSetConvergedReason(Tao, TaoConvergedReason);
2971*7f296bb3SBarry Smith```
2972*7f296bb3SBarry Smith
2973*7f296bb3SBarry Smith(sec_tao_linesearch)=
2974*7f296bb3SBarry Smith
2975*7f296bb3SBarry Smith### Line Searches
2976*7f296bb3SBarry Smith
2977*7f296bb3SBarry SmithBy using the command line option `-tao_ls_type`. Available line
2978*7f296bb3SBarry Smithsearches include Moré-Thuente {cite}`more:92`, Armijo, gpcg,
2979*7f296bb3SBarry Smithand unit.
2980*7f296bb3SBarry Smith
2981*7f296bb3SBarry SmithThe line search routines involve several parameters, which are set to
2982*7f296bb3SBarry Smithdefaults that are reasonable for many applications. The user can
2983*7f296bb3SBarry Smithoverride the defaults by using the following options
2984*7f296bb3SBarry Smith
2985*7f296bb3SBarry Smith- `-tao_ls_max_funcs <max>`
2986*7f296bb3SBarry Smith- `-tao_ls_stepmin <min>`
2987*7f296bb3SBarry Smith- `-tao_ls_stepmax <max>`
2988*7f296bb3SBarry Smith- `-tao_ls_ftol <ftol>`
2989*7f296bb3SBarry Smith- `-tao_ls_gtol <gtol>`
2990*7f296bb3SBarry Smith- `-tao_ls_rtol <rtol>`
2991*7f296bb3SBarry Smith
2992*7f296bb3SBarry SmithOne should run a TAO program with the option `-help` for details.
2993*7f296bb3SBarry SmithUsers may write their own customized line search codes by modeling them
2994*7f296bb3SBarry Smithafter one of the defaults provided.
2995*7f296bb3SBarry Smith
2996*7f296bb3SBarry Smith(sec_tao_recyclehistory)=
2997*7f296bb3SBarry Smith
2998*7f296bb3SBarry Smith### Recycling History
2999*7f296bb3SBarry Smith
3000*7f296bb3SBarry SmithSome TAO algorithms can re-use information accumulated in the previous
3001*7f296bb3SBarry Smith`TaoSolve()` call to hot-start the new solution. This can be enabled
3002*7f296bb3SBarry Smithusing the `-tao_recycle_history` flag, or in code via the
3003*7f296bb3SBarry Smith`TaoSetRecycleHistory()` interface.
3004*7f296bb3SBarry Smith
3005*7f296bb3SBarry SmithFor the nonlinear conjugate gradient solver (`TAOBNCG`), this option
3006*7f296bb3SBarry Smithre-uses the latest search direction from the previous `TaoSolve()`
3007*7f296bb3SBarry Smithcall to compute the initial search direction of a new `TaoSolve()`. By
3008*7f296bb3SBarry Smithdefault, the feature is disabled and the algorithm sets the initial
3009*7f296bb3SBarry Smithdirection as the negative gradient.
3010*7f296bb3SBarry Smith
3011*7f296bb3SBarry SmithFor the quasi-Newton family of methods (`TAOBQNLS`, `TAOBQNKLS`,
3012*7f296bb3SBarry Smith`TAOBQNKTR`, `TAOBQNKTL`), this option re-uses the accumulated
3013*7f296bb3SBarry Smithquasi-Newton Hessian approximation from the previous `TaoSolve()`
3014*7f296bb3SBarry Smithcall. By default, the feature is disabled and the algorithm will reset
3015*7f296bb3SBarry Smiththe quasi-Newton approximation to the identity matrix at the beginning
3016*7f296bb3SBarry Smithof every new `TaoSolve()`.
3017*7f296bb3SBarry Smith
3018*7f296bb3SBarry SmithThe option flag has no effect on other TAO solvers.
3019*7f296bb3SBarry Smith
3020*7f296bb3SBarry Smith(sec_tao_addsolver)=
3021*7f296bb3SBarry Smith
3022*7f296bb3SBarry Smith## Adding a Solver
3023*7f296bb3SBarry Smith
3024*7f296bb3SBarry SmithOne of the strengths of both TAO and PETSc is the ability to allow users
3025*7f296bb3SBarry Smithto extend the built-in solvers with new user-defined algorithms. It is
3026*7f296bb3SBarry Smithcertainly possible to develop new optimization algorithms outside of TAO
3027*7f296bb3SBarry Smithframework, but Using TAO to implement a solver has many advantages,
3028*7f296bb3SBarry Smith
3029*7f296bb3SBarry Smith1. TAO includes other optimization solvers with an identical interface,
3030*7f296bb3SBarry Smith   so application problems may conveniently switch solvers to compare
3031*7f296bb3SBarry Smith   their effectiveness.
3032*7f296bb3SBarry Smith2. TAO provides support for function evaluations and derivative
3033*7f296bb3SBarry Smith   information. It allows for the direct evaluation of this information
3034*7f296bb3SBarry Smith   by the application developer, contains limited support for finite
3035*7f296bb3SBarry Smith   difference approximations, and allows the uses of matrix-free
3036*7f296bb3SBarry Smith   methods. The solvers can obtain this function and derivative
3037*7f296bb3SBarry Smith   information through a simple interface while the details of its
3038*7f296bb3SBarry Smith   computation are handled within the toolkit.
3039*7f296bb3SBarry Smith3. TAO provides line searches, convergence tests, monitoring routines,
3040*7f296bb3SBarry Smith   and other tools that are helpful in an optimization algorithm. The
3041*7f296bb3SBarry Smith   availability of these tools means that the developers of the
3042*7f296bb3SBarry Smith   optimization solver do not have to write these utilities.
3043*7f296bb3SBarry Smith4. PETSc offers vectors, matrices, index sets, and linear solvers that
3044*7f296bb3SBarry Smith   can be used by the solver. These objects are standard mathematical
3045*7f296bb3SBarry Smith   constructions that have many different implementations. The objects
3046*7f296bb3SBarry Smith   may be distributed over multiple processors, restricted to a single
3047*7f296bb3SBarry Smith   processor, have a dense representation, use a sparse data structure,
3048*7f296bb3SBarry Smith   or vary in many other ways. TAO solvers do not need to know how these
3049*7f296bb3SBarry Smith   objects are represented or how the operations defined on them have
3050*7f296bb3SBarry Smith   been implemented. Instead, the solvers apply these operations through
3051*7f296bb3SBarry Smith   an abstract interface that leaves the details to PETSc and external
3052*7f296bb3SBarry Smith   libraries. This abstraction allows solvers to work seamlessly with a
3053*7f296bb3SBarry Smith   variety of data structures while allowing application developers to
3054*7f296bb3SBarry Smith   select data structures tailored for their purposes.
3055*7f296bb3SBarry Smith5. PETSc provides the user a convenient method for setting options at
3056*7f296bb3SBarry Smith   runtime, performance profiling, and debugging.
3057*7f296bb3SBarry Smith
3058*7f296bb3SBarry Smith(header_file_1)=
3059*7f296bb3SBarry Smith
3060*7f296bb3SBarry Smith### Header File
3061*7f296bb3SBarry Smith
3062*7f296bb3SBarry SmithTAO solver implementation files must include the TAO implementation file
3063*7f296bb3SBarry Smith`taoimpl.h`:
3064*7f296bb3SBarry Smith
3065*7f296bb3SBarry Smith```
3066*7f296bb3SBarry Smith#include "petsc/private/taoimpl.h"
3067*7f296bb3SBarry Smith```
3068*7f296bb3SBarry Smith
3069*7f296bb3SBarry SmithThis file contains data elements that are generally kept hidden from
3070*7f296bb3SBarry Smithapplication programmers, but may be necessary for solver implementations
3071*7f296bb3SBarry Smithto access.
3072*7f296bb3SBarry Smith
3073*7f296bb3SBarry Smith### TAO Interface with Solvers
3074*7f296bb3SBarry Smith
3075*7f296bb3SBarry SmithTAO solvers must be written in C or C++ and include several routines
3076*7f296bb3SBarry Smithwith a particular calling sequence. Two of these routines are mandatory:
3077*7f296bb3SBarry Smithone that initializes the TAO structure with the appropriate information
3078*7f296bb3SBarry Smithand one that applies the algorithm to a problem instance. Additional
3079*7f296bb3SBarry Smithroutines may be written to set options within the solver, view the
3080*7f296bb3SBarry Smithsolver, setup appropriate data structures, and destroy these data
3081*7f296bb3SBarry Smithstructures. In order to implement the conjugate gradient algorithm, for
3082*7f296bb3SBarry Smithexample, the following structure is useful.
3083*7f296bb3SBarry Smith
3084*7f296bb3SBarry Smith```
3085*7f296bb3SBarry Smithtypedef struct{
3086*7f296bb3SBarry Smith
3087*7f296bb3SBarry Smith  PetscReal beta;
3088*7f296bb3SBarry Smith  PetscReal eta;
3089*7f296bb3SBarry Smith  PetscInt  ngradtseps;
3090*7f296bb3SBarry Smith  PetscInt  nresetsteps;
3091*7f296bb3SBarry Smith  Vec X_old;
3092*7f296bb3SBarry Smith  Vec G_old;
3093*7f296bb3SBarry Smith
3094*7f296bb3SBarry Smith} TAO_CG;
3095*7f296bb3SBarry Smith```
3096*7f296bb3SBarry Smith
3097*7f296bb3SBarry SmithThis structure contains two parameters, two counters, and two work
3098*7f296bb3SBarry Smithvectors. Vectors for the solution and gradient are not needed here
3099*7f296bb3SBarry Smithbecause the TAO structure has pointers to them.
3100*7f296bb3SBarry Smith
3101*7f296bb3SBarry Smith#### Solver Routine
3102*7f296bb3SBarry Smith
3103*7f296bb3SBarry SmithAll TAO solvers have a routine that accepts a TAO structure and computes
3104*7f296bb3SBarry Smitha solution. TAO will call this routine when the application program uses
3105*7f296bb3SBarry Smiththe routine `TaoSolve()` and will pass to the solver information about
3106*7f296bb3SBarry Smiththe objective function and constraints, pointers to the variable vector
3107*7f296bb3SBarry Smithand gradient vector, and support for line searches, linear solvers, and
3108*7f296bb3SBarry Smithconvergence monitoring. As an example, consider the following code that
3109*7f296bb3SBarry Smithsolves an unconstrained minimization problem using the conjugate
3110*7f296bb3SBarry Smithgradient method.
3111*7f296bb3SBarry Smith
3112*7f296bb3SBarry Smith```
3113*7f296bb3SBarry SmithPetscErrorCode TaoSolve_CG(Tao tao)
3114*7f296bb3SBarry Smith{
3115*7f296bb3SBarry Smith  TAO_CG  *cg = (TAO_CG *) tao->data;
3116*7f296bb3SBarry Smith  Vec x = tao->solution;
3117*7f296bb3SBarry Smith  Vec g = tao->gradient;
3118*7f296bb3SBarry Smith  Vec s = tao->stepdirection;
3119*7f296bb3SBarry Smith  PetscInt     iter=0;
3120*7f296bb3SBarry Smith  PetscReal  gnormPrev,gdx,f,gnorm,steplength=0;
3121*7f296bb3SBarry Smith  TaoLineSearchConvergedReason lsflag=TAO_LINESEARCH_CONTINUE_ITERATING;
3122*7f296bb3SBarry Smith  TaoConvergedReason reason=TAO_CONTINUE_ITERATING;
3123*7f296bb3SBarry Smith
3124*7f296bb3SBarry Smith  PetscFunctionBegin;
3125*7f296bb3SBarry Smith
3126*7f296bb3SBarry Smith  PetscCall(TaoComputeObjectiveAndGradient(tao,x,&f,g));
3127*7f296bb3SBarry Smith  PetscCall(VecNorm(g,NORM_2,&gnorm));
3128*7f296bb3SBarry Smith
3129*7f296bb3SBarry Smith  PetscCall(VecSet(s,0));
3130*7f296bb3SBarry Smith
3131*7f296bb3SBarry Smith  cg->beta=0;
3132*7f296bb3SBarry Smith  gnormPrev = gnorm;
3133*7f296bb3SBarry Smith
3134*7f296bb3SBarry Smith  /* Enter loop */
3135*7f296bb3SBarry Smith  while (1){
3136*7f296bb3SBarry Smith
3137*7f296bb3SBarry Smith    /* Test for convergence */
3138*7f296bb3SBarry Smith    PetscCall(TaoMonitor(tao,iter,f,gnorm,0.0,step,&reason));
3139*7f296bb3SBarry Smith    if (reason!=TAO_CONTINUE_ITERATING) break;
3140*7f296bb3SBarry Smith
3141*7f296bb3SBarry Smith    cg->beta=(gnorm*gnorm)/(gnormPrev*gnormPrev);
3142*7f296bb3SBarry Smith    PetscCall(VecScale(s,cg->beta));
3143*7f296bb3SBarry Smith    PetscCall(VecAXPY(s,-1.0,g));
3144*7f296bb3SBarry Smith
3145*7f296bb3SBarry Smith    PetscCall(VecDot(s,g,&gdx));
3146*7f296bb3SBarry Smith    if (gdx>=0){     /* If not a descent direction, use gradient */
3147*7f296bb3SBarry Smith      PetscCall(VecCopy(g,s));
3148*7f296bb3SBarry Smith      PetscCall(VecScale(s,-1.0));
3149*7f296bb3SBarry Smith      gdx=-gnorm*gnorm;
3150*7f296bb3SBarry Smith    }
3151*7f296bb3SBarry Smith
3152*7f296bb3SBarry Smith    /* Line Search */
3153*7f296bb3SBarry Smith    gnormPrev = gnorm;  step=1.0;
3154*7f296bb3SBarry Smith    PetscCall(TaoLineSearchSetInitialStepLength(tao->linesearch,1.0));
3155*7f296bb3SBarry Smith    PetscCall(TaoLineSearchApply(tao->linesearch,x,&f,g,s,&steplength,&lsflag));
3156*7f296bb3SBarry Smith    PetscCall(TaoAddLineSearchCounts(tao));
3157*7f296bb3SBarry Smith    PetscCall(VecNorm(g,NORM_2,&gnorm));
3158*7f296bb3SBarry Smith    iter++;
3159*7f296bb3SBarry Smith  }
3160*7f296bb3SBarry Smith
3161*7f296bb3SBarry Smith  PetscFunctionReturn(PETSC_SUCCESS);
3162*7f296bb3SBarry Smith}
3163*7f296bb3SBarry Smith```
3164*7f296bb3SBarry Smith
3165*7f296bb3SBarry SmithThe first line of this routine casts the second argument to a pointer to
3166*7f296bb3SBarry Smitha `TAO_CG` data structure. This structure contains pointers to three
3167*7f296bb3SBarry Smithvectors and a scalar that will be needed in the algorithm.
3168*7f296bb3SBarry Smith
3169*7f296bb3SBarry SmithAfter declaring an initializing several variables, the solver lets TAO
3170*7f296bb3SBarry Smithevaluate the function and gradient at the current point in the using the
3171*7f296bb3SBarry Smithroutine `TaoComputeObjectiveAndGradient()`. Other routines may be used
3172*7f296bb3SBarry Smithto evaluate the Hessian matrix or evaluate constraints. TAO may obtain
3173*7f296bb3SBarry Smiththis information using direct evaluation or other means, but these
3174*7f296bb3SBarry Smithdetails do not affect our implementation of the algorithm.
3175*7f296bb3SBarry Smith
3176*7f296bb3SBarry SmithThe norm of the gradient is a standard measure used by unconstrained
3177*7f296bb3SBarry Smithminimization solvers to define convergence. This quantity is always
3178*7f296bb3SBarry Smithnonnegative and equals zero at the solution. The solver will pass this
3179*7f296bb3SBarry Smithquantity, the current function value, the current iteration number, and
3180*7f296bb3SBarry Smitha measure of infeasibility to TAO with the routine
3181*7f296bb3SBarry Smith
3182*7f296bb3SBarry Smith```
3183*7f296bb3SBarry SmithPetscErrorCode TaoMonitor(Tao tao, PetscInt iter, PetscReal f,
3184*7f296bb3SBarry Smith               PetscReal res, PetscReal cnorm, PetscReal steplength,
3185*7f296bb3SBarry Smith               TaoConvergedReason *reason);
3186*7f296bb3SBarry Smith```
3187*7f296bb3SBarry Smith
3188*7f296bb3SBarry SmithMost optimization algorithms are iterative, and solvers should include
3189*7f296bb3SBarry Smiththis command somewhere in each iteration. This routine records this
3190*7f296bb3SBarry Smithinformation, and applies any monitoring routines and convergence tests
3191*7f296bb3SBarry Smithset by default or the user. In this routine, the second argument is the
3192*7f296bb3SBarry Smithcurrent iteration number, and the third argument is the current function
3193*7f296bb3SBarry Smithvalue. The fourth argument is a nonnegative error measure associated
3194*7f296bb3SBarry Smithwith the distance between the current solution and the optimal solution.
3195*7f296bb3SBarry SmithExamples of this measure are the norm of the gradient or the square root
3196*7f296bb3SBarry Smithof a duality gap. The fifth argument is a nonnegative error that usually
3197*7f296bb3SBarry Smithrepresents a measure of the infeasibility such as the norm of the
3198*7f296bb3SBarry Smithconstraints or violation of bounds. This number should be zero for
3199*7f296bb3SBarry Smithunconstrained solvers. The sixth argument is a nonnegative steplength,
3200*7f296bb3SBarry Smithor the multiple of the step direction added to the previous iterate. The
3201*7f296bb3SBarry Smithresults of the convergence test are returned in the last argument. If
3202*7f296bb3SBarry Smiththe termination reason is `TAO_CONTINUE_ITERATING`, the algorithm
3203*7f296bb3SBarry Smithshould continue.
3204*7f296bb3SBarry Smith
3205*7f296bb3SBarry SmithAfter this monitoring routine, the solver computes a step direction
3206*7f296bb3SBarry Smithusing the conjugate gradient algorithm and computations using Vec
3207*7f296bb3SBarry Smithobjects. These methods include adding vectors together and computing an
3208*7f296bb3SBarry Smithinner product. A full list of these methods can be found in the manual
3209*7f296bb3SBarry Smithpages.
3210*7f296bb3SBarry Smith
3211*7f296bb3SBarry SmithNonlinear conjugate gradient algorithms also require a line search. TAO
3212*7f296bb3SBarry Smithprovides several line searches and support for using them. The routine
3213*7f296bb3SBarry Smith
3214*7f296bb3SBarry Smith```
3215*7f296bb3SBarry SmithTaoLineSearchApply(TaoLineSearch ls, Vec x, PetscReal *f, Vec g,
3216*7f296bb3SBarry Smith                       TaoVec *s, PetscReal *steplength,
3217*7f296bb3SBarry Smith                       TaoLineSearchConvergedReason *lsflag)
3218*7f296bb3SBarry Smith```
3219*7f296bb3SBarry Smith
3220*7f296bb3SBarry Smithpasses the current solution, gradient, and objective value to the line
3221*7f296bb3SBarry Smithsearch and returns a new solution, gradient, and objective value. More
3222*7f296bb3SBarry Smithdetails on line searches can be found in
3223*7f296bb3SBarry Smith{any}`sec_tao_linesearch`. The details of the
3224*7f296bb3SBarry Smithline search applied are specified elsewhere, when the line search is
3225*7f296bb3SBarry Smithcreated.
3226*7f296bb3SBarry Smith
3227*7f296bb3SBarry SmithTAO also includes support for linear solvers using PETSc KSP objects.
3228*7f296bb3SBarry SmithAlthough this algorithm does not require one, linear solvers are an
3229*7f296bb3SBarry Smithimportant part of many algorithms. Details on the use of these solvers
3230*7f296bb3SBarry Smithcan be found in the PETSc users manual.
3231*7f296bb3SBarry Smith
3232*7f296bb3SBarry Smith#### Creation Routine
3233*7f296bb3SBarry Smith
3234*7f296bb3SBarry SmithThe TAO solver is initialized for a particular algorithm in a separate
3235*7f296bb3SBarry Smithroutine. This routine sets default convergence tolerances, creates a
3236*7f296bb3SBarry Smithline search or linear solver if needed, and creates structures needed by
3237*7f296bb3SBarry Smiththis solver. For example, the routine that creates the nonlinear
3238*7f296bb3SBarry Smithconjugate gradient algorithm shown above can be implemented as follows.
3239*7f296bb3SBarry Smith
3240*7f296bb3SBarry Smith```
3241*7f296bb3SBarry SmithPETSC_EXTERN PetscErrorCode TaoCreate_CG(Tao tao)
3242*7f296bb3SBarry Smith{
3243*7f296bb3SBarry Smith  TAO_CG *cg = (TAO_CG*)tao->data;
3244*7f296bb3SBarry Smith  const char *morethuente_type = TAOLINESEARCH_MT;
3245*7f296bb3SBarry Smith
3246*7f296bb3SBarry Smith  PetscFunctionBegin;
3247*7f296bb3SBarry Smith
3248*7f296bb3SBarry Smith  PetscCall(PetscNew(&cg));
3249*7f296bb3SBarry Smith  tao->data = (void*)cg;
3250*7f296bb3SBarry Smith  cg->eta = 0.1;
3251*7f296bb3SBarry Smith  cg->delta_min = 1e-7;
3252*7f296bb3SBarry Smith  cg->delta_max = 100;
3253*7f296bb3SBarry Smith  cg->cg_type = CG_PolakRibierePlus;
3254*7f296bb3SBarry Smith
3255*7f296bb3SBarry Smith  tao->max_it = 2000;
3256*7f296bb3SBarry Smith  tao->max_funcs = 4000;
3257*7f296bb3SBarry Smith
3258*7f296bb3SBarry Smith  tao->ops->setup = TaoSetUp_CG;
3259*7f296bb3SBarry Smith  tao->ops->solve = TaoSolve_CG;
3260*7f296bb3SBarry Smith  tao->ops->view = TaoView_CG;
3261*7f296bb3SBarry Smith  tao->ops->setfromoptions = TaoSetFromOptions_CG;
3262*7f296bb3SBarry Smith  tao->ops->destroy = TaoDestroy_CG;
3263*7f296bb3SBarry Smith
3264*7f296bb3SBarry Smith  PetscCall(TaoLineSearchCreate(((PetscObject)tao)->comm, &tao->linesearch));
3265*7f296bb3SBarry Smith  PetscCall(TaoLineSearchSetType(tao->linesearch, morethuente_type));
3266*7f296bb3SBarry Smith  PetscCall(TaoLineSearchUseTaoRoutines(tao->linesearch, tao));
3267*7f296bb3SBarry Smith
3268*7f296bb3SBarry Smith  PetscFunctionReturn(PETSC_SUCCESS);
3269*7f296bb3SBarry Smith}
3270*7f296bb3SBarry SmithEXTERN_C_END
3271*7f296bb3SBarry Smith```
3272*7f296bb3SBarry Smith
3273*7f296bb3SBarry SmithThis routine declares some variables and then allocates memory for the
3274*7f296bb3SBarry Smith`TAO_CG` data structure. Notice that the `Tao` object now has a
3275*7f296bb3SBarry Smithpointer to this data structure (`tao->data`) so it can be accessed by
3276*7f296bb3SBarry Smiththe other functions written for this solver implementation.
3277*7f296bb3SBarry Smith
3278*7f296bb3SBarry SmithThis routine also sets some default parameters particular to the
3279*7f296bb3SBarry Smithconjugate gradient algorithm, sets default convergence tolerances, and
3280*7f296bb3SBarry Smithcreates a particular line search. These defaults could be specified in
3281*7f296bb3SBarry Smiththe routine that solves the problem, but specifying them here gives the
3282*7f296bb3SBarry Smithuser the opportunity to modify these parameters either by using direct
3283*7f296bb3SBarry Smithcalls setting parameters or by using options.
3284*7f296bb3SBarry Smith
3285*7f296bb3SBarry SmithFinally, this solver passes to TAO the names of all the other routines
3286*7f296bb3SBarry Smithused by the solver.
3287*7f296bb3SBarry Smith
3288*7f296bb3SBarry SmithNote that the lines `EXTERN_C_BEGIN` and `EXTERN_C_END` surround
3289*7f296bb3SBarry Smiththis routine. These macros are required to preserve the name of this
3290*7f296bb3SBarry Smithfunction without any name-mangling from the C++ compiler (if used).
3291*7f296bb3SBarry Smith
3292*7f296bb3SBarry Smith#### Destroy Routine
3293*7f296bb3SBarry Smith
3294*7f296bb3SBarry SmithAnother routine needed by most solvers destroys the data structures
3295*7f296bb3SBarry Smithcreated by earlier routines. For the nonlinear conjugate gradient method
3296*7f296bb3SBarry Smithdiscussed earlier, the following routine destroys the two work vectors
3297*7f296bb3SBarry Smithand the `TAO_CG` structure.
3298*7f296bb3SBarry Smith
3299*7f296bb3SBarry Smith```
3300*7f296bb3SBarry SmithPetscErrorCode TaoDestroy_CG(TAO_SOLVER tao)
3301*7f296bb3SBarry Smith{
3302*7f296bb3SBarry Smith  TAO_CG *cg = (TAO_CG *) tao->data;
3303*7f296bb3SBarry Smith
3304*7f296bb3SBarry Smith  PetscFunctionBegin;
3305*7f296bb3SBarry Smith
3306*7f296bb3SBarry Smith  PetscCall(VecDestroy(&cg->X_old));
3307*7f296bb3SBarry Smith  PetscCall(VecDestroy(&cg->G_old));
3308*7f296bb3SBarry Smith
3309*7f296bb3SBarry Smith  PetscFree(tao->data);
3310*7f296bb3SBarry Smith  tao->data = NULL;
3311*7f296bb3SBarry Smith
3312*7f296bb3SBarry Smith  PetscFunctionReturn(PETSC_SUCCESS);
3313*7f296bb3SBarry Smith}
3314*7f296bb3SBarry Smith```
3315*7f296bb3SBarry Smith
3316*7f296bb3SBarry SmithThis routine is called from within the `TaoDestroy()` routine. Only
3317*7f296bb3SBarry Smithalgorithm-specific data objects are destroyed in this routine; any
3318*7f296bb3SBarry Smithobjects indexed by TAO (`tao->linesearch`, `tao->ksp`,
3319*7f296bb3SBarry Smith`tao->gradient`, etc.) will be destroyed by TAO immediately after the
3320*7f296bb3SBarry Smithalgorithm-specific destroy routine completes.
3321*7f296bb3SBarry Smith
3322*7f296bb3SBarry Smith#### SetUp Routine
3323*7f296bb3SBarry Smith
3324*7f296bb3SBarry SmithIf the SetUp routine has been set by the initialization routine, TAO
3325*7f296bb3SBarry Smithwill call it during the execution of `TaoSolve()`. While this routine
3326*7f296bb3SBarry Smithis optional, it is often provided to allocate the gradient vector, work
3327*7f296bb3SBarry Smithvectors, and other data structures required by the solver. It should
3328*7f296bb3SBarry Smithhave the following form.
3329*7f296bb3SBarry Smith
3330*7f296bb3SBarry Smith```
3331*7f296bb3SBarry SmithPetscErrorCode TaoSetUp_CG(Tao tao)
3332*7f296bb3SBarry Smith{
3333*7f296bb3SBarry Smith  TAO_CG *cg = (TAO_CG*)tao->data;
3334*7f296bb3SBarry Smith  PetscFunctionBegin;
3335*7f296bb3SBarry Smith
3336*7f296bb3SBarry Smith  PetscCall(VecDuplicate(tao->solution,&tao->gradient));
3337*7f296bb3SBarry Smith  PetscCall(VecDuplicate(tao->solution,&tao->stepdirection));
3338*7f296bb3SBarry Smith  PetscCall(VecDuplicate(tao->solution,&cg->X_old));
3339*7f296bb3SBarry Smith  PetscCall(VecDuplicate(tao->solution,&cg->G_old));
3340*7f296bb3SBarry Smith
3341*7f296bb3SBarry Smith  PetscFunctionReturn(PETSC_SUCCESS);
3342*7f296bb3SBarry Smith}
3343*7f296bb3SBarry Smith```
3344*7f296bb3SBarry Smith
3345*7f296bb3SBarry Smith#### SetFromOptions Routine
3346*7f296bb3SBarry Smith
3347*7f296bb3SBarry SmithThe SetFromOptions routine should be used to check for any
3348*7f296bb3SBarry Smithalgorithm-specific options set by the user and will be called when the
3349*7f296bb3SBarry Smithapplication makes a call to `TaoSetFromOptions()`. It should have the
3350*7f296bb3SBarry Smithfollowing form.
3351*7f296bb3SBarry Smith
3352*7f296bb3SBarry Smith```
3353*7f296bb3SBarry SmithPetscErrorCode TaoSetFromOptions_CG(Tao tao, void *solver);
3354*7f296bb3SBarry Smith{
3355*7f296bb3SBarry Smith  TAO_CG *cg = (TAO_CG*)solver;
3356*7f296bb3SBarry Smith  PetscFunctionBegin;
3357*7f296bb3SBarry Smith  PetscCall(PetscOptionsReal("-tao_cg_eta","restart tolerance","",cg->eta,&cg->eta,0));
3358*7f296bb3SBarry Smith  PetscCall(PetscOptionsReal("-tao_cg_delta_min","minimum delta value","",cg->delta_min,&cg->delta_min,0));
3359*7f296bb3SBarry Smith  PetscCall(PetscOptionsReal("-tao_cg_delta_max","maximum delta value","",cg->delta_max,&cg->delta_max,0));
3360*7f296bb3SBarry Smith  PetscFunctionReturn(PETSC_SUCCESS);
3361*7f296bb3SBarry Smith}
3362*7f296bb3SBarry Smith```
3363*7f296bb3SBarry Smith
3364*7f296bb3SBarry Smith#### View Routine
3365*7f296bb3SBarry Smith
3366*7f296bb3SBarry SmithThe View routine should be used to output any algorithm-specific
3367*7f296bb3SBarry Smithinformation or statistics at the end of a solve. This routine will be
3368*7f296bb3SBarry Smithcalled when the application makes a call to `TaoView()` or when the
3369*7f296bb3SBarry Smithcommand line option `-tao_view` is used. It should have the following
3370*7f296bb3SBarry Smithform.
3371*7f296bb3SBarry Smith
3372*7f296bb3SBarry Smith```
3373*7f296bb3SBarry SmithPetscErrorCode TaoView_CG(Tao tao, PetscViewer viewer)
3374*7f296bb3SBarry Smith{
3375*7f296bb3SBarry Smith  TAO_CG *cg = (TAO_CG*)tao->data;
3376*7f296bb3SBarry Smith
3377*7f296bb3SBarry Smith  PetscFunctionBegin;
3378*7f296bb3SBarry Smith  PetscCall(PetscViewerASCIIPushTab(viewer));
3379*7f296bb3SBarry Smith  PetscCall(PetscViewerASCIIPrintf(viewer,"Grad. steps: %d\n",cg->ngradsteps));
3380*7f296bb3SBarry Smith  PetscCall(PetscViewerASCIIPrintf(viewer,"Reset steps: %d\n",cg->nresetsteps));
3381*7f296bb3SBarry Smith  PetscCall(PetscViewerASCIIPopTab(viewer));
3382*7f296bb3SBarry Smith  PetscFunctionReturn(PETSC_SUCCESS);
3383*7f296bb3SBarry Smith}
3384*7f296bb3SBarry Smith```
3385*7f296bb3SBarry Smith
3386*7f296bb3SBarry Smith#### Registering the Solver
3387*7f296bb3SBarry Smith
3388*7f296bb3SBarry SmithOnce a new solver is implemented, TAO needs to know the name of the
3389*7f296bb3SBarry Smithsolver and what function to use to create the solver. To this end, one
3390*7f296bb3SBarry Smithcan use the routine
3391*7f296bb3SBarry Smith
3392*7f296bb3SBarry Smith```
3393*7f296bb3SBarry SmithTaoRegister(const char *name,
3394*7f296bb3SBarry Smith                const char *path,
3395*7f296bb3SBarry Smith                const char *cname,
3396*7f296bb3SBarry Smith                PetscErrorCode (*create) (Tao));
3397*7f296bb3SBarry Smith```
3398*7f296bb3SBarry Smith
3399*7f296bb3SBarry Smithwhere `name` is the name of the solver (i.e., `tao_blmvm`), `path`
3400*7f296bb3SBarry Smithis the path to the library containing the solver, `cname` is the name
3401*7f296bb3SBarry Smithof the routine that creates the solver (in our case, `TaoCreate_CG`),
3402*7f296bb3SBarry Smithand `create` is a pointer to that creation routine. If one is using
3403*7f296bb3SBarry Smithdynamic loading, then the fourth argument will be ignored.
3404*7f296bb3SBarry Smith
3405*7f296bb3SBarry SmithOnce the solver has been registered, the new solver can be selected
3406*7f296bb3SBarry Smitheither by using the `TaoSetType()` function or by using the
3407*7f296bb3SBarry Smith`-tao_type` command line option.
3408*7f296bb3SBarry Smith
3409*7f296bb3SBarry Smith```{rubric} Footnotes
3410*7f296bb3SBarry Smith```
3411*7f296bb3SBarry Smith
3412*7f296bb3SBarry Smith[^mpi]: For more on MPI and PETSc, see {any}`sec_running`.
3413*7f296bb3SBarry Smith
3414*7f296bb3SBarry Smith```{eval-rst}
3415*7f296bb3SBarry Smith.. bibliography:: /petsc.bib
3416*7f296bb3SBarry Smith   :filter: docname in docnames
3417*7f296bb3SBarry Smith```
3418