17f296bb3SBarry Smith(ch_tao)= 27f296bb3SBarry Smith 37f296bb3SBarry Smith# TAO: Optimization Solvers 47f296bb3SBarry Smith 57f296bb3SBarry SmithThe Toolkit for Advanced Optimization (TAO) focuses on algorithms for the 67f296bb3SBarry Smithsolution of large-scale optimization problems on high-performance 77f296bb3SBarry Smitharchitectures. Methods are available for 87f296bb3SBarry Smith 97f296bb3SBarry Smith- {any}`sec_tao_leastsquares` 107f296bb3SBarry Smith- {any}`sec_tao_quadratic` 117f296bb3SBarry Smith- {any}`sec_tao_unconstrained` 127f296bb3SBarry Smith- {any}`sec_tao_bound` 137f296bb3SBarry Smith- {any}`sec_tao_constrained` 147f296bb3SBarry Smith- {any}`sec_tao_complementary` 157f296bb3SBarry Smith- {any}`sec_tao_pde_constrained` 167f296bb3SBarry Smith 177f296bb3SBarry Smith(sec_tao_getting_started)= 187f296bb3SBarry Smith 197f296bb3SBarry Smith## Getting Started: A Simple TAO Example 207f296bb3SBarry Smith 217f296bb3SBarry SmithTo help the user start using TAO immediately, we introduce here a simple 227f296bb3SBarry Smithuniprocessor example. Please read {any}`sec_tao_solvers` 237f296bb3SBarry Smithfor a more in-depth discussion on using the TAO solvers. The code 247f296bb3SBarry Smithpresented {any}`below <tao_example1>` minimizes the 257f296bb3SBarry Smithextended Rosenbrock function $f: \mathbb R^n \to \mathbb R$ 267f296bb3SBarry Smithdefined by 277f296bb3SBarry Smith 287f296bb3SBarry Smith$$ 297f296bb3SBarry Smithf(x) = \sum_{i=0}^{m-1} \left( \alpha(x_{2i+1}-x_{2i}^2)^2 + (1-x_{2i})^2 \right), 307f296bb3SBarry Smith$$ 317f296bb3SBarry Smith 327f296bb3SBarry Smithwhere $n = 2m$ is the number of variables. Note that while we use 337f296bb3SBarry Smiththe C language to introduce the TAO software, the package is fully 347f296bb3SBarry Smithusable from C++ and Fortran. 357f296bb3SBarry Smith{any}`ch_fortran` discusses additional 367f296bb3SBarry Smithissues concerning Fortran usage. 377f296bb3SBarry Smith 387f296bb3SBarry SmithThe code in {any}`the example <tao_example1>` contains many of 397f296bb3SBarry Smiththe components needed to write most TAO programs and thus is 407f296bb3SBarry Smithillustrative of the features present in complex optimization problems. 417f296bb3SBarry SmithNote that for display purposes we have omitted some nonessential lines 427f296bb3SBarry Smithof code as well as the (essential) code required for the routine 437f296bb3SBarry Smith`FormFunctionGradient`, which evaluates the function and gradient, and 447f296bb3SBarry Smiththe code for `FormHessian`, which evaluates the Hessian matrix for 457f296bb3SBarry SmithRosenbrock’s function. The complete code is available in 467f296bb3SBarry Smith<a href="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/unconstrained/tutorials/rosenbrock1.c.html">\$TAO_DIR/src/unconstrained/tutorials/rosenbrock1.c</a>. 477f296bb3SBarry SmithThe following sections annotate the lines of code in 487f296bb3SBarry Smith{any}`the example <tao_example1>`. 497f296bb3SBarry Smith 507f296bb3SBarry Smith(tao_example1)= 517f296bb3SBarry Smith 527f296bb3SBarry Smith:::{admonition} Listing: `src/tao/unconstrained/tutorials/rosenbrock1.c` 537f296bb3SBarry Smith```{literalinclude} /../src/tao/unconstrained/tutorials/rosenbrock1.c 547f296bb3SBarry Smith:append: return ierr;} 557f296bb3SBarry Smith:end-at: PetscFinalize 567f296bb3SBarry Smith:prepend: '#include <petsctao.h>' 577f296bb3SBarry Smith:start-at: typedef struct 587f296bb3SBarry Smith``` 597f296bb3SBarry Smith::: 607f296bb3SBarry Smith 617f296bb3SBarry Smith(sec_tao_workflow)= 627f296bb3SBarry Smith 637f296bb3SBarry Smith## TAO Workflow 647f296bb3SBarry Smith 657f296bb3SBarry SmithMany TAO applications will follow an ordered set of procedures for 667f296bb3SBarry Smithsolving an optimization problem: The user creates a `Tao` context and 677f296bb3SBarry Smithselects a default algorithm. Call-back routines as well as vector 687f296bb3SBarry Smith(`Vec`) and matrix (`Mat`) data structures are then set. These 697f296bb3SBarry Smithcall-back routines will be used for evaluating the objective function, 707f296bb3SBarry Smithgradient, and perhaps the Hessian matrix. The user then invokes TAO to 717f296bb3SBarry Smithsolve the optimization problem and finally destroys the `Tao` context. 727f296bb3SBarry SmithA list of the necessary functions for performing these steps using TAO 737f296bb3SBarry Smithis shown below. 747f296bb3SBarry Smith 757f296bb3SBarry Smith``` 767f296bb3SBarry SmithTaoCreate(MPI_Comm comm, Tao *tao); 777f296bb3SBarry SmithTaoSetType(Tao tao, TaoType type); 787f296bb3SBarry SmithTaoSetSolution(Tao tao, Vec x); 79*2a8381b2SBarry SmithTaoSetObjectiveAndGradient(Tao tao, Vec g, PetscErrorCode (*FormFGradient)(Tao, Vec, PetscReal*, Vec, PetscCtx), PetscCtx ctx); 80*2a8381b2SBarry SmithTaoSetHessian(Tao tao, Mat H, Mat Hpre, PetscErrorCode (*FormHessian)(Tao, Vec, Mat, Mat, PetscCtx), PetscCtx ctx); 817f296bb3SBarry SmithTaoSolve(Tao tao); 827f296bb3SBarry SmithTaoDestroy(Tao tao); 837f296bb3SBarry Smith``` 847f296bb3SBarry Smith 857f296bb3SBarry SmithNote that the solver algorithm selected through the function 867f296bb3SBarry Smith`TaoSetType()` can be overridden at runtime by using an options 877f296bb3SBarry Smithdatabase. Through this database, the user not only can select a 887f296bb3SBarry Smithminimization method (e.g., limited-memory variable metric, conjugate 897f296bb3SBarry Smithgradient, Newton with line search or trust region) but also can 907f296bb3SBarry Smithprescribe the convergence tolerance, set various monitoring routines, 917f296bb3SBarry Smithset iterative methods and preconditions for solving the linear systems, 927f296bb3SBarry Smithand so forth. See {any}`sec_tao_solvers` for more 937f296bb3SBarry Smithinformation on the solver methods available in TAO. 947f296bb3SBarry Smith 957f296bb3SBarry Smith### Header File 967f296bb3SBarry Smith 977f296bb3SBarry SmithTAO applications written in C/C++ should have the statement 987f296bb3SBarry Smith 997f296bb3SBarry Smith``` 1007f296bb3SBarry Smith#include <petsctao.h> 1017f296bb3SBarry Smith``` 1027f296bb3SBarry Smith 1037f296bb3SBarry Smithin each file that uses a routine in the TAO libraries. 1047f296bb3SBarry Smith 1057f296bb3SBarry Smith### Creation and Destruction 1067f296bb3SBarry Smith 1077f296bb3SBarry SmithA TAO solver can be created by calling the 1087f296bb3SBarry Smith 1097f296bb3SBarry Smith``` 1107f296bb3SBarry SmithTaoCreate(MPI_Comm, Tao*); 1117f296bb3SBarry Smith``` 1127f296bb3SBarry Smith 1137f296bb3SBarry Smithroutine. Much like creating PETSc vector and matrix objects, the first 1147f296bb3SBarry Smithargument is an MPI *communicator*. An MPI [^mpi] 1157f296bb3SBarry Smithcommunicator indicates a collection of processors that will be used to 1167f296bb3SBarry Smithevaluate the objective function, compute constraints, and provide 1177f296bb3SBarry Smithderivative information. When only one processor is being used, the 1187f296bb3SBarry Smithcommunicator `PETSC_COMM_SELF` can be used with no understanding of 1197f296bb3SBarry SmithMPI. Even parallel users need to be familiar with only the basic 1207f296bb3SBarry Smithconcepts of message passing and distributed-memory computing. Most 1217f296bb3SBarry Smithapplications running TAO in parallel environments can employ the 1227f296bb3SBarry Smithcommunicator `PETSC_COMM_WORLD` to indicate all processes known to 1237f296bb3SBarry SmithPETSc in a given run. 1247f296bb3SBarry Smith 1257f296bb3SBarry SmithThe routine 1267f296bb3SBarry Smith 1277f296bb3SBarry Smith``` 1287f296bb3SBarry SmithTaoSetType(Tao, TaoType); 1297f296bb3SBarry Smith``` 1307f296bb3SBarry Smith 1317f296bb3SBarry Smithcan be used to set the algorithm TAO uses to solve the application. The 1327f296bb3SBarry Smithvarious types of TAO solvers and the flags that identify them will be 1337f296bb3SBarry Smithdiscussed in the following sections. The solution method should be 1347f296bb3SBarry Smithcarefully chosen depending on the problem being solved. Some solvers, 1357f296bb3SBarry Smithfor instance, are meant for problems with no constraints, whereas other 1367f296bb3SBarry Smithsolvers acknowledge constraints in the problem and handle them 1377f296bb3SBarry Smithaccordingly. The user must also be aware of the derivative information 1387f296bb3SBarry Smiththat is available. Some solvers require second-order information, while 1397f296bb3SBarry Smithother solvers require only gradient or function information. The command 1407f296bb3SBarry Smithline option `-tao_type` followed by 1417f296bb3SBarry Smitha TAO method will override any method specified by the second argument. 1427f296bb3SBarry SmithThe command line option `-tao_type bqnls`, for instance, will 1437f296bb3SBarry Smithspecify the limited-memory quasi-Newton line search method for 1447f296bb3SBarry Smithbound-constrained problems. Note that the `TaoType` variable is a string that 1457f296bb3SBarry Smithrequires quotation marks in an application program, but quotation marks 1467f296bb3SBarry Smithare not required at the command line. 1477f296bb3SBarry Smith 1487f296bb3SBarry SmithEach TAO solver that has been created should also be destroyed by using 1497f296bb3SBarry Smiththe 1507f296bb3SBarry Smith 1517f296bb3SBarry Smith``` 1527f296bb3SBarry SmithTaoDestroy(Tao tao); 1537f296bb3SBarry Smith``` 1547f296bb3SBarry Smith 1557f296bb3SBarry Smithcommand. This routine frees the internal data structures used by the 1567f296bb3SBarry Smithsolver. 1577f296bb3SBarry Smith 1587f296bb3SBarry Smith### Command-line Options 1597f296bb3SBarry Smith 1607f296bb3SBarry SmithAdditional options for the TAO solver can be set from the command 1617f296bb3SBarry Smithline by using the 1627f296bb3SBarry Smith 1637f296bb3SBarry Smith``` 1647f296bb3SBarry SmithTaoSetFromOptions(Tao) 1657f296bb3SBarry Smith``` 1667f296bb3SBarry Smith 1677f296bb3SBarry Smithroutine. This command also provides information about runtime options 1687f296bb3SBarry Smithwhen the user includes the `-help` option on the command line. 1697f296bb3SBarry Smith 1707f296bb3SBarry SmithIn addition to common command line options shared by all TAO solvers, each TAO 1717f296bb3SBarry Smithmethod also implements its own specialized options. Please refer to the 1727f296bb3SBarry Smithdocumentation for individual methods for more details. 1737f296bb3SBarry Smith 1747f296bb3SBarry Smith### Defining Variables 1757f296bb3SBarry Smith 1767f296bb3SBarry SmithIn all the optimization solvers, the application must provide a `Vec` 1777f296bb3SBarry Smithobject of appropriate dimension to represent the variables. This vector 1787f296bb3SBarry Smithwill be cloned by the solvers to create additional work space within the 1797f296bb3SBarry Smithsolver. If this vector is distributed over multiple processors, it 1807f296bb3SBarry Smithshould have a parallel distribution that allows for efficient scaling, 1817f296bb3SBarry Smithinner products, and function evaluations. This vector can be passed to 1827f296bb3SBarry Smiththe application object by using the 1837f296bb3SBarry Smith 1847f296bb3SBarry Smith``` 1857f296bb3SBarry SmithTaoSetSolution(Tao, Vec); 1867f296bb3SBarry Smith``` 1877f296bb3SBarry Smith 1887f296bb3SBarry Smithroutine. When using this routine, the application should initialize the 1897f296bb3SBarry Smithvector with an approximate solution of the optimization problem before 1907f296bb3SBarry Smithcalling the TAO solver. This vector will be used by the TAO solver to 1917f296bb3SBarry Smithstore the solution. Elsewhere in the application, this solution vector 1927f296bb3SBarry Smithcan be retrieved from the application object by using the 1937f296bb3SBarry Smith 1947f296bb3SBarry Smith``` 1957f296bb3SBarry SmithTaoGetSolution(Tao, Vec*); 1967f296bb3SBarry Smith``` 1977f296bb3SBarry Smith 1987f296bb3SBarry Smithroutine. This routine takes the address of a `Vec` in the second 1997f296bb3SBarry Smithargument and sets it to the solution vector used in the application. 2007f296bb3SBarry Smith 2017f296bb3SBarry Smith### User Defined Call-back Routines 2027f296bb3SBarry Smith 2037f296bb3SBarry SmithUsers of TAO are required to provide routines that perform function 2047f296bb3SBarry Smithevaluations. Depending on the solver chosen, they may also have to write 2057f296bb3SBarry Smithroutines that evaluate the gradient vector and Hessian matrix. 2067f296bb3SBarry Smith 2077f296bb3SBarry Smith#### Application Context 2087f296bb3SBarry Smith 2097f296bb3SBarry SmithWriting a TAO application may require use of an *application context*. 2107f296bb3SBarry SmithAn application context is a structure or object defined by an 2117f296bb3SBarry Smithapplication developer, passed into a routine also written by the 2127f296bb3SBarry Smithapplication developer, and used within the routine to perform its stated 2137f296bb3SBarry Smithtask. 2147f296bb3SBarry Smith 2157f296bb3SBarry SmithFor example, a routine that evaluates an objective function may need 2167f296bb3SBarry Smithparameters, work vectors, and other information. This information, which 2177f296bb3SBarry Smithmay be specific to an application and necessary to evaluate the 2187f296bb3SBarry Smithobjective, can be collected in a single structure and used as one of the 2197f296bb3SBarry Smitharguments in the routine. The address of this structure will be cast as 2207f296bb3SBarry Smithtype `(void*)` and passed to the routine in the final argument. Many 2217f296bb3SBarry Smithexamples of these structures are included in the TAO distribution. 2227f296bb3SBarry Smith 2237f296bb3SBarry SmithThis technique offers several advantages. In particular, it allows for a 2247f296bb3SBarry Smithuniform interface between TAO and the applications. The fundamental 2257f296bb3SBarry Smithinformation needed by TAO appears in the arguments of the routine, while 2267f296bb3SBarry Smithdata specific to an application and its implementation is confined to an 2277f296bb3SBarry Smithopaque pointer. The routines can access information created outside the 2287f296bb3SBarry Smithlocal scope without the use of global variables. The TAO solvers and 2297f296bb3SBarry Smithapplication objects will never access this structure, so the application 2307f296bb3SBarry Smithdeveloper has complete freedom to define it. If no such structure or 2317f296bb3SBarry Smithneeded by the application then a NULL pointer can be used. 2327f296bb3SBarry Smith 2337f296bb3SBarry Smith(sec_tao_fghj)= 2347f296bb3SBarry Smith 2357f296bb3SBarry Smith#### Objective Function and Gradient Routines 2367f296bb3SBarry Smith 2377f296bb3SBarry SmithTAO solvers that minimize an objective function require the application 2387f296bb3SBarry Smithto evaluate the objective function. Some solvers may also require the 2397f296bb3SBarry Smithapplication to evaluate derivatives of the objective function. Routines 2407f296bb3SBarry Smiththat perform these computations must be identified to the application 2417f296bb3SBarry Smithobject and must follow a strict calling sequence. 2427f296bb3SBarry Smith 2437f296bb3SBarry SmithRoutines should follow the form 2447f296bb3SBarry Smith 2457f296bb3SBarry Smith``` 246*2a8381b2SBarry SmithPetscErrorCode EvaluateObjective(Tao, Vec, PetscReal*, PetscCtx); 2477f296bb3SBarry Smith``` 2487f296bb3SBarry Smith 2497f296bb3SBarry Smithin order to evaluate an objective function 2507f296bb3SBarry Smith$f: \, \mathbb R^n \to \mathbb R$. The first argument is the TAO 2517f296bb3SBarry SmithSolver object, the second argument is the $n$-dimensional vector 2527f296bb3SBarry Smiththat identifies where the objective should be evaluated, and the fourth 2537f296bb3SBarry Smithargument is an application context. This routine should use the third 2547f296bb3SBarry Smithargument to return the objective value evaluated at the point specified 2557f296bb3SBarry Smithby the vector in the second argument. 2567f296bb3SBarry Smith 2577f296bb3SBarry SmithThis routine, and the application context, should be passed to the 2587f296bb3SBarry Smithapplication object by using the 2597f296bb3SBarry Smith 2607f296bb3SBarry Smith``` 261*2a8381b2SBarry SmithTaoSetObjective(Tao, PetscErrorCode(*)(Tao, Vec, PetscReal*, PetscCtx), PetscCtx); 2627f296bb3SBarry Smith``` 2637f296bb3SBarry Smith 2647f296bb3SBarry Smithroutine. The first argument in this routine is the TAO solver object, 2657f296bb3SBarry Smiththe second argument is a function pointer to the routine that evaluates 2667f296bb3SBarry Smiththe objective, and the third argument is the pointer to an appropriate 2677f296bb3SBarry Smithapplication context. Although the final argument may point to anything, 2687f296bb3SBarry Smithit must be cast as a `(void*)` type. This pointer will be passed back 2697f296bb3SBarry Smithto the developer in the fourth argument of the routine that evaluates 2707f296bb3SBarry Smiththe objective. In this routine, the pointer can be cast back to the 2717f296bb3SBarry Smithappropriate type. Examples of these structures and their usage are 2727f296bb3SBarry Smithprovided in the distribution. 2737f296bb3SBarry Smith 2747f296bb3SBarry SmithMany TAO solvers also require gradient information from the application 2757f296bb3SBarry SmithThe gradient of the objective function is specified in a similar manner. 2767f296bb3SBarry SmithRoutines that evaluate the gradient should have the calling sequence 2777f296bb3SBarry Smith 2787f296bb3SBarry Smith``` 279*2a8381b2SBarry SmithPetscErrorCode EvaluateGradient(Tao, Vec, Vec, PetscCtx); 2807f296bb3SBarry Smith``` 2817f296bb3SBarry Smith 2827f296bb3SBarry Smithwhere the first argument is the TAO solver object, the second argument 2837f296bb3SBarry Smithis the variable vector, the third argument is the gradient vector, and 2847f296bb3SBarry Smiththe fourth argument is the user-defined application context. Only the 2857f296bb3SBarry Smiththird argument in this routine is different from the arguments in the 2867f296bb3SBarry Smithroutine for evaluating the objective function. The numbers in the 2877f296bb3SBarry Smithgradient vector have no meaning when passed into this routine, but they 2887f296bb3SBarry Smithshould represent the gradient of the objective at the specified point at 2897f296bb3SBarry Smiththe end of the routine. This routine, and the user-defined pointer, can 2907f296bb3SBarry Smithbe passed to the application object by using the 2917f296bb3SBarry Smith 2927f296bb3SBarry Smith``` 293*2a8381b2SBarry SmithTaoSetGradient(Tao, Vec, PetscErrorCode (*)(Tao, Vec, Vec, PetscCtx), PetscCtx); 2947f296bb3SBarry Smith``` 2957f296bb3SBarry Smith 2967f296bb3SBarry Smithroutine. In this routine, the first argument is the Tao object, the second 2977f296bb3SBarry Smithargument is the optional vector to hold the computed gradient, the 2987f296bb3SBarry Smiththird argument is the function pointer, and the fourth object is the 2997f296bb3SBarry Smithapplication context, cast to `(void*)`. 3007f296bb3SBarry Smith 3017f296bb3SBarry SmithInstead of evaluating the objective and its gradient in separate 3027f296bb3SBarry Smithroutines, TAO also allows the user to evaluate the function and the 3037f296bb3SBarry Smithgradient in the same routine. In fact, some solvers are more efficient 3047f296bb3SBarry Smithwhen both function and gradient information can be computed in the same 3057f296bb3SBarry Smithroutine. These routines should follow the form 3067f296bb3SBarry Smith 3077f296bb3SBarry Smith``` 308*2a8381b2SBarry SmithPetscErrorCode EvaluateFunctionAndGradient(Tao, Vec, PetscReal*, Vec, PetscCtx); 3097f296bb3SBarry Smith``` 3107f296bb3SBarry Smith 3117f296bb3SBarry Smithwhere the first argument is the TAO solver and the second argument 3127f296bb3SBarry Smithpoints to the input vector for use in evaluating the function and 3137f296bb3SBarry Smithgradient. The third argument should return the function value, while the 3147f296bb3SBarry Smithfourth argument should return the gradient vector. The fifth argument is 3157f296bb3SBarry Smitha pointer to a user-defined context. This context and the name of the 3167f296bb3SBarry Smithroutine should be set with the call 3177f296bb3SBarry Smith 3187f296bb3SBarry Smith``` 319*2a8381b2SBarry SmithTaoSetObjectiveAndGradient(Tao, Vec PetscErrorCode (*)(Tao, Vec, PetscReal*, Vec, PetscCtx), PetscCtx); 3207f296bb3SBarry Smith``` 3217f296bb3SBarry Smith 3227f296bb3SBarry Smithwhere the arguments are the TAO application, the optional vector to be 3237f296bb3SBarry Smithused to hold the computed gradient, a function pointer, and a 3247f296bb3SBarry Smithpointer to a user-defined context. 3257f296bb3SBarry Smith 3267f296bb3SBarry SmithThe TAO example problems demonstrate the use of these application 3277f296bb3SBarry Smithcontexts as well as specific instances of function, gradient, and 3287f296bb3SBarry SmithHessian evaluation routines. All these routines should return the 3297f296bb3SBarry Smithinteger $0$ after successful completion and a nonzero integer if 3307f296bb3SBarry Smiththe function is undefined at that point or an error occurred. 3317f296bb3SBarry Smith 3327f296bb3SBarry Smith(sec_tao_matrixfree)= 3337f296bb3SBarry Smith 3347f296bb3SBarry Smith#### Hessian Evaluation 3357f296bb3SBarry Smith 3367f296bb3SBarry SmithSome optimization routines also require a Hessian matrix from the user. 3377f296bb3SBarry SmithThe routine that evaluates the Hessian should have the form 3387f296bb3SBarry Smith 3397f296bb3SBarry Smith``` 340*2a8381b2SBarry SmithPetscErrorCode EvaluateHessian(Tao, Vec, Mat, Mat, PetscCtx); 3417f296bb3SBarry Smith``` 3427f296bb3SBarry Smith 3437f296bb3SBarry Smithwhere the first argument of this routine is a TAO solver object. The 3447f296bb3SBarry Smithsecond argument is the point at which the Hessian should be evaluated. 3457f296bb3SBarry SmithThe third argument is the Hessian matrix, and the sixth argument is a 3467f296bb3SBarry Smithuser-defined context. Since the Hessian matrix is usually used in 3477f296bb3SBarry Smithsolving a system of linear equations, a preconditioner for the matrix is 3487f296bb3SBarry Smithoften needed. The fourth argument is the matrix that will be used for 3497f296bb3SBarry Smithpreconditioning the linear system; in most cases, this matrix will be 3507f296bb3SBarry Smiththe same as the Hessian matrix. The fifth argument is the flag used to 3517f296bb3SBarry Smithset the Hessian matrix and linear solver in the routine 3527f296bb3SBarry Smith`KSPSetOperators()`. 3537f296bb3SBarry Smith 3547f296bb3SBarry SmithOne can set the Hessian evaluation routine by calling the 3557f296bb3SBarry Smith 3567f296bb3SBarry Smith``` 357*2a8381b2SBarry SmithTaoSetHessian(Tao, Mat, Mat, PetscErrorCode (*)(Tao, Vec, Mat, Mat, PetscCtx), PetscCtx); 3587f296bb3SBarry Smith``` 3597f296bb3SBarry Smith 3607f296bb3SBarry Smithroutine. The first argument is the TAO Solver object. The second and 3617f296bb3SBarry Smiththird arguments are, respectively, the Mat object where the Hessian will 3627f296bb3SBarry Smithbe stored and the Mat object that will be used for the preconditioning 3637f296bb3SBarry Smith(they may be the same). The fourth argument is the function that 3647f296bb3SBarry Smithevaluates the Hessian, and the fifth argument is a pointer to a 3657f296bb3SBarry Smithuser-defined context, cast to `(void*)`. 3667f296bb3SBarry Smith 3677f296bb3SBarry Smith##### Finite Differences 3687f296bb3SBarry Smith 3697f296bb3SBarry SmithFinite-difference approximations can be used to compute the gradient and 3707f296bb3SBarry Smiththe Hessian of an objective function. These approximations will slow the 3717f296bb3SBarry Smithsolve considerably and are recommended primarily for checking the 3727f296bb3SBarry Smithaccuracy of hand-coded gradients and Hessians. These routines are 3737f296bb3SBarry Smith 3747f296bb3SBarry Smith``` 375*2a8381b2SBarry SmithTaoDefaultComputeGradient(Tao, Vec, Vec, PetscCtx); 3767f296bb3SBarry Smith``` 3777f296bb3SBarry Smith 3787f296bb3SBarry Smithand 3797f296bb3SBarry Smith 3807f296bb3SBarry Smith``` 381*2a8381b2SBarry SmithTaoDefaultComputeHessian(Tao, Vec, Mat, Mat, PetscCtx); 3827f296bb3SBarry Smith``` 3837f296bb3SBarry Smith 3847f296bb3SBarry Smithrespectively. They can be set by using `TaoSetGradient()` and 3857f296bb3SBarry Smith`TaoSetHessian()` or through the options database with the 3867f296bb3SBarry Smithoptions `-tao_fdgrad` and `-tao_fd`, respectively. 3877f296bb3SBarry Smith 3887f296bb3SBarry SmithThe efficiency of the finite-difference Hessian can be improved if the 3897f296bb3SBarry Smithcoloring of the matrix is known. If the application programmer creates a 3907f296bb3SBarry SmithPETSc `MatFDColoring` object, it can be applied to the 3917f296bb3SBarry Smithfinite-difference approximation by setting the Hessian evaluation 3927f296bb3SBarry Smithroutine to 3937f296bb3SBarry Smith 3947f296bb3SBarry Smith``` 395*2a8381b2SBarry SmithTaoDefaultComputeHessianColor(Tao, Vec, Mat, Mat, PetscCtx); 3967f296bb3SBarry Smith``` 3977f296bb3SBarry Smith 3987f296bb3SBarry Smithand using the `MatFDColoring` object as the last (`void *`) argument 3997f296bb3SBarry Smithto `TaoSetHessian()`. 4007f296bb3SBarry Smith 4017f296bb3SBarry SmithOne also can use finite-difference approximations to directly check the 4027f296bb3SBarry Smithcorrectness of the gradient and/or Hessian evaluation routines. This 4037f296bb3SBarry Smithprocess can be initiated from the command line by using the special TAO 4047f296bb3SBarry Smithsolver `tao_fd_test` together with the option `-tao_test_gradient` 4057f296bb3SBarry Smithor `-tao_test_hessian`. 4067f296bb3SBarry Smith 4077f296bb3SBarry Smith##### Matrix-Free Methods 4087f296bb3SBarry Smith 4097f296bb3SBarry SmithTAO fully supports matrix-free methods. The matrices specified in the 4107f296bb3SBarry SmithHessian evaluation routine need not be conventional matrices; instead, 4117f296bb3SBarry Smiththey can point to the data required to implement a particular 4127f296bb3SBarry Smithmatrix-free method. The matrix-free variant is allowed *only* when the 4137f296bb3SBarry Smithlinear systems are solved by an iterative method in combination with no 4147f296bb3SBarry Smithpreconditioning (`PCNONE` or `-pc_type none`), a user-provided 4157addb90fSBarry Smithmatrix from which to construct the preconditioner, or a user-provided preconditioner shell 4167f296bb3SBarry Smith(`PCSHELL`). In other words, matrix-free methods cannot be used if a 4177f296bb3SBarry Smithdirect solver is to be employed. Details about using matrix-free methods 4187f296bb3SBarry Smithare provided in the {doc}`/manual/index`. 4197f296bb3SBarry Smith 4207f296bb3SBarry Smith:::{figure} /images/manual/taofig.svg 4217f296bb3SBarry Smith:name: fig_taocallbacks 4227f296bb3SBarry Smith 4237f296bb3SBarry SmithTao use of PETSc and callbacks 4247f296bb3SBarry Smith::: 4257f296bb3SBarry Smith 4267f296bb3SBarry Smith(sec_tao_bounds)= 4277f296bb3SBarry Smith 4287f296bb3SBarry Smith#### Constraints 4297f296bb3SBarry Smith 4307f296bb3SBarry SmithSome optimization problems also impose constraints on the variables or 4317f296bb3SBarry Smithintermediate application states. The user defines these constraints through 4327f296bb3SBarry Smiththe appropriate TAO interface functions and call-back routines where necessary. 4337f296bb3SBarry Smith 4347f296bb3SBarry Smith##### Variable Bounds 4357f296bb3SBarry Smith 4367f296bb3SBarry SmithThe simplest type of constraint on an optimization problem puts lower or 4377f296bb3SBarry Smithupper bounds on the variables. Vectors that represent lower and upper 4387f296bb3SBarry Smithbounds for each variable can be set with the 4397f296bb3SBarry Smith 4407f296bb3SBarry Smith``` 4417f296bb3SBarry SmithTaoSetVariableBounds(Tao, Vec, Vec); 4427f296bb3SBarry Smith``` 4437f296bb3SBarry Smith 4447f296bb3SBarry Smithcommand. The first vector and second vector should contain the lower and 4457f296bb3SBarry Smithupper bounds, respectively. When no upper or lower bound exists for a 4467f296bb3SBarry Smithvariable, the bound may be set to `PETSC_INFINITY` or `PETSC_NINFINITY`. 4477f296bb3SBarry SmithAfter the two bound vectors have been set, they may be accessed with the 4487f296bb3SBarry Smithcommand `TaoGetVariableBounds()`. 4497f296bb3SBarry Smith 4507f296bb3SBarry SmithSince not all solvers recognize the presence of bound constraints on 4517f296bb3SBarry Smithvariables, the user must be careful to select a solver that acknowledges 4527f296bb3SBarry Smiththese bounds. 4537f296bb3SBarry Smith 4547f296bb3SBarry Smith(sec_tao_programming)= 4557f296bb3SBarry Smith 4567f296bb3SBarry Smith##### General Constraints 4577f296bb3SBarry Smith 4587f296bb3SBarry SmithSome TAO algorithms also support general constraints as a linear or nonlinear 4597f296bb3SBarry Smithfunction of the optimization variables. These constraints can be imposed either 4607f296bb3SBarry Smithas equalities or inequalities. TAO currently does not make any distinctions 4617f296bb3SBarry Smithbetween linear and nonlinear constraints, and implements them through the 4627f296bb3SBarry Smithsame software interfaces. 4637f296bb3SBarry Smith 4647f296bb3SBarry SmithIn the equality constrained case, TAO assumes that the constraints are 4657f296bb3SBarry Smithformulated as $c_e(x) = 0$ and requires the user to implement a call-back 4667f296bb3SBarry Smithroutine for evaluating $c_e(x)$ at a given vector of optimization 4677f296bb3SBarry Smithvariables, 4687f296bb3SBarry Smith 4697f296bb3SBarry Smith``` 470*2a8381b2SBarry SmithPetscErrorCode EvaluateEqualityConstraints(Tao, Vec, Vec, PetscCtx); 4717f296bb3SBarry Smith``` 4727f296bb3SBarry Smith 4737f296bb3SBarry SmithAs in the previous call-back routines, the first argument is the TAO solver 4747f296bb3SBarry Smithobject. The second and third arguments are the vector of optimization variables 4757f296bb3SBarry Smith(input) and vector of equality constraints (output), respectively. The final 4767f296bb3SBarry Smithargument is a pointer to the user-defined application context, cast into 4777f296bb3SBarry Smith`(void*)`. 4787f296bb3SBarry Smith 4797f296bb3SBarry SmithGenerally constrained TAO algorithms also require a second user call-back 4807f296bb3SBarry Smithfunction to compute the constraint Jacobian matrix $\nabla_x c_e(x)$, 4817f296bb3SBarry Smith 4827f296bb3SBarry Smith``` 483*2a8381b2SBarry SmithPetscErrorCode EvaluateEqualityJacobian(Tao, Vec, Mat, Mat, PetscCtx); 4847f296bb3SBarry Smith``` 4857f296bb3SBarry Smith 4867f296bb3SBarry Smithwhere the first and last arguments are the TAO solver object and the application 4877f296bb3SBarry Smithcontext pointer as before. The second argument is the vector of optimization 4887f296bb3SBarry Smithvariables at which the computation takes place. The third and fourth arguments 4897f296bb3SBarry Smithare the constraint Jacobian and its pseudo-inverse (optional), respectively. The 4907f296bb3SBarry Smithpseudoinverse is optional, and if not available, the user can simply set it 4917f296bb3SBarry Smithto the constraint Jacobian itself. 4927f296bb3SBarry Smith 4937f296bb3SBarry SmithThese call-back functions are then given to the TAO solver using the 4947f296bb3SBarry Smithinterface functions 4957f296bb3SBarry Smith 4967f296bb3SBarry Smith``` 497*2a8381b2SBarry SmithTaoSetEqualityConstraintsRoutine(Tao, Vec, PetscErrorCode (*)(Tao, Vec, Vec, PetscCtx), PetscCtx); 4987f296bb3SBarry Smith``` 4997f296bb3SBarry Smith 5007f296bb3SBarry Smithand 5017f296bb3SBarry Smith 5027f296bb3SBarry Smith``` 503*2a8381b2SBarry SmithTaoSetJacobianEqualityRoutine(Tao, Mat, Mat, PetscErrorCode (*)(Tao, Vec, Mat, Mat, PetscCtx, PetscCtx); 5047f296bb3SBarry Smith``` 5057f296bb3SBarry Smith 506dd1e8424Spaul.kuehnerInequality constraints are assumed to be formulated as $c_i(x) \geq 0$ 5077f296bb3SBarry Smithand follow the same workflow as equality constraints using the 5087f296bb3SBarry Smith`TaoSetInequalityConstraintsRoutine()` and `TaoSetJacobianInequalityRoutine()` 5097f296bb3SBarry Smithinterfaces. 5107f296bb3SBarry Smith 5117f296bb3SBarry SmithSome TAO algorithms may adopt an alternative double-sided 5127f296bb3SBarry Smith$c_l \leq c_i(x) \leq c_u$ formulation and require the lower and upper 5137f296bb3SBarry Smithbounds $c_l$ and $c_u$ to be set using the 5147f296bb3SBarry Smith`TaoSetInequalityBounds(Tao, Vec, Vec)` interface. Please refer to the 5157f296bb3SBarry Smithdocumentation for each TAO algorithm for further details. 5167f296bb3SBarry Smith 5177f296bb3SBarry Smith### Solving 5187f296bb3SBarry Smith 5197f296bb3SBarry SmithOnce the application and solver have been set up, the solver can be 5207f296bb3SBarry Smith 5217f296bb3SBarry Smith``` 5227f296bb3SBarry SmithTaoSolve(Tao); 5237f296bb3SBarry Smith``` 5247f296bb3SBarry Smith 5257f296bb3SBarry Smithroutine. We discuss several universal options below. 5267f296bb3SBarry Smith 5277f296bb3SBarry Smith(sec_tao_customize)= 5287f296bb3SBarry Smith 5297f296bb3SBarry Smith#### Convergence 5307f296bb3SBarry Smith 5317f296bb3SBarry SmithAlthough TAO and its solvers set default parameters that are useful for 5327f296bb3SBarry Smithmany problems, the user may need to modify these parameters in order to 5337f296bb3SBarry Smithchange the behavior and convergence of various algorithms. 5347f296bb3SBarry Smith 5357f296bb3SBarry SmithOne convergence criterion for most algorithms concerns the number of 5367f296bb3SBarry Smithdigits of accuracy needed in the solution. In particular, the 5377f296bb3SBarry Smithconvergence test employed by TAO attempts to stop when the error in the 5387f296bb3SBarry Smithconstraints is less than $\epsilon_{crtol}$ and either 5397f296bb3SBarry Smith 5407f296bb3SBarry Smith$$ 5417f296bb3SBarry Smith\begin{array}{lcl} 5427f296bb3SBarry Smith||g(X)|| &\leq& \epsilon_{gatol}, \\ 5437f296bb3SBarry Smith||g(X)||/|f(X)| &\leq& \epsilon_{grtol}, \quad \text{or} \\ 5447f296bb3SBarry Smith||g(X)||/|g(X_0)| &\leq& \epsilon_{gttol}, 5457f296bb3SBarry Smith\end{array} 5467f296bb3SBarry Smith$$ 5477f296bb3SBarry Smith 5487f296bb3SBarry Smithwhere $X$ is the current approximation to the true solution 5497f296bb3SBarry Smith$X^*$ and $X_0$ is the initial guess. $X^*$ is 5507f296bb3SBarry Smithunknown, so TAO estimates $f(X) - f(X^*)$ with either the square 5517f296bb3SBarry Smithof the norm of the gradient or the duality gap. A relative tolerance of 5527f296bb3SBarry Smith$\epsilon_{frtol}=0.01$ indicates that two significant digits are 5537f296bb3SBarry Smithdesired in the objective function. Each solver sets its own convergence 5547f296bb3SBarry Smithtolerances, but they can be changed by using the routine 5557f296bb3SBarry Smith`TaoSetTolerances()`. Another set of convergence tolerances terminates 5567f296bb3SBarry Smiththe solver when the norm of the gradient function (or Lagrangian 5577f296bb3SBarry Smithfunction for bound-constrained problems) is sufficiently close to zero. 5587f296bb3SBarry Smith 5597f296bb3SBarry SmithOther stopping criteria include a minimum trust-region radius or a 5607f296bb3SBarry Smithmaximum number of iterations. These parameters can be set with the 5617f296bb3SBarry Smithroutines `TaoSetTrustRegionTolerance()` and 5627f296bb3SBarry Smith`TaoSetMaximumIterations()` Similarly, a maximum number of function 5637f296bb3SBarry Smithevaluations can be set with the command 5647f296bb3SBarry Smith`TaoSetMaximumFunctionEvaluations()`. `-tao_max_it`, and 5657f296bb3SBarry Smith`-tao_max_funcs`. 5667f296bb3SBarry Smith 5677f296bb3SBarry Smith#### Viewing Status 5687f296bb3SBarry Smith 5697f296bb3SBarry SmithTo see parameters and performance statistics for the solver, the routine 5707f296bb3SBarry Smith 5717f296bb3SBarry Smith``` 5727f296bb3SBarry SmithTaoView(Tao tao) 5737f296bb3SBarry Smith``` 5747f296bb3SBarry Smith 5757f296bb3SBarry Smithcan be used. This routine will display to standard output the number of 5767f296bb3SBarry Smithfunction evaluations need by the solver and other information specific 5777f296bb3SBarry Smithto the solver. This same output can be produced by using the command 5787f296bb3SBarry Smithline option `-tao_view`. 5797f296bb3SBarry Smith 5807f296bb3SBarry SmithThe progress of the optimization solver can be monitored with the 5817f296bb3SBarry Smithruntime option `-tao_monitor`. Although monitoring routines can be 5827f296bb3SBarry Smithcustomized, the default monitoring routine will print out several 5837f296bb3SBarry Smithrelevant statistics to the screen. 5847f296bb3SBarry Smith 5857f296bb3SBarry SmithThe user also has access to information about the current solution. The 5867f296bb3SBarry Smithcurrent iteration number, objective function value, gradient norm, 5877f296bb3SBarry Smithinfeasibility norm, and step length can be retrieved with the following 5887f296bb3SBarry Smithcommand. 5897f296bb3SBarry Smith 5907f296bb3SBarry Smith``` 5917f296bb3SBarry SmithTaoGetSolutionStatus(Tao tao, PetscInt* iterate, PetscReal* f, 5927f296bb3SBarry Smith PetscReal* gnorm, PetscReal* cnorm, PetscReal* xdiff, 5937f296bb3SBarry Smith TaoConvergedReason* reason) 5947f296bb3SBarry Smith``` 5957f296bb3SBarry Smith 5967f296bb3SBarry SmithThe last argument returns a code that indicates the reason that the 5977f296bb3SBarry Smithsolver terminated. Positive numbers indicate that a solution has been 5987f296bb3SBarry Smithfound, while negative numbers indicate a failure. A list of reasons can 5997f296bb3SBarry Smithbe found in the manual page for `TaoGetConvergedReason()`. 6007f296bb3SBarry Smith 6017f296bb3SBarry Smith#### Obtaining a Solution 6027f296bb3SBarry Smith 6037f296bb3SBarry SmithAfter exiting the `TaoSolve()` function, the solution and the gradient can be 6047f296bb3SBarry Smithrecovered with the following routines. 6057f296bb3SBarry Smith 6067f296bb3SBarry Smith``` 6077f296bb3SBarry SmithTaoGetSolution(Tao, Vec*); 6087f296bb3SBarry SmithTaoGetGradient(Tao, Vec*, NULL, NULL); 6097f296bb3SBarry Smith``` 6107f296bb3SBarry Smith 6117f296bb3SBarry SmithNote that the `Vec` returned by `TaoGetSolution()` will be the 6127f296bb3SBarry Smithsame vector passed to `TaoSetSolution()`. This information can be 6137f296bb3SBarry Smithobtained during user-defined routines such as a function evaluation and 6147f296bb3SBarry Smithcustomized monitoring routine or after the solver has terminated. 6157f296bb3SBarry Smith 6167f296bb3SBarry Smith### Special Problem structures 6177f296bb3SBarry Smith 6187f296bb3SBarry SmithCertain special classes of problems solved with TAO utilize specialized 6197f296bb3SBarry Smithcode interfaces that are described below per problem type. 6207f296bb3SBarry Smith 6217f296bb3SBarry Smith(sec_tao_pde_constrained)= 6227f296bb3SBarry Smith 6237f296bb3SBarry Smith#### PDE-constrained Optimization 6247f296bb3SBarry Smith 6257f296bb3SBarry SmithTAO solves PDE-constrained optimization problems of the form 6267f296bb3SBarry Smith 6277f296bb3SBarry Smith$$ 6287f296bb3SBarry Smith\begin{array}{ll} 6297f296bb3SBarry Smith\displaystyle \min_{u,v} & f(u,v) \\ 6307f296bb3SBarry Smith\text{subject to} & g(u,v) = 0, 6317f296bb3SBarry Smith\end{array} 6327f296bb3SBarry Smith$$ 6337f296bb3SBarry Smith 6347f296bb3SBarry Smithwhere the state variable $u$ is the solution to the discretized 6357f296bb3SBarry Smithpartial differential equation defined by $g$ and parametrized by 6367f296bb3SBarry Smiththe design variable $v$, and $f$ is an objective function. 6377f296bb3SBarry SmithThe Lagrange multipliers on the constraint are denoted by $y$. 6387f296bb3SBarry SmithThis method is set by using the linearly constrained augmented 6397f296bb3SBarry SmithLagrangian TAO solver `tao_lcl`. 6407f296bb3SBarry Smith 6417f296bb3SBarry SmithWe make two main assumptions when solving these problems: the objective 6427f296bb3SBarry Smithfunction and PDE constraints have been discretized so that we can treat 6437f296bb3SBarry Smiththe optimization problem as finite dimensional and 6447f296bb3SBarry Smith$\nabla_u g(u,v)$ is invertible for all $u$ and $v$. 6457f296bb3SBarry Smith 6467f296bb3SBarry SmithUnlike other TAO solvers where the solution vector contains only the 6477f296bb3SBarry Smithoptimization variables, PDE-constrained problems solved with `tao_lcl` 6487f296bb3SBarry Smithcombine the design and state variables together in a monolithic solution vector 6497f296bb3SBarry Smith$x^T = [u^T, v^T]$. Consequently, the user must provide index sets to 6507f296bb3SBarry Smithseparate the two, 6517f296bb3SBarry Smith 6527f296bb3SBarry Smith``` 6537f296bb3SBarry SmithTaoSetStateDesignIS(Tao, IS, IS); 6547f296bb3SBarry Smith``` 6557f296bb3SBarry Smith 6567f296bb3SBarry Smithwhere the first IS is a PETSc IndexSet containing the indices of the 6577f296bb3SBarry Smithstate variables and the second IS the design variables. 6587f296bb3SBarry Smith 6597f296bb3SBarry SmithPDE constraints have the general form $g(x) = 0$, 6607f296bb3SBarry Smithwhere $c: \mathbb R^n \to \mathbb R^m$. These constraints should 6617f296bb3SBarry Smithbe specified in a routine, written by the user, that evaluates 6627f296bb3SBarry Smith$g(x)$. The routine that evaluates the constraint equations 6637f296bb3SBarry Smithshould have the form 6647f296bb3SBarry Smith 6657f296bb3SBarry Smith``` 666*2a8381b2SBarry SmithPetscErrorCode EvaluateConstraints(Tao, Vec, Vec, PetscCtx); 6677f296bb3SBarry Smith``` 6687f296bb3SBarry Smith 6697f296bb3SBarry SmithThe first argument of this routine is a TAO solver object. The second 6707f296bb3SBarry Smithargument is the variable vector at which the constraint function should 6717f296bb3SBarry Smithbe evaluated. The third argument is the vector of function values 6727f296bb3SBarry Smith$g(x)$, and the fourth argument is a pointer to a user-defined 6737f296bb3SBarry Smithcontext. This routine and the user-defined context should be set in the 6747f296bb3SBarry SmithTAO solver with the 6757f296bb3SBarry Smith 6767f296bb3SBarry Smith``` 677*2a8381b2SBarry SmithTaoSetConstraintsRoutine(Tao, Vec, PetscErrorCode (*)(Tao, Vec, Vec, PetscCtx), PetscCtx); 6787f296bb3SBarry Smith``` 6797f296bb3SBarry Smith 6807f296bb3SBarry Smithcommand. In this function, the first argument is the TAO solver object, 6817f296bb3SBarry Smiththe second argument a vector in which to store the constraints, the 6827f296bb3SBarry Smiththird argument is a function point to the routine for evaluating the 6837f296bb3SBarry Smithconstraints, and the fourth argument is a pointer to a user-defined 6847f296bb3SBarry Smithcontext. 6857f296bb3SBarry Smith 6867f296bb3SBarry SmithThe Jacobian of $g(x)$ is the matrix in 6877f296bb3SBarry Smith$\mathbb R^{m \times n}$ such that each column contains the 6887f296bb3SBarry Smithpartial derivatives of $g(x)$ with respect to one variable. The 6897f296bb3SBarry Smithevaluation of the Jacobian of $g$ should be performed by calling 6907f296bb3SBarry Smiththe 6917f296bb3SBarry Smith 6927f296bb3SBarry Smith``` 693*2a8381b2SBarry SmithPetscErrorCode JacobianState(Tao, Vec, Mat, Mat, Mat, PetscCtx); 694*2a8381b2SBarry SmithPetscErrorCode JacobianDesign(Tao, Vec, Mat*, PetscCtx); 6957f296bb3SBarry Smith``` 6967f296bb3SBarry Smith 6977f296bb3SBarry Smithroutines. In these functions, The first argument is the TAO solver 6987f296bb3SBarry Smithobject. The second argument is the variable vector at which to evaluate 6997f296bb3SBarry Smiththe Jacobian matrix, the third argument is the Jacobian matrix, and the 7007f296bb3SBarry Smithlast argument is a pointer to a user-defined context. The fourth and 7017f296bb3SBarry Smithfifth arguments of the Jacobian evaluation with respect to the state 7027f296bb3SBarry Smithvariables are for providing PETSc matrix objects for the preconditioner 7037f296bb3SBarry Smithand for applying the inverse of the state Jacobian, respectively. This 7047f296bb3SBarry Smithinverse matrix may be `PETSC_NULL`, in which case TAO will use a PETSc 7057f296bb3SBarry SmithKrylov subspace solver to solve the state system. These evaluation 7067f296bb3SBarry Smithroutines should be registered with TAO by using the 7077f296bb3SBarry Smith 7087f296bb3SBarry Smith``` 7097f296bb3SBarry SmithTaoSetJacobianStateRoutine(Tao, Mat, Mat, Mat, 710*2a8381b2SBarry Smith PetscErrorCode (*)(Tao, Vec, Mat, Mat, PetscCtx), 711*2a8381b2SBarry Smith PetscCtx); 7127f296bb3SBarry SmithTaoSetJacobianDesignRoutine(Tao, Mat, 713*2a8381b2SBarry Smith PetscErrorCode (*)(Tao, Vec, Mat*, PetscCtx), 714*2a8381b2SBarry Smith PetscCtx); 7157f296bb3SBarry Smith``` 7167f296bb3SBarry Smith 7177f296bb3SBarry Smithroutines. The first argument is the TAO solver object, and the second 7187f296bb3SBarry Smithargument is the matrix in which the Jacobian information can be stored. 7197f296bb3SBarry SmithFor the state Jacobian, the third argument is the matrix that will be 7207f296bb3SBarry Smithused for preconditioning, and the fourth argument is an optional matrix 7217f296bb3SBarry Smithfor the inverse of the state Jacobian. One can use `PETSC_NULL` for 7227f296bb3SBarry Smiththis inverse argument and let PETSc apply the inverse using a KSP 7237f296bb3SBarry Smithmethod, but faster results may be obtained by manipulating the structure 7247f296bb3SBarry Smithof the Jacobian and providing an inverse. The fifth argument is the 7257f296bb3SBarry Smithfunction pointer, and the sixth argument is an optional user-defined 7267f296bb3SBarry Smithcontext. Since no solve is performed with the design Jacobian, there is 7277f296bb3SBarry Smithno need to provide preconditioner or inverse matrices. 7287f296bb3SBarry Smith 7297f296bb3SBarry Smith(sec_tao_evalsof)= 7307f296bb3SBarry Smith 7317f296bb3SBarry Smith#### Nonlinear Least Squares 7327f296bb3SBarry Smith 7337f296bb3SBarry SmithFor nonlinear least squares applications, we are solving the 7347f296bb3SBarry Smithoptimization problem 7357f296bb3SBarry Smith 7367f296bb3SBarry Smith$$ 7377f296bb3SBarry Smith\min_{x} \;\frac{1}{2}||r(x)||_2^2. 7387f296bb3SBarry Smith$$ 7397f296bb3SBarry Smith 7407f296bb3SBarry SmithFor these problems, the objective function value should be computed as a 7417f296bb3SBarry Smithvector of residuals, $r(x)$, computed with a function of the form 7427f296bb3SBarry Smith 7437f296bb3SBarry Smith``` 744*2a8381b2SBarry SmithPetscErrorCode EvaluateResidual(Tao, Vec, Vec, PetscCtx); 7457f296bb3SBarry Smith``` 7467f296bb3SBarry Smith 7477f296bb3SBarry Smithand set with the 7487f296bb3SBarry Smith 7497f296bb3SBarry Smith``` 750*2a8381b2SBarry SmithTaoSetResidualRoutine(Tao, PetscErrorCode (*)(Tao, Vec, Vec, PetscCtx), PetscCtx); 7517f296bb3SBarry Smith``` 7527f296bb3SBarry Smith 7537f296bb3SBarry Smithroutine. If required by the algorithm, the Jacobian of the residual, 7547f296bb3SBarry Smith$J = \partial r(x) / \partial x$, should be computed with a 7557f296bb3SBarry Smithfunction of the form 7567f296bb3SBarry Smith 7577f296bb3SBarry Smith``` 758*2a8381b2SBarry SmithPetscErrorCode EvaluateJacobian(Tao, Vec, Mat, PetscCtx; 7597f296bb3SBarry Smith``` 7607f296bb3SBarry Smith 7617f296bb3SBarry Smithand set with the 7627f296bb3SBarry Smith 7637f296bb3SBarry Smith``` 764*2a8381b2SBarry SmithTaoSetJacobianResidualRoutine(Tao, PetscErrorCode (*)(Tao, Vec, Mat, PetscCtx), PetscCtx); 7657f296bb3SBarry Smith``` 7667f296bb3SBarry Smith 7677f296bb3SBarry Smithroutine. 7687f296bb3SBarry Smith 7697f296bb3SBarry Smith(sec_tao_complementary)= 7707f296bb3SBarry Smith 7717f296bb3SBarry Smith#### Complementarity 7727f296bb3SBarry Smith 7737f296bb3SBarry SmithComplementarity applications have equality constraints in the form of 7747f296bb3SBarry Smithnonlinear equations $C(X) = 0$, where 7757f296bb3SBarry Smith$C: \mathbb R^n \to \mathbb R^m$. These constraints should be 7767f296bb3SBarry Smithspecified in a routine written by the user with the form 7777f296bb3SBarry Smith 7787f296bb3SBarry Smith``` 779*2a8381b2SBarry SmithPetscErrorCode EqualityConstraints(Tao, Vec, Vec, PetscCtx); 7807f296bb3SBarry Smith``` 7817f296bb3SBarry Smith 7827f296bb3SBarry Smiththat evaluates $C(X)$. The first argument of this routine is a TAO 7837f296bb3SBarry SmithSolver object. The second argument is the variable vector $X$ at 7847f296bb3SBarry Smithwhich the constraint function should be evaluated. The third argument is 7857f296bb3SBarry Smiththe output vector of function values $C(X)$, and the fourth 7867f296bb3SBarry Smithargument is a pointer to a user-defined context. 7877f296bb3SBarry Smith 7887f296bb3SBarry SmithThis routine and the user-defined context must be registered with TAO by 7897f296bb3SBarry Smithusing the 7907f296bb3SBarry Smith 7917f296bb3SBarry Smith``` 792*2a8381b2SBarry SmithTaoSetConstraintRoutine(Tao, Vec, PetscErrorCode (*)(Tao, Vec, Vec, PetscCtx), PetscCtx); 7937f296bb3SBarry Smith``` 7947f296bb3SBarry Smith 7957f296bb3SBarry Smithcommand. In this command, the first argument is TAO Solver object, the 7967f296bb3SBarry Smithsecond argument is vector in which to store the function values, the 7977f296bb3SBarry Smiththird argument is the user-defined routine that evaluates $C(X)$, 7987f296bb3SBarry Smithand the fourth argument is a pointer to a user-defined context that will 7997f296bb3SBarry Smithbe passed back to the user. 8007f296bb3SBarry Smith 8017f296bb3SBarry SmithThe Jacobian of the function is the matrix in 8027f296bb3SBarry Smith$\mathbb R^{m \times n}$ such that each column contains the 8037f296bb3SBarry Smithpartial derivatives of $f$ with respect to one variable. The 8047f296bb3SBarry Smithevaluation of the Jacobian of $C$ should be performed in a routine 8057f296bb3SBarry Smithof the form 8067f296bb3SBarry Smith 8077f296bb3SBarry Smith``` 808*2a8381b2SBarry SmithPetscErrorCode EvaluateJacobian(Tao, Vec, Mat, Mat, PetscCtx); 8097f296bb3SBarry Smith``` 8107f296bb3SBarry Smith 8117f296bb3SBarry SmithIn this function, the first argument is the TAO Solver object and the 8127f296bb3SBarry Smithsecond argument is the variable vector at which to evaluate the Jacobian 8137f296bb3SBarry Smithmatrix. The third argument is the Jacobian matrix, and the sixth 8147f296bb3SBarry Smithargument is a pointer to a user-defined context. Since the Jacobian 8157f296bb3SBarry Smithmatrix may be used in solving a system of linear equations, a 8167f296bb3SBarry Smithpreconditioner for the matrix may be needed. The fourth argument is the 8177f296bb3SBarry Smithmatrix that will be used for preconditioning the linear system; in most 8187f296bb3SBarry Smithcases, this matrix will be the same as the Hessian matrix. The fifth 8197f296bb3SBarry Smithargument is the flag used to set the Jacobian matrix and linear solver 8207f296bb3SBarry Smithin the routine `KSPSetOperators()`. 8217f296bb3SBarry Smith 8227f296bb3SBarry SmithThis routine should be specified to TAO by using the 8237f296bb3SBarry Smith 8247f296bb3SBarry Smith``` 825*2a8381b2SBarry SmithTaoSetJacobianRoutine(Tao, Mat, Mat, PetscErrorCode (*)(Tao, Vec, Mat, Mat, PetscCtx), PetscCtx); 8267f296bb3SBarry Smith``` 8277f296bb3SBarry Smith 8287f296bb3SBarry Smithcommand. The first argument is the TAO Solver object; the second and 8297f296bb3SBarry Smiththird arguments are the Mat objects in which the Jacobian will be stored 8307f296bb3SBarry Smithand the Mat object that will be used for the preconditioning (they may 8317f296bb3SBarry Smithbe the same), respectively. The fourth argument is the function pointer; 8327f296bb3SBarry Smithand the fifth argument is an optional user-defined context. The Jacobian 8337f296bb3SBarry Smithmatrix should be created in a way such that the product of it and the 8347f296bb3SBarry Smithvariable vector can be stored in the constraint vector. 8357f296bb3SBarry Smith 8367f296bb3SBarry Smith(sec_tao_solvers)= 8377f296bb3SBarry Smith 8387f296bb3SBarry Smith## TAO Algorithms 8397f296bb3SBarry Smith 8407f296bb3SBarry SmithTAO includes a variety of optimization algorithms for several classes of 8417f296bb3SBarry Smithproblems (unconstrained, bound-constrained, and PDE-constrained 8427f296bb3SBarry Smithminimization, nonlinear least-squares, and complementarity). The TAO 8437f296bb3SBarry Smithalgorithms for solving these problems are detailed in this section, a 8447f296bb3SBarry Smithparticular algorithm can chosen by using the `TaoSetType()` function 8457f296bb3SBarry Smithor using the command line arguments `-tao_type <name>`. For those 8467f296bb3SBarry Smithinterested in extending these algorithms or using new ones, please see 8477f296bb3SBarry Smith{any}`sec_tao_addsolver` for more information. 8487f296bb3SBarry Smith 8497f296bb3SBarry Smith(sec_tao_unconstrained)= 8507f296bb3SBarry Smith 8517f296bb3SBarry Smith### Unconstrained Minimization 8527f296bb3SBarry Smith 8537f296bb3SBarry SmithUnconstrained minimization is used to minimize a function of many 8547f296bb3SBarry Smithvariables without any constraints on the variables, such as bounds. The 8557f296bb3SBarry Smithmethods available in TAO for solving these problems can be classified 8567f296bb3SBarry Smithaccording to the amount of derivative information required: 8577f296bb3SBarry Smith 8587f296bb3SBarry Smith1. Function evaluation only – Nelder-Mead method (`tao_nm`) 8597f296bb3SBarry Smith2. Function and gradient evaluations – limited-memory, variable-metric 8607f296bb3SBarry Smith method (`tao_lmvm`) and nonlinear conjugate gradient method 8617f296bb3SBarry Smith (`tao_cg`) 8627f296bb3SBarry Smith3. Function, gradient, and Hessian evaluations – Newton Krylov methods: 8637f296bb3SBarry Smith Newton line search (`tao_nls`), Newton trust-region (`tao_ntr`), 8647f296bb3SBarry Smith and Newton trust-region line-search (`tao_ntl`) 8657f296bb3SBarry Smith 8667f296bb3SBarry SmithThe best method to use depends on the particular problem being solved 8677f296bb3SBarry Smithand the accuracy required in the solution. If a Hessian evaluation 8687f296bb3SBarry Smithroutine is available, then the Newton line search and Newton 8697f296bb3SBarry Smithtrust-region methods will likely perform best. When a Hessian evaluation 8707f296bb3SBarry Smithroutine is not available, then the limited-memory, variable-metric 8717f296bb3SBarry Smithmethod is likely to perform best. The Nelder-Mead method should be used 8727f296bb3SBarry Smithonly as a last resort when no gradient information is available. 8737f296bb3SBarry Smith 8747f296bb3SBarry SmithEach solver has a set of options associated with it that can be set with 8757f296bb3SBarry Smithcommand line arguments. These algorithms and the associated options are 8767f296bb3SBarry Smithbriefly discussed in this section. 8777f296bb3SBarry Smith 8787f296bb3SBarry Smith#### Newton-Krylov Methods 8797f296bb3SBarry Smith 8807f296bb3SBarry SmithTAO features three Newton-Krylov algorithms, separated by their globalization methods 8817f296bb3SBarry Smithfor unconstrained optimization: line search (NLS), trust region (NTR), and trust 8827f296bb3SBarry Smithregion with a line search (NTL). They are available via the TAO solvers 8837f296bb3SBarry Smith`TAONLS`, `TAONTR` and `TAONTL`, respectively, or the `-tao_type` 8847f296bb3SBarry Smith`nls`/`ntr`/`ntl` flag. 8857f296bb3SBarry Smith 8867f296bb3SBarry Smith##### Newton Line Search Method (NLS) 8877f296bb3SBarry Smith 8887f296bb3SBarry SmithThe Newton line search method solves the symmetric system of equations 8897f296bb3SBarry Smith 8907f296bb3SBarry Smith$$ 8917f296bb3SBarry SmithH_k d_k = -g_k 8927f296bb3SBarry Smith$$ 8937f296bb3SBarry Smith 8947f296bb3SBarry Smithto obtain a step $d_k$, where $H_k$ is the Hessian of the 8957f296bb3SBarry Smithobjective function at $x_k$ and $g_k$ is the gradient of the 8967f296bb3SBarry Smithobjective function at $x_k$. For problems where the Hessian matrix 8977f296bb3SBarry Smithis indefinite, the perturbed system of equations 8987f296bb3SBarry Smith 8997f296bb3SBarry Smith$$ 9007f296bb3SBarry Smith(H_k + \rho_k I) d_k = -g_k 9017f296bb3SBarry Smith$$ 9027f296bb3SBarry Smith 9037f296bb3SBarry Smithis solved to obtain the direction, where $\rho_k$ is a positive 9047f296bb3SBarry Smithconstant. If the direction computed is not a descent direction, the 9057f296bb3SBarry Smith(scaled) steepest descent direction is used instead. Having obtained the 9067f296bb3SBarry Smithdirection, a Moré-Thuente line search is applied to obtain a step 9077f296bb3SBarry Smithlength, $\tau_k$, that approximately solves the one-dimensional 9087f296bb3SBarry Smithoptimization problem 9097f296bb3SBarry Smith 9107f296bb3SBarry Smith$$ 9117f296bb3SBarry Smith\min_\tau f(x_k + \tau d_k). 9127f296bb3SBarry Smith$$ 9137f296bb3SBarry Smith 9147f296bb3SBarry SmithThe Newton line search method can be selected by using the TAO solver 9157f296bb3SBarry Smith`tao_nls`. The options available for this solver are listed in 9167f296bb3SBarry Smith{numref}`table_nlsoptions`. For the best efficiency, function and 9177f296bb3SBarry Smithgradient evaluations should be performed simultaneously when using this 9187f296bb3SBarry Smithalgorithm. 9197f296bb3SBarry Smith 9207f296bb3SBarry Smith> ```{eval-rst} 9217f296bb3SBarry Smith> .. table:: Summary of ``nls`` options 9227f296bb3SBarry Smith> :name: table_nlsoptions 9237f296bb3SBarry Smith> 9247f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 9257f296bb3SBarry Smith> | Name ``-tao_nls_`` | Value | Default | Description | 9267f296bb3SBarry Smith> +==========================+================+====================+====================+ 9277f296bb3SBarry Smith> | ``ksp_type`` | cg, nash, | stcg | KSPType for | 9287f296bb3SBarry Smith> | | | | linear system | 9297f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 9307f296bb3SBarry Smith> | ``pc_type`` | none, jacobi | lmvm | PCType for linear | 9317f296bb3SBarry Smith> | | | | system | 9327f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 9337f296bb3SBarry Smith> | ``sval`` | real | :math:`0` | Initial | 9347f296bb3SBarry Smith> | | | | perturbation | 9357f296bb3SBarry Smith> | | | | value | 9367f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 9377f296bb3SBarry Smith> | ``imin`` | real | :math:`10^{-4}` | Minimum | 9387f296bb3SBarry Smith> | | | | initial | 9397f296bb3SBarry Smith> | | | | perturbation | 9407f296bb3SBarry Smith> | | | | value | 9417f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 9427f296bb3SBarry Smith> | ``imax`` | real | :math:`100` | Maximum | 9437f296bb3SBarry Smith> | | | | initial | 9447f296bb3SBarry Smith> | | | | perturbation | 9457f296bb3SBarry Smith> | | | | value | 9467f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 9477f296bb3SBarry Smith> | ``imfac`` | real | :math:`0.1` | Gradient norm | 9487f296bb3SBarry Smith> | | | | factor when | 9497f296bb3SBarry Smith> | | | | initializing | 9507f296bb3SBarry Smith> | | | | perturbation | 9517f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 9527f296bb3SBarry Smith> | ``pmax`` | real | :math:`100` | Maximum | 9537f296bb3SBarry Smith> | | | | perturbation | 9547f296bb3SBarry Smith> | | | | when | 9557f296bb3SBarry Smith> | | | | increasing | 9567f296bb3SBarry Smith> | | | | value | 9577f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 9587f296bb3SBarry Smith> | ``pgfac`` | real | :math:`10` | Perturbation growth| 9597f296bb3SBarry Smith> | | | | when | 9607f296bb3SBarry Smith> | | | | increasing | 9617f296bb3SBarry Smith> | | | | value | 9627f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 9637f296bb3SBarry Smith> | ``pmgfac`` | real | :math:`0.1` | Gradient norm | 9647f296bb3SBarry Smith> | | | | factor when | 9657f296bb3SBarry Smith> | | | | increasing | 9667f296bb3SBarry Smith> | | | | perturbation | 9677f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 9687f296bb3SBarry Smith> | ``pmin`` | real | :math:`10^{-12}` | Minimum non-zero | 9697f296bb3SBarry Smith> | | | | perturbation | 9707f296bb3SBarry Smith> | | | | when | 9717f296bb3SBarry Smith> | | | | decreasing | 9727f296bb3SBarry Smith> | | | | value | 9737f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 9747f296bb3SBarry Smith> | ``psfac`` | real | :math:`0.4` | Perturbation shrink| 9757f296bb3SBarry Smith> | | | | factor when | 9767f296bb3SBarry Smith> | | | | decreasing | 9777f296bb3SBarry Smith> | | | | value | 9787f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 9797f296bb3SBarry Smith> | ``pmsfac`` | real | :math:`0.1` | Gradient norm | 9807f296bb3SBarry Smith> | | | | factor when | 9817f296bb3SBarry Smith> | | | | decreasing | 9827f296bb3SBarry Smith> | | | | perturbation | 9837f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 9847f296bb3SBarry Smith> | ``nu1`` | real | 0.25 | :math:`\nu_1` | 9857f296bb3SBarry Smith> | | | | in ``step`` | 9867f296bb3SBarry Smith> | | | | update | 9877f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 9887f296bb3SBarry Smith> | ``nu2`` | real | 0.50 | :math:`\nu_2` | 9897f296bb3SBarry Smith> | | | | in ``step`` | 9907f296bb3SBarry Smith> | | | | update | 9917f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 9927f296bb3SBarry Smith> | ``nu3`` | real | 1.00 | :math:`\nu_3` | 9937f296bb3SBarry Smith> | | | | in ``step`` | 9947f296bb3SBarry Smith> | | | | update | 9957f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 9967f296bb3SBarry Smith> | ``nu4`` | real | 1.25 | :math:`\nu_4` | 9977f296bb3SBarry Smith> | | | | in ``step`` | 9987f296bb3SBarry Smith> | | | | update | 9997f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10007f296bb3SBarry Smith> | ``omega1`` | real | 0.25 | :math:`\omega_1` | 10017f296bb3SBarry Smith> | | | | in ``step`` | 10027f296bb3SBarry Smith> | | | | update | 10037f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10047f296bb3SBarry Smith> | ``omega2`` | real | 0.50 | :math:`\omega_2` | 10057f296bb3SBarry Smith> | | | | in ``step`` | 10067f296bb3SBarry Smith> | | | | update | 10077f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10087f296bb3SBarry Smith> | ``omega3`` | real | 1.00 | :math:`\omega_3` | 10097f296bb3SBarry Smith> | | | | in ``step`` | 10107f296bb3SBarry Smith> | | | | update | 10117f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10127f296bb3SBarry Smith> | ``omega4`` | real | 2.00 | :math:`\omega_4` | 10137f296bb3SBarry Smith> | | | | in ``step`` | 10147f296bb3SBarry Smith> | | | | update | 10157f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10167f296bb3SBarry Smith> | ``omega5`` | real | 4.00 | :math:`\omega_5` | 10177f296bb3SBarry Smith> | | | | in ``step`` | 10187f296bb3SBarry Smith> | | | | update | 10197f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10207f296bb3SBarry Smith> | ``eta1`` | real | :math:`10^{-4}` | :math:`\eta_1` | 10217f296bb3SBarry Smith> | | | | in | 10227f296bb3SBarry Smith> | | | | ``reduction`` | 10237f296bb3SBarry Smith> | | | | update | 10247f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10257f296bb3SBarry Smith> | ``eta2`` | real | 0.25 | :math:`\eta_2` | 10267f296bb3SBarry Smith> | | | | in | 10277f296bb3SBarry Smith> | | | | ``reduction`` | 10287f296bb3SBarry Smith> | | | | update | 10297f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10307f296bb3SBarry Smith> | ``eta3`` | real | 0.50 | :math:`\eta_3` | 10317f296bb3SBarry Smith> | | | | in | 10327f296bb3SBarry Smith> | | | | ``reduction`` | 10337f296bb3SBarry Smith> | | | | update | 10347f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10357f296bb3SBarry Smith> | ``eta4`` | real | 0.90 | :math:`\eta_4` | 10367f296bb3SBarry Smith> | | | | in | 10377f296bb3SBarry Smith> | | | | ``reduction`` | 10387f296bb3SBarry Smith> | | | | update | 10397f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10407f296bb3SBarry Smith> | ``alpha1`` | real | 0.25 | :math:`\alpha_1` | 10417f296bb3SBarry Smith> | | | | in | 10427f296bb3SBarry Smith> | | | | ``reduction`` | 10437f296bb3SBarry Smith> | | | | update | 10447f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10457f296bb3SBarry Smith> | ``alpha2`` | real | 0.50 | :math:`\alpha_2` | 10467f296bb3SBarry Smith> | | | | in | 10477f296bb3SBarry Smith> | | | | ``reduction`` | 10487f296bb3SBarry Smith> | | | | update | 10497f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10507f296bb3SBarry Smith> | ``alpha3`` | real | 1.00 | :math:`\alpha_3` | 10517f296bb3SBarry Smith> | | | | in | 10527f296bb3SBarry Smith> | | | | ``reduction`` | 10537f296bb3SBarry Smith> | | | | update | 10547f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10557f296bb3SBarry Smith> | ``alpha4`` | real | 2.00 | :math:`\alpha_4` | 10567f296bb3SBarry Smith> | | | | in | 10577f296bb3SBarry Smith> | | | | ``reduction`` | 10587f296bb3SBarry Smith> | | | | update | 10597f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10607f296bb3SBarry Smith> | ``alpha5`` | real | 4.00 | :math:`\alpha_5` | 10617f296bb3SBarry Smith> | | | | in | 10627f296bb3SBarry Smith> | | | | ``reduction`` | 10637f296bb3SBarry Smith> | | | | update | 10647f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10657f296bb3SBarry Smith> | ``mu1`` | real | 0.10 | :math:`\mu_1` | 10667f296bb3SBarry Smith> | | | | in | 10677f296bb3SBarry Smith> | | | | ``interpolation`` | 10687f296bb3SBarry Smith> | | | | update | 10697f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10707f296bb3SBarry Smith> | ``mu2`` | real | 0.50 | :math:`\mu_2` | 10717f296bb3SBarry Smith> | | | | in | 10727f296bb3SBarry Smith> | | | | ``interpolation`` | 10737f296bb3SBarry Smith> | | | | update | 10747f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10757f296bb3SBarry Smith> | ``gamma1`` | real | 0.25 | :math:`\gamma_1` | 10767f296bb3SBarry Smith> | | | | in | 10777f296bb3SBarry Smith> | | | | ``interpolation`` | 10787f296bb3SBarry Smith> | | | | update | 10797f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10807f296bb3SBarry Smith> | ``gamma2`` | real | 0.50 | :math:`\gamma_2` | 10817f296bb3SBarry Smith> | | | | in | 10827f296bb3SBarry Smith> | | | | ``interpolation`` | 10837f296bb3SBarry Smith> | | | | update | 10847f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10857f296bb3SBarry Smith> | ``gamma3`` | real | 2.00 | :math:`\gamma_3` | 10867f296bb3SBarry Smith> | | | | in | 10877f296bb3SBarry Smith> | | | | ``interpolation`` | 10887f296bb3SBarry Smith> | | | | update | 10897f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10907f296bb3SBarry Smith> | ``gamma4`` | real | 4.00 | :math:`\gamma_4` | 10917f296bb3SBarry Smith> | | | | in | 10927f296bb3SBarry Smith> | | | | ``interpolation`` | 10937f296bb3SBarry Smith> | | | | update | 10947f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 10957f296bb3SBarry Smith> | ``theta`` | real | 0.05 | :math:`\theta` | 10967f296bb3SBarry Smith> | | | | in | 10977f296bb3SBarry Smith> | | | | ``interpolation`` | 10987f296bb3SBarry Smith> | | | | update | 10997f296bb3SBarry Smith> +--------------------------+----------------+--------------------+--------------------+ 11007f296bb3SBarry Smith> ``` 11017f296bb3SBarry Smith 11027f296bb3SBarry SmithThe system of equations is approximately solved by applying the 11037f296bb3SBarry Smithconjugate gradient method, Nash conjugate gradient method, 11047f296bb3SBarry SmithSteihaug-Toint conjugate gradient method, generalized Lanczos method, or 11057f296bb3SBarry Smithan alternative Krylov subspace method supplied by PETSc. The method used 11067f296bb3SBarry Smithto solve the systems of equations is specified with the command line 11077f296bb3SBarry Smithargument `-tao_nls_ksp_type <cg,nash,stcg,gltr,gmres,...>`; `stcg` 11087f296bb3SBarry Smithis the default. See the PETSc manual for further information on changing 11097f296bb3SBarry Smiththe behavior of the linear system solvers. 11107f296bb3SBarry Smith 11117f296bb3SBarry SmithA good preconditioner reduces the number of iterations required to solve 11127f296bb3SBarry Smiththe linear system of equations. For the conjugate gradient methods and 11137f296bb3SBarry Smithgeneralized Lanczos method, this preconditioner must be symmetric and 11147f296bb3SBarry Smithpositive definite. The available options are to use no preconditioner, 11157f296bb3SBarry Smiththe absolute value of the diagonal of the Hessian matrix, a 11167f296bb3SBarry Smithlimited-memory BFGS approximation to the Hessian matrix, or one of the 11177f296bb3SBarry Smithother preconditioners provided by the PETSc package. These 11187f296bb3SBarry Smithpreconditioners are specified by the command line arguments 11197f296bb3SBarry Smith`-tao_nls_pc_type <none,jacobi,icc,ilu,lmvm>`, respectively. The 11207f296bb3SBarry Smithdefault is the `lmvm` preconditioner, which uses a BFGS approximation 11217f296bb3SBarry Smithof the inverse Hessian. See the PETSc manual for further information on 11227f296bb3SBarry Smithchanging the behavior of the preconditioners. 11237f296bb3SBarry Smith 11247f296bb3SBarry SmithThe perturbation $\rho_k$ is added when the direction returned by 11257f296bb3SBarry Smiththe Krylov subspace method is not a descent direction, the Krylov method 11267f296bb3SBarry Smithdiverged due to an indefinite preconditioner or matrix, or a direction 11277f296bb3SBarry Smithof negative curvature was found. In the last two cases, if the step 11287f296bb3SBarry Smithreturned is a descent direction, it is used during the line search. 11297f296bb3SBarry SmithOtherwise, a steepest descent direction is used during the line search. 11307f296bb3SBarry SmithThe perturbation is decreased as long as the Krylov subspace method 11317f296bb3SBarry Smithreports success and increased if further problems are encountered. There 11327f296bb3SBarry Smithare three cases: initializing, increasing, and decreasing the 11337f296bb3SBarry Smithperturbation. These cases are described below. 11347f296bb3SBarry Smith 11357f296bb3SBarry Smith1. If $\rho_k$ is zero and a problem was detected with either the 11367f296bb3SBarry Smith direction or the Krylov subspace method, the perturbation is 11377f296bb3SBarry Smith initialized to 11387f296bb3SBarry Smith 11397f296bb3SBarry Smith $$ 11407f296bb3SBarry Smith \rho_{k+1} = \text{median}\left\{\text{imin}, \text{imfac} * \|g(x_k)\|, \text{imax}\right\}, 11417f296bb3SBarry Smith $$ 11427f296bb3SBarry Smith 11437f296bb3SBarry Smith where $g(x_k)$ is the gradient of the objective function and 11447f296bb3SBarry Smith `imin` is set with the command line argument 11457f296bb3SBarry Smith `-tao_nls_imin <real>` with a default value of $10^{-4}$, 11467f296bb3SBarry Smith `imfac` by `-tao_nls_imfac` with a default value of 0.1, and 11477f296bb3SBarry Smith `imax` by `-tao_nls_imax` with a default value of 100. When using 11487f296bb3SBarry Smith the `gltr` method to solve the system of equations, an estimate of 11497f296bb3SBarry Smith the minimum eigenvalue $\lambda_1$ of the Hessian matrix is 11507f296bb3SBarry Smith available. This value is used to initialize the perturbation to 11517f296bb3SBarry Smith $\rho_{k+1} = \max\left\{\rho_{k+1}, -\lambda_1\right\}$ in 11527f296bb3SBarry Smith this case. 11537f296bb3SBarry Smith 11547f296bb3SBarry Smith2. If $\rho_k$ is nonzero and a problem was detected with either 11557f296bb3SBarry Smith the direction or Krylov subspace method, the perturbation is 11567f296bb3SBarry Smith increased to 11577f296bb3SBarry Smith 11587f296bb3SBarry Smith $$ 11597f296bb3SBarry Smith \rho_{k+1} = \min\left\{\text{pmax}, \max\left\{\text{pgfac} * \rho_k, \text{pmgfac} * \|g(x_k)\|\right\}\right\}, 11607f296bb3SBarry Smith $$ 11617f296bb3SBarry Smith 11627f296bb3SBarry Smith where $g(x_k)$ is the gradient of the objective function and 11637f296bb3SBarry Smith `pgfac` is set with the command line argument `-tao_nls_pgfac` 11647f296bb3SBarry Smith with a default value of 10, `pmgfac` by `-tao_nls_pmgfac` with a 11657f296bb3SBarry Smith default value of 0.1, and `pmax` by `-tao_nls_pmax` with a 11667f296bb3SBarry Smith default value of 100. 11677f296bb3SBarry Smith 11687f296bb3SBarry Smith3. If $\rho_k$ is nonzero and no problems were detected with 11697f296bb3SBarry Smith either the direction or Krylov subspace method, the perturbation is 11707f296bb3SBarry Smith decreased to 11717f296bb3SBarry Smith 11727f296bb3SBarry Smith $$ 11737f296bb3SBarry Smith \rho_{k+1} = \min\left\{\text{psfac} * \rho_k, \text{pmsfac} * \|g(x_k)\|\right\}, 11747f296bb3SBarry Smith $$ 11757f296bb3SBarry Smith 11767f296bb3SBarry Smith where $g(x_k)$ is the gradient of the objective function, 11777f296bb3SBarry Smith `psfac` is set with the command line argument `-tao_nls_psfac` 11787f296bb3SBarry Smith with a default value of 0.4, and `pmsfac` is set by 11797f296bb3SBarry Smith `-tao_nls_pmsfac` with a default value of 0.1. Moreover, if 11807f296bb3SBarry Smith $\rho_{k+1} < \text{pmin}$, then $\rho_{k+1} = 0$, where 11817f296bb3SBarry Smith `pmin` is set with the command line argument `-tao_nls_pmin` and 11827f296bb3SBarry Smith has a default value of $10^{-12}$. 11837f296bb3SBarry Smith 11847f296bb3SBarry SmithNear a local minimizer to the unconstrained optimization problem, the 11857f296bb3SBarry SmithHessian matrix will be positive-semidefinite; the perturbation will 11867f296bb3SBarry Smithshrink toward zero, and one would eventually observe a superlinear 11877f296bb3SBarry Smithconvergence rate. 11887f296bb3SBarry Smith 11897f296bb3SBarry SmithWhen using `nash`, `stcg`, or `gltr` to solve the linear systems 11907f296bb3SBarry Smithof equation, a trust-region radius needs to be initialized and updated. 11917f296bb3SBarry SmithThis trust-region radius simultaneously limits the size of the step 11927f296bb3SBarry Smithcomputed and reduces the number of iterations of the conjugate gradient 11937f296bb3SBarry Smithmethod. The method for initializing the trust-region radius is set with 11947f296bb3SBarry Smiththe command line argument 11957f296bb3SBarry Smith`-tao_nls_init_type <constant,direction,interpolation>`; 11967f296bb3SBarry Smith`interpolation`, which chooses an initial value based on the 11977f296bb3SBarry Smithinterpolation scheme found in {cite}`cgt`, is the default. 11987f296bb3SBarry SmithThis scheme performs a number of function and gradient evaluations to 11997f296bb3SBarry Smithdetermine a radius such that the reduction predicted by the quadratic 12007f296bb3SBarry Smithmodel along the gradient direction coincides with the actual reduction 12017f296bb3SBarry Smithin the nonlinear function. The iterate obtaining the best objective 12027f296bb3SBarry Smithfunction value is used as the starting point for the main line search 12037f296bb3SBarry Smithalgorithm. The `constant` method initializes the trust-region radius 12047f296bb3SBarry Smithby using the value specified with the `-tao_trust0 <real>` command 12057f296bb3SBarry Smithline argument, where the default value is 100. The `direction` 12067f296bb3SBarry Smithtechnique solves the first quadratic optimization problem by using a 12077f296bb3SBarry Smithstandard conjugate gradient method and initializes the trust region to 12087f296bb3SBarry Smith$\|s_0\|$. 12097f296bb3SBarry Smith 12107f296bb3SBarry SmithThe method for updating the trust-region radius is set with the command 12117f296bb3SBarry Smithline argument `-tao_nls_update_type <step,reduction,interpolation>`; 12127f296bb3SBarry Smith`step` is the default. The `step` method updates the trust-region 12137f296bb3SBarry Smithradius based on the value of $\tau_k$. In particular, 12147f296bb3SBarry Smith 12157f296bb3SBarry Smith$$ 12167f296bb3SBarry Smith\Delta_{k+1} = \left\{\begin{array}{ll} 12177f296bb3SBarry Smith\omega_1 \text{min}(\Delta_k, \|d_k\|) & \text{if } \tau_k \in [0, \nu_1) \\ 12187f296bb3SBarry Smith\omega_2 \text{min}(\Delta_k, \|d_k\|) & \text{if } \tau_k \in [\nu_1, \nu_2) \\ 12197f296bb3SBarry Smith\omega_3 \Delta_k & \text{if } \tau_k \in [\nu_2, \nu_3) \\ 12207f296bb3SBarry Smith\text{max}(\Delta_k, \omega_4 \|d_k\|) & \text{if } \tau_k \in [\nu_3, \nu_4) \\ 12217f296bb3SBarry Smith\text{max}(\Delta_k, \omega_5 \|d_k\|) & \text{if } \tau_k \in [\nu_4, \infty), 12227f296bb3SBarry Smith\end{array} 12237f296bb3SBarry Smith\right. 12247f296bb3SBarry Smith$$ 12257f296bb3SBarry Smith 12267f296bb3SBarry Smithwhere 12277f296bb3SBarry Smith$0 < \omega_1 < \omega_2 < \omega_3 = 1 < \omega_4 < \omega_5$ and 12287f296bb3SBarry Smith$0 < \nu_1 < \nu_2 < \nu_3 < \nu_4$ are constants. The 12297f296bb3SBarry Smith`reduction` method computes the ratio of the actual reduction in the 12307f296bb3SBarry Smithobjective function to the reduction predicted by the quadratic model for 12317f296bb3SBarry Smiththe full step, 12327f296bb3SBarry Smith$\kappa_k = \frac{f(x_k) - f(x_k + d_k)}{q(x_k) - q(x_k + d_k)}$, 12337f296bb3SBarry Smithwhere $q_k$ is the quadratic model. The radius is then updated as 12347f296bb3SBarry Smith 12357f296bb3SBarry Smith$$ 12367f296bb3SBarry Smith\Delta_{k+1} = \left\{\begin{array}{ll} 12377f296bb3SBarry Smith\alpha_1 \text{min}(\Delta_k, \|d_k\|) & \text{if } \kappa_k \in (-\infty, \eta_1) \\ 12387f296bb3SBarry Smith\alpha_2 \text{min}(\Delta_k, \|d_k\|) & \text{if } \kappa_k \in [\eta_1, \eta_2) \\ 12397f296bb3SBarry Smith\alpha_3 \Delta_k & \text{if } \kappa_k \in [\eta_2, \eta_3) \\ 12407f296bb3SBarry Smith\text{max}(\Delta_k, \alpha_4 \|d_k\|) & \text{if } \kappa_k \in [\eta_3, \eta_4) \\ 12417f296bb3SBarry Smith\text{max}(\Delta_k, \alpha_5 \|d_k\|) & \text{if } \kappa_k \in [\eta_4, \infty), 12427f296bb3SBarry Smith\end{array} 12437f296bb3SBarry Smith\right. 12447f296bb3SBarry Smith$$ 12457f296bb3SBarry Smith 12467f296bb3SBarry Smithwhere 12477f296bb3SBarry Smith$0 < \alpha_1 < \alpha_2 < \alpha_3 = 1 < \alpha_4 < \alpha_5$ and 12487f296bb3SBarry Smith$0 < \eta_1 < \eta_2 < \eta_3 < \eta_4$ are constants. The 12497f296bb3SBarry Smith`interpolation` method uses the same interpolation mechanism as in the 12507f296bb3SBarry Smithinitialization to compute a new value for the trust-region radius. 12517f296bb3SBarry Smith 12527f296bb3SBarry SmithThis algorithm will be deprecated in the next version and replaced by 12537f296bb3SBarry Smiththe Bounded Newton Line Search (BNLS) algorithm that can solve both 12547f296bb3SBarry Smithbound constrained and unconstrained problems. 12557f296bb3SBarry Smith 12567f296bb3SBarry Smith##### Newton Trust-Region Method (NTR) 12577f296bb3SBarry Smith 12587f296bb3SBarry SmithThe Newton trust-region method solves the constrained quadratic 12597f296bb3SBarry Smithprogramming problem 12607f296bb3SBarry Smith 12617f296bb3SBarry Smith$$ 12627f296bb3SBarry Smith\begin{array}{ll} 12637f296bb3SBarry Smith\min_d & \frac{1}{2}d^T H_k d + g_k^T d \\ 12647f296bb3SBarry Smith\text{subject to} & \|d\| \leq \Delta_k 12657f296bb3SBarry Smith\end{array} 12667f296bb3SBarry Smith$$ 12677f296bb3SBarry Smith 12687f296bb3SBarry Smithto obtain a direction $d_k$, where $H_k$ is the Hessian of 12697f296bb3SBarry Smiththe objective function at $x_k$, $g_k$ is the gradient of 12707f296bb3SBarry Smiththe objective function at $x_k$, and $\Delta_k$ is the 12717f296bb3SBarry Smithtrust-region radius. If $x_k + d_k$ sufficiently reduces the 12727f296bb3SBarry Smithnonlinear objective function, then the step is accepted, and the 12737f296bb3SBarry Smithtrust-region radius is updated. However, if $x_k + d_k$ does not 12747f296bb3SBarry Smithsufficiently reduce the nonlinear objective function, then the step is 12757f296bb3SBarry Smithrejected, the trust-region radius is reduced, and the quadratic program 12767f296bb3SBarry Smithis re-solved by using the updated trust-region radius. The Newton 12777f296bb3SBarry Smithtrust-region method can be set by using the TAO solver `tao_ntr`. The 12787f296bb3SBarry Smithoptions available for this solver are listed in 12797f296bb3SBarry Smith{numref}`table_ntroptions`. For the best efficiency, function and 12807f296bb3SBarry Smithgradient evaluations should be performed separately when using this 12817f296bb3SBarry Smithalgorithm. 12827f296bb3SBarry Smith 12837f296bb3SBarry Smith> ```{eval-rst} 12847f296bb3SBarry Smith> .. table:: Summary of ``ntr`` options 12857f296bb3SBarry Smith> :name: table_ntroptions 12867f296bb3SBarry Smith> 12877f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 12887f296bb3SBarry Smith> | Name ``-tao_ntr_`` | Value | Default | Description | 12897f296bb3SBarry Smith> +===========================+================+==================+======================+ 12907f296bb3SBarry Smith> | ``ksp_type`` | nash, stcg | stcg | KSPType for | 12917f296bb3SBarry Smith> | | | | linear system | 12927f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 12937f296bb3SBarry Smith> | ``pc_type`` | none, jacobi | lmvm | PCType for linear | 12947f296bb3SBarry Smith> | | | | system | 12957f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 12967f296bb3SBarry Smith> | ``init_type`` | constant, | interpolation | Radius | 12977f296bb3SBarry Smith> | | direction, | | initialization | 12987f296bb3SBarry Smith> | | interpolation | | method | 12997f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13007f296bb3SBarry Smith> | ``mu1_i`` | real | 0.35 | :math:`\mu_1` | 13017f296bb3SBarry Smith> | | | | in | 13027f296bb3SBarry Smith> | | | | ``interpolation`` | 13037f296bb3SBarry Smith> | | | | init | 13047f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13057f296bb3SBarry Smith> | ``mu2_i`` | real | 0.50 | :math:`\mu_2` | 13067f296bb3SBarry Smith> | | | | in | 13077f296bb3SBarry Smith> | | | | ``interpolation`` | 13087f296bb3SBarry Smith> | | | | init | 13097f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13107f296bb3SBarry Smith> | ``gamma1_i`` | real | 0.0625 | :math:`\gamma_1` | 13117f296bb3SBarry Smith> | | | | in | 13127f296bb3SBarry Smith> | | | | ``interpolation`` | 13137f296bb3SBarry Smith> | | | | init | 13147f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13157f296bb3SBarry Smith> | ``gamma2_i`` | real | 0.50 | :math:`\gamma_2` | 13167f296bb3SBarry Smith> | | | | in | 13177f296bb3SBarry Smith> | | | | ``interpolation`` | 13187f296bb3SBarry Smith> | | | | init | 13197f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13207f296bb3SBarry Smith> | ``gamma3_i`` | real | 2.00 | :math:`\gamma_3` | 13217f296bb3SBarry Smith> | | | | in | 13227f296bb3SBarry Smith> | | | | ``interpolation`` | 13237f296bb3SBarry Smith> | | | | init | 13247f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13257f296bb3SBarry Smith> | ``gamma4_i`` | real | 5.00 | :math:`\gamma_4` | 13267f296bb3SBarry Smith> | | | | in | 13277f296bb3SBarry Smith> | | | | ``interpolation`` | 13287f296bb3SBarry Smith> | | | | init | 13297f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13307f296bb3SBarry Smith> | ``theta_i`` | real | 0.25 | :math:`\theta` | 13317f296bb3SBarry Smith> | | | | in | 13327f296bb3SBarry Smith> | | | | ``interpolation`` | 13337f296bb3SBarry Smith> | | | | init | 13347f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13357f296bb3SBarry Smith> | ``update_type`` | step, | step | Radius | 13367f296bb3SBarry Smith> | | reduction, | | update method | 13377f296bb3SBarry Smith> | | interpolation | | | 13387f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13397f296bb3SBarry Smith> | ``mu1_i`` | real | 0.35 | :math:`\mu_1` | 13407f296bb3SBarry Smith> | | | | in | 13417f296bb3SBarry Smith> | | | | ``interpolation`` | 13427f296bb3SBarry Smith> | | | | init | 13437f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13447f296bb3SBarry Smith> | ``mu2_i`` | real | 0.50 | :math:`\mu_2` | 13457f296bb3SBarry Smith> | | | | in | 13467f296bb3SBarry Smith> | | | | ``interpolation`` | 13477f296bb3SBarry Smith> | | | | init | 13487f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13497f296bb3SBarry Smith> | ``gamma1_i`` | real | 0.0625 | :math:`\gamma_1` | 13507f296bb3SBarry Smith> | | | | in | 13517f296bb3SBarry Smith> | | | | ``interpolation`` | 13527f296bb3SBarry Smith> | | | | init | 13537f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13547f296bb3SBarry Smith> | ``gamma2_i`` | real | 0.50 | :math:`\gamma_2` | 13557f296bb3SBarry Smith> | | | | in | 13567f296bb3SBarry Smith> | | | | ``interpolation`` | 13577f296bb3SBarry Smith> | | | | init | 13587f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13597f296bb3SBarry Smith> | ``gamma3_i`` | real | 2.00 | :math:`\gamma_3` | 13607f296bb3SBarry Smith> | | | | in | 13617f296bb3SBarry Smith> | | | | ``interpolation`` | 13627f296bb3SBarry Smith> | | | | init | 13637f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13647f296bb3SBarry Smith> | ``gamma4_i`` | real | 5.00 | :math:`\gamma_4` | 13657f296bb3SBarry Smith> | | | | in | 13667f296bb3SBarry Smith> | | | | ``interpolation`` | 13677f296bb3SBarry Smith> | | | | init | 13687f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13697f296bb3SBarry Smith> | ``theta_i`` | real | 0.25 | :math:`\theta` | 13707f296bb3SBarry Smith> | | | | in | 13717f296bb3SBarry Smith> | | | | ``interpolation`` | 13727f296bb3SBarry Smith> | | | | init | 13737f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13747f296bb3SBarry Smith> | ``eta1`` | real | : | :math:`\eta_1` | 13757f296bb3SBarry Smith> | | | | in ``reduction`` | 13767f296bb3SBarry Smith> | | | | update | 13777f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13787f296bb3SBarry Smith> | ``eta2`` | real | 0.25 | :math:`\eta_2` | 13797f296bb3SBarry Smith> | | | | in ``reduction`` | 13807f296bb3SBarry Smith> | | | | update | 13817f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13827f296bb3SBarry Smith> | ``eta3`` | real | 0.50 | :math:`\eta_3` | 13837f296bb3SBarry Smith> | | | | in ``reduction`` | 13847f296bb3SBarry Smith> | | | | update | 13857f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13867f296bb3SBarry Smith> | ``eta4`` | real | 0.90 | :math:`\eta_4` | 13877f296bb3SBarry Smith> | | | | in ``reduction`` | 13887f296bb3SBarry Smith> | | | | update | 13897f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13907f296bb3SBarry Smith> | ``alpha1`` | real | 0.25 | :math:`\alpha_1` | 13917f296bb3SBarry Smith> | | | | in ``reduction`` | 13927f296bb3SBarry Smith> | | | | update | 13937f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13947f296bb3SBarry Smith> | ``alpha2`` | real | 0.50 | :math:`\alpha_2` | 13957f296bb3SBarry Smith> | | | | in ``reduction`` | 13967f296bb3SBarry Smith> | | | | update | 13977f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 13987f296bb3SBarry Smith> | ``alpha3`` | real | 1.00 | :math:`\alpha_3` | 13997f296bb3SBarry Smith> | | | | in ``reduction`` | 14007f296bb3SBarry Smith> | | | | update | 14017f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 14027f296bb3SBarry Smith> | ``alpha4`` | real | 2.00 | :math:`\alpha_4` | 14037f296bb3SBarry Smith> | | | | in ``reduction`` | 14047f296bb3SBarry Smith> | | | | update | 14057f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 14067f296bb3SBarry Smith> | ``alpha5`` | real | 4.00 | :math:`\alpha_5` | 14077f296bb3SBarry Smith> | | | | in ``reduction`` | 14087f296bb3SBarry Smith> | | | | update | 14097f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 14107f296bb3SBarry Smith> | ``mu1`` | real | 0.10 | :math:`\mu_1` | 14117f296bb3SBarry Smith> | | | | in | 14127f296bb3SBarry Smith> | | | | ``interpolation`` | 14137f296bb3SBarry Smith> | | | | update | 14147f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 14157f296bb3SBarry Smith> | ``mu2`` | real | 0.50 | :math:`\mu_2` | 14167f296bb3SBarry Smith> | | | | in | 14177f296bb3SBarry Smith> | | | | ``interpolation`` | 14187f296bb3SBarry Smith> | | | | update | 14197f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 14207f296bb3SBarry Smith> | ``gamma1`` | real | 0.25 | :math:`\gamma_1` | 14217f296bb3SBarry Smith> | | | | in | 14227f296bb3SBarry Smith> | | | | ``interpolation`` | 14237f296bb3SBarry Smith> | | | | update | 14247f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 14257f296bb3SBarry Smith> | ``gamma2`` | real | 0.50 | :math:`\gamma_2` | 14267f296bb3SBarry Smith> | | | | in | 14277f296bb3SBarry Smith> | | | | ``interpolation`` | 14287f296bb3SBarry Smith> | | | | update | 14297f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 14307f296bb3SBarry Smith> | ``gamma3`` | real | 2.00 | :math:`\gamma_3` | 14317f296bb3SBarry Smith> | | | | in | 14327f296bb3SBarry Smith> | | | | ``interpolation`` | 14337f296bb3SBarry Smith> | | | | update | 14347f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 14357f296bb3SBarry Smith> | ``gamma4`` | real | 4.00 | :math:`\gamma_4` | 14367f296bb3SBarry Smith> | | | | in | 14377f296bb3SBarry Smith> | | | | ``interpolation`` | 14387f296bb3SBarry Smith> | | | | update | 14397f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 14407f296bb3SBarry Smith> | ``theta`` | real | 0.05 | :math:`\theta` | 14417f296bb3SBarry Smith> | | | | in | 14427f296bb3SBarry Smith> | | | | ``interpolation`` | 14437f296bb3SBarry Smith> | | | | update | 14447f296bb3SBarry Smith> +---------------------------+----------------+------------------+----------------------+ 14457f296bb3SBarry Smith> ``` 14467f296bb3SBarry Smith 14477f296bb3SBarry SmithThe quadratic optimization problem is approximately solved by applying 14487f296bb3SBarry Smiththe Nash or Steihaug-Toint conjugate gradient methods or the generalized 14497f296bb3SBarry SmithLanczos method to the symmetric system of equations 14507f296bb3SBarry Smith$H_k d = -g_k$. The method used to solve the system of equations 14517f296bb3SBarry Smithis specified with the command line argument 14527f296bb3SBarry Smith`-tao_ntr_ksp_type <nash,stcg,gltr>`; `stcg` is the default. See the 14537f296bb3SBarry SmithPETSc manual for further information on changing the behavior of these 14547f296bb3SBarry Smithlinear system solvers. 14557f296bb3SBarry Smith 14567f296bb3SBarry SmithA good preconditioner reduces the number of iterations required to 14577f296bb3SBarry Smithcompute the direction. For the Nash and Steihaug-Toint conjugate 14587f296bb3SBarry Smithgradient methods and generalized Lanczos method, this preconditioner 14597f296bb3SBarry Smithmust be symmetric and positive definite. The available options are to 14607f296bb3SBarry Smithuse no preconditioner, the absolute value of the diagonal of the Hessian 14617f296bb3SBarry Smithmatrix, a limited-memory BFGS approximation to the Hessian matrix, or 14627f296bb3SBarry Smithone of the other preconditioners provided by the PETSc package. These 14637f296bb3SBarry Smithpreconditioners are specified by the command line argument 14647f296bb3SBarry Smith`-tao_ntr_pc_type <none,jacobi,icc,ilu,lmvm>`, respectively. The 14657f296bb3SBarry Smithdefault is the `lmvm` preconditioner. See the PETSc manual for further 14667f296bb3SBarry Smithinformation on changing the behavior of the preconditioners. 14677f296bb3SBarry Smith 14687f296bb3SBarry SmithThe method for computing an initial trust-region radius is set with the 14697f296bb3SBarry Smithcommand line arguments 14707f296bb3SBarry Smith`-tao_ntr_init_type <constant,direction,interpolation>`; 14717f296bb3SBarry Smith`interpolation`, which chooses an initial value based on the 14727f296bb3SBarry Smithinterpolation scheme found in {cite}`cgt`, is the default. 14737f296bb3SBarry SmithThis scheme performs a number of function and gradient evaluations to 14747f296bb3SBarry Smithdetermine a radius such that the reduction predicted by the quadratic 14757f296bb3SBarry Smithmodel along the gradient direction coincides with the actual reduction 14767f296bb3SBarry Smithin the nonlinear function. The iterate obtaining the best objective 14777f296bb3SBarry Smithfunction value is used as the starting point for the main trust-region 14787f296bb3SBarry Smithalgorithm. The `constant` method initializes the trust-region radius 14797f296bb3SBarry Smithby using the value specified with the `-tao_trust0 <real>` command 14807f296bb3SBarry Smithline argument, where the default value is 100. The `direction` 14817f296bb3SBarry Smithtechnique solves the first quadratic optimization problem by using a 14827f296bb3SBarry Smithstandard conjugate gradient method and initializes the trust region to 14837f296bb3SBarry Smith$\|s_0\|$. 14847f296bb3SBarry Smith 14857f296bb3SBarry SmithThe method for updating the trust-region radius is set with the command 14867f296bb3SBarry Smithline arguments `-tao_ntr_update_type <reduction,interpolation>`; 14877f296bb3SBarry Smith`reduction` is the default. The `reduction` method computes the 14887f296bb3SBarry Smithratio of the actual reduction in the objective function to the reduction 14897f296bb3SBarry Smithpredicted by the quadratic model for the full step, 14907f296bb3SBarry Smith$\kappa_k = \frac{f(x_k) - f(x_k + d_k)}{q(x_k) - q(x_k + d_k)}$, 14917f296bb3SBarry Smithwhere $q_k$ is the quadratic model. The radius is then updated as 14927f296bb3SBarry Smith 14937f296bb3SBarry Smith$$ 14947f296bb3SBarry Smith\Delta_{k+1} = \left\{\begin{array}{ll} 14957f296bb3SBarry Smith\alpha_1 \text{min}(\Delta_k, \|d_k\|) & \text{if } \kappa_k \in (-\infty, \eta_1) \\ 14967f296bb3SBarry Smith\alpha_2 \text{min}(\Delta_k, \|d_k\|) & \text{if } \kappa_k \in [\eta_1, \eta_2) \\ 14977f296bb3SBarry Smith\alpha_3 \Delta_k & \text{if } \kappa_k \in [\eta_2, \eta_3) \\ 14987f296bb3SBarry Smith\text{max}(\Delta_k, \alpha_4 \|d_k\|) & \text{if } \kappa_k \in [\eta_3, \eta_4) \\ 14997f296bb3SBarry Smith\text{max}(\Delta_k, \alpha_5 \|d_k\|) & \text{if } \kappa_k \in [\eta_4, \infty), 15007f296bb3SBarry Smith\end{array} 15017f296bb3SBarry Smith\right. 15027f296bb3SBarry Smith$$ 15037f296bb3SBarry Smith 15047f296bb3SBarry Smithwhere 15057f296bb3SBarry Smith$0 < \alpha_1 < \alpha_2 < \alpha_3 = 1 < \alpha_4 < \alpha_5$ and 15067f296bb3SBarry Smith$0 < \eta_1 < \eta_2 < \eta_3 < \eta_4$ are constants. The 15077f296bb3SBarry Smith`interpolation` method uses the same interpolation mechanism as in the 15087f296bb3SBarry Smithinitialization to compute a new value for the trust-region radius. 15097f296bb3SBarry Smith 15107f296bb3SBarry SmithThis algorithm will be deprecated in the next version and replaced by 15117f296bb3SBarry Smiththe Bounded Newton Trust Region (BNTR) algorithm that can solve both 15127f296bb3SBarry Smithbound constrained and unconstrained problems. 15137f296bb3SBarry Smith 15147f296bb3SBarry Smith##### Newton Trust Region with Line Search (NTL) 15157f296bb3SBarry Smith 15167f296bb3SBarry SmithNTL safeguards the trust-region globalization such that a line search 15177f296bb3SBarry Smithis used in the event that the step is initially rejected by the 15187f296bb3SBarry Smithpredicted versus actual decrease comparison. If the line search fails to 15197f296bb3SBarry Smithfind a viable step length for the Newton step, it falls back onto a 15207f296bb3SBarry Smithscaled gradient or a gradient descent step. The trust radius is then 15217f296bb3SBarry Smithmodified based on the line search step length. 15227f296bb3SBarry Smith 15237f296bb3SBarry SmithThis algorithm will be deprecated in the next version and replaced by 15247f296bb3SBarry Smiththe Bounded Newton Trust Region with Line Search (BNTL) algorithm that 15257f296bb3SBarry Smithcan solve both bound constrained and unconstrained problems. 15267f296bb3SBarry Smith 15277f296bb3SBarry Smith#### Limited-Memory Variable-Metric Method (LMVM) 15287f296bb3SBarry Smith 15297f296bb3SBarry SmithThe limited-memory, variable-metric method (LMVM) computes a positive definite 15307f296bb3SBarry Smithapproximation to the Hessian matrix from a limited number of previous 15317f296bb3SBarry Smithiterates and gradient evaluations. A direction is then obtained by 15327f296bb3SBarry Smithsolving the system of equations 15337f296bb3SBarry Smith 15347f296bb3SBarry Smith$$ 15357f296bb3SBarry SmithH_k d_k = -\nabla f(x_k), 15367f296bb3SBarry Smith$$ 15377f296bb3SBarry Smith 15387f296bb3SBarry Smithwhere $H_k$ is the Hessian approximation obtained by using the 15397f296bb3SBarry SmithBFGS update formula. The inverse of $H_k$ can readily be applied 15407f296bb3SBarry Smithto obtain the direction $d_k$. Having obtained the direction, a 15417f296bb3SBarry SmithMoré-Thuente line search is applied to compute a step length, 15427f296bb3SBarry Smith$\tau_k$, that approximately solves the one-dimensional 15437f296bb3SBarry Smithoptimization problem 15447f296bb3SBarry Smith 15457f296bb3SBarry Smith$$ 15467f296bb3SBarry Smith\min_\tau f(x_k + \tau d_k). 15477f296bb3SBarry Smith$$ 15487f296bb3SBarry Smith 15497f296bb3SBarry SmithThe current iterate and Hessian approximation are updated, and the 15507f296bb3SBarry Smithprocess is repeated until the method converges. This algorithm is the 15517f296bb3SBarry Smithdefault unconstrained minimization solver and can be selected by using 15527f296bb3SBarry Smiththe TAO solver `tao_lmvm`. For best efficiency, function and gradient 15537f296bb3SBarry Smithevaluations should be performed simultaneously when using this 15547f296bb3SBarry Smithalgorithm. 15557f296bb3SBarry Smith 15567f296bb3SBarry SmithThe primary factors determining the behavior of this algorithm are the 15577f296bb3SBarry Smithtype of Hessian approximation used, the number of vectors stored for the 15587f296bb3SBarry Smithapproximation and the initialization/scaling of the approximation. These 15597f296bb3SBarry Smithoptions can be configured using the `-tao_lmvm_mat_lmvm` prefix. For 15607f296bb3SBarry Smithfurther detail, we refer the reader to the `MATLMVM` matrix type 15617f296bb3SBarry Smithdefinitions in the PETSc Manual. 15627f296bb3SBarry Smith 15637f296bb3SBarry SmithThe LMVM algorithm also allows the user to define a custom initial 15647f296bb3SBarry SmithHessian matrix $H_{0,k}$ through the interface function 15657f296bb3SBarry Smith`TaoLMVMSetH0()`. This user-provided initialization overrides any 15667f296bb3SBarry Smithother scalar or diagonal initialization inherent to the LMVM 15677f296bb3SBarry Smithapproximation. The provided $H_{0,k}$ must be a PETSc `Mat` type 15687f296bb3SBarry Smithobject that represents a positive-definite matrix. The approximation 15697f296bb3SBarry Smithprefers `MatSolve()` if the provided matrix has `MATOP_SOLVE` 15707f296bb3SBarry Smithimplemented. Otherwise, `MatMult()` is used in a KSP solve to perform 15717f296bb3SBarry Smiththe inversion of the user-provided initial Hessian. 15727f296bb3SBarry Smith 15737f296bb3SBarry SmithIn applications where `TaoSolve()` on the LMVM algorithm is repeatedly 15747f296bb3SBarry Smithcalled to solve similar or related problems, `-tao_lmvm_recycle` flag 15757f296bb3SBarry Smithcan be used to prevent resetting the LMVM approximation between 15767f296bb3SBarry Smithsubsequent solutions. This recycling also avoids one extra function and 15777f296bb3SBarry Smithgradient evaluation, instead re-using the values already computed at the 15787f296bb3SBarry Smithend of the previous solution. 15797f296bb3SBarry Smith 15807f296bb3SBarry SmithThis algorithm will be deprecated in the next version and replaced by 15817f296bb3SBarry Smiththe Bounded Quasi-Newton Line Search (BQNLS) algorithm that can solve 15827f296bb3SBarry Smithboth bound constrained and unconstrained problems. 15837f296bb3SBarry Smith 15847f296bb3SBarry Smith#### Nonlinear Conjugate Gradient Method (CG) 15857f296bb3SBarry Smith 15867f296bb3SBarry SmithThe nonlinear conjugate gradient method can be viewed as an extension of 15877f296bb3SBarry Smiththe conjugate gradient method for solving symmetric, positive-definite 15887f296bb3SBarry Smithlinear systems of equations. This algorithm requires only function and 15897f296bb3SBarry Smithgradient evaluations as well as a line search. The TAO implementation 15907f296bb3SBarry Smithuses a Moré-Thuente line search to obtain the step length. The nonlinear 15917f296bb3SBarry Smithconjugate gradient method can be selected by using the TAO solver 15927f296bb3SBarry Smith`tao_cg`. For the best efficiency, function and gradient evaluations 15937f296bb3SBarry Smithshould be performed simultaneously when using this algorithm. 15947f296bb3SBarry Smith 15957f296bb3SBarry SmithFive variations are currently supported by the TAO implementation: the 15967f296bb3SBarry SmithFletcher-Reeves method, the Polak-Ribiére method, the Polak-Ribiére-Plus 15977f296bb3SBarry Smithmethod {cite}`nocedal2006numerical`, the Hestenes-Stiefel method, and the 15987f296bb3SBarry SmithDai-Yuan method. These conjugate gradient methods can be specified by 15997f296bb3SBarry Smithusing the command line argument `-tao_cg_type <fr,pr,prp,hs,dy>`, 16007f296bb3SBarry Smithrespectively. The default value is `prp`. 16017f296bb3SBarry Smith 16027f296bb3SBarry SmithThe conjugate gradient method incorporates automatic restarts when 16037f296bb3SBarry Smithsuccessive gradients are not sufficiently orthogonal. TAO measures the 16047f296bb3SBarry Smithorthogonality by dividing the inner product of the gradient at the 16057f296bb3SBarry Smithcurrent point and the gradient at the previous point by the square of 16067f296bb3SBarry Smiththe Euclidean norm of the gradient at the current point. When the 16077f296bb3SBarry Smithabsolute value of this ratio is greater than $\eta$, the algorithm 16087f296bb3SBarry Smithrestarts using the gradient direction. The parameter $\eta$ can be 16097f296bb3SBarry Smithset by using the command line argument `-tao_cg_eta <real>`; 0.1 is 16107f296bb3SBarry Smiththe default value. 16117f296bb3SBarry Smith 16127f296bb3SBarry SmithThis algorithm will be deprecated in the next version and replaced by 16137f296bb3SBarry Smiththe Bounded Nonlinear Conjugate Gradient (BNCG) algorithm that can solve 16147f296bb3SBarry Smithboth bound constrained and unconstrained problems. 16157f296bb3SBarry Smith 16167f296bb3SBarry Smith#### Nelder-Mead Simplex Method (NM) 16177f296bb3SBarry Smith 16187f296bb3SBarry SmithThe Nelder-Mead algorithm {cite}`nelder.mead:simplex` is a 16197f296bb3SBarry Smithdirect search method for finding a local minimum of a function 16207f296bb3SBarry Smith$f(x)$. This algorithm does not require any gradient or Hessian 16217f296bb3SBarry Smithinformation of $f$ and therefore has some expected advantages and 16227f296bb3SBarry Smithdisadvantages compared to the other TAO solvers. The obvious advantage 16237f296bb3SBarry Smithis that it is easier to write an application when no derivatives need to 16247f296bb3SBarry Smithbe calculated. The downside is that this algorithm can be slow to 16257f296bb3SBarry Smithconverge or can even stagnate, and it performs poorly for large numbers 16267f296bb3SBarry Smithof variables. 16277f296bb3SBarry Smith 16287f296bb3SBarry SmithThis solver keeps a set of $N+1$ sorted vectors 16297f296bb3SBarry Smith${x_1,x_2,\ldots,x_{N+1}}$ and their corresponding objective 16307f296bb3SBarry Smithfunction values $f_1 \leq f_2 \leq \ldots \leq f_{N+1}$. At each 16317f296bb3SBarry Smithiteration, $x_{N+1}$ is removed from the set and replaced with 16327f296bb3SBarry Smith 16337f296bb3SBarry Smith$$ 16347f296bb3SBarry Smithx(\mu) = (1+\mu) \frac{1}{N} \sum_{i=1}^N x_i - \mu x_{N+1}, 16357f296bb3SBarry Smith$$ 16367f296bb3SBarry Smith 16377f296bb3SBarry Smithwhere $\mu$ can be one of 16387f296bb3SBarry Smith${\mu_0,2\mu_0,\frac{1}{2}\mu_0,-\frac{1}{2}\mu_0}$ depending on 16397f296bb3SBarry Smiththe values of each possible $f(x(\mu))$. 16407f296bb3SBarry Smith 16417f296bb3SBarry SmithThe algorithm terminates when the residual $f_{N+1} - f_1$ becomes 16427f296bb3SBarry Smithsufficiently small. Because of the way new vectors can be added to the 16437f296bb3SBarry Smithsorted set, the minimum function value and/or the residual may not be 16447f296bb3SBarry Smithimpacted at each iteration. 16457f296bb3SBarry Smith 16467f296bb3SBarry SmithTwo options can be set specifically for the Nelder-Mead algorithm: 16477f296bb3SBarry Smith 16487f296bb3SBarry Smith`-tao_nm_lambda <value>` 16497f296bb3SBarry Smith 16507f296bb3SBarry Smith: sets the initial set of vectors ($x_0$ plus `value` in each 16517f296bb3SBarry Smith coordinate direction); the default value is $1$. 16527f296bb3SBarry Smith 16537f296bb3SBarry Smith`-tao_nm_mu <value>` 16547f296bb3SBarry Smith 16557f296bb3SBarry Smith: sets the value of $\mu_0$; the default is $\mu_0=1$. 16567f296bb3SBarry Smith 16577f296bb3SBarry Smith(sec_tao_bound)= 16587f296bb3SBarry Smith 16597f296bb3SBarry Smith### Bound-Constrained Optimization 16607f296bb3SBarry Smith 16617f296bb3SBarry SmithBound-constrained optimization algorithms solve optimization problems of 16627f296bb3SBarry Smiththe form 16637f296bb3SBarry Smith 16647f296bb3SBarry Smith$$ 16657f296bb3SBarry Smith\begin{array}{ll} \displaystyle 16667f296bb3SBarry Smith\min_{x} & f(x) \\ 16677f296bb3SBarry Smith\text{subject to} & l \leq x \leq u. 16687f296bb3SBarry Smith\end{array} 16697f296bb3SBarry Smith$$ 16707f296bb3SBarry Smith 16717f296bb3SBarry SmithThese solvers use the bounds on the variables as well as objective 16727f296bb3SBarry Smithfunction, gradient, and possibly Hessian information. 16737f296bb3SBarry Smith 16747f296bb3SBarry SmithFor any unbounded variables, the bound value for the associated index 16757f296bb3SBarry Smithcan be set to `PETSC_INFINITY` for the upper bound and 16767f296bb3SBarry Smith`PETSC_NINFINITY` for the lower bound. If all bounds are set to 16777f296bb3SBarry Smithinfinity, then the bounded algorithms are equivalent to their 16787f296bb3SBarry Smithunconstrained counterparts. 16797f296bb3SBarry Smith 16807f296bb3SBarry SmithBefore introducing specific methods, we will first define two projection 16817f296bb3SBarry Smithoperations used by all bound constrained algorithms. 16827f296bb3SBarry Smith 16837f296bb3SBarry Smith- Gradient projection: 16847f296bb3SBarry Smith 16857f296bb3SBarry Smith $$ 16867f296bb3SBarry Smith \mathfrak{P}(g) = \left\{\begin{array}{ll} 16877f296bb3SBarry Smith 0 & \text{if} \; (x \leq l_i \land g_i > 0) \lor (x \geq u_i \land g_i < 0) \\ 16887f296bb3SBarry Smith g_i & \text{otherwise} 16897f296bb3SBarry Smith \end{array} 16907f296bb3SBarry Smith \right. 16917f296bb3SBarry Smith $$ 16927f296bb3SBarry Smith 16937f296bb3SBarry Smith- Bound projection: 16947f296bb3SBarry Smith 16957f296bb3SBarry Smith $$ 16967f296bb3SBarry Smith \mathfrak{B}(x) = \left\{\begin{array}{ll} 16977f296bb3SBarry Smith l_i & \text{if} \; x_i < l_i \\ 16987f296bb3SBarry Smith u_i & \text{if} \; x_i > u_i \\ 16997f296bb3SBarry Smith x_i & \text{otherwise} 17007f296bb3SBarry Smith \end{array} 17017f296bb3SBarry Smith \right. 17027f296bb3SBarry Smith $$ 17037f296bb3SBarry Smith 17047f296bb3SBarry Smith(sec_tao_bnk)= 17057f296bb3SBarry Smith 17067f296bb3SBarry Smith#### Bounded Newton-Krylov Methods 17077f296bb3SBarry Smith 17087f296bb3SBarry SmithTAO features three bounded Newton-Krylov (BNK) class of algorithms, 17097f296bb3SBarry Smithseparated by their globalization methods: projected line search (BNLS), 17107f296bb3SBarry Smithtrust region (BNTR), and trust region with a projected line search 17117f296bb3SBarry Smithfall-back (BNTL). They are available via the TAO solvers `TAOBNLS`, 17127f296bb3SBarry Smith`TAOBNTR` and `TAOBNTL`, respectively, or the `-tao_type` 17137f296bb3SBarry Smith`bnls`/`bntr`/`bntl` flag. 17147f296bb3SBarry Smith 17157f296bb3SBarry SmithThe BNK class of methods use an active-set approach to solve the 17167f296bb3SBarry Smithsymmetric system of equations, 17177f296bb3SBarry Smith 17187f296bb3SBarry Smith$$ 17197f296bb3SBarry SmithH_k p_k = -g_k, 17207f296bb3SBarry Smith$$ 17217f296bb3SBarry Smith 17227f296bb3SBarry Smithonly for inactive variables in the interior of the bounds. The 17237f296bb3SBarry Smithactive-set estimation is based on Bertsekas 17247f296bb3SBarry Smith{cite}`bertsekas:projected` with the following variable 17257f296bb3SBarry Smithindex categories: 17267f296bb3SBarry Smith 17277f296bb3SBarry Smith$$ 17287f296bb3SBarry Smith\begin{array}{rlll} \displaystyle 17297f296bb3SBarry Smith\text{lower bounded}: & \mathcal{L}(x) & = & \{ i \; : \; x_i \leq l_i + \epsilon \; \land \; g(x)_i > 0 \}, \\ 17307f296bb3SBarry Smith\text{upper bounded}: & \mathcal{U}(x) & = & \{ i \; : \; x_i \geq u_i + \epsilon \; \land \; g(x)_i < 0 \}, \\ 17317f296bb3SBarry Smith\text{fixed}: & \mathcal{F}(x) & = & \{ i \; : \; l_i = u_i \}, \\ 17327f296bb3SBarry Smith\text{active-set}: & \mathcal{A}(x) & = & \{ \mathcal{L}(x) \; \bigcup \; \mathcal{U}(x) \; \bigcup \; \mathcal{F}(x) \}, \\ 17337f296bb3SBarry Smith\text{inactive-set}: & \mathcal{I}(x) & = & \{ 1,2,\ldots,n \} \; \backslash \; \mathcal{A}(x). 17347f296bb3SBarry Smith\end{array} 17357f296bb3SBarry Smith$$ 17367f296bb3SBarry Smith 17377f296bb3SBarry SmithAt each iteration, the bound tolerance is estimated as 17387f296bb3SBarry Smith$\epsilon_{k+1} = \text{min}(\epsilon_k, ||w_k||_2)$ with 17397f296bb3SBarry Smith$w_k = x_k - \mathfrak{B}(x_k - \beta D_k g_k)$, where the 17407f296bb3SBarry Smithdiagonal matrix $D_k$ is an approximation of the Hessian inverse 17417f296bb3SBarry Smith$H_k^{-1}$. The initial bound tolerance $\epsilon_0$ and the 17427f296bb3SBarry Smithstep length $\beta$ have default values of $0.001$ and can 17437f296bb3SBarry Smithbe adjusted using `-tao_bnk_as_tol` and `-tao_bnk_as_step` flags, 17447f296bb3SBarry Smithrespectively. The active-set estimation can be disabled using the option 17457f296bb3SBarry Smith`-tao_bnk_as_type none`, in which case the algorithm simply uses the 17467f296bb3SBarry Smithcurrent iterate with no bound tolerances to determine which variables 17477f296bb3SBarry Smithare actively bounded and which are free. 17487f296bb3SBarry Smith 17497f296bb3SBarry SmithBNK algorithms invert the reduced Hessian using a Krylov iterative 17507f296bb3SBarry Smithmethod. Trust-region conjugate gradient methods (`KSPNASH`, 17517f296bb3SBarry Smith`KSPSTCG`, and `KSPGLTR`) are required for the BNTR and BNTL 17527f296bb3SBarry Smithalgorithms, and recommended for the BNLS algorithm. The preconditioner 17537f296bb3SBarry Smithtype can be changed using the `-tao_bnk_pc_type` 17547f296bb3SBarry Smith`none`/`ilu`/`icc`/`jacobi`/`lmvm`. The `lmvm` option, which 17557f296bb3SBarry Smithis also the default, preconditions the Krylov solution with a 17567f296bb3SBarry Smith`MATLMVM` matrix. The remaining supported preconditioner types are 17577f296bb3SBarry Smithdefault PETSc types. If Jacobi is selected, the diagonal values are 17587f296bb3SBarry Smithsafeguarded to be positive. `icc` and `ilu` options produce good 17597f296bb3SBarry Smithresults for problems with dense Hessians. The LMVM and Jacobi 17607f296bb3SBarry Smithpreconditioners are also used as the approximate inverse-Hessian in the 17617f296bb3SBarry Smithactive-set estimation. If neither are available, or if the Hessian 17627f296bb3SBarry Smithmatrix does not have `MATOP_GET_DIAGONAL` defined, then the active-set 17637f296bb3SBarry Smithestimation falls back onto using an identity matrix in place of 17647f296bb3SBarry Smith$D_k$ (this is equivalent to estimating the active-set using a 17657f296bb3SBarry Smithgradient descent step). 17667f296bb3SBarry Smith 17677f296bb3SBarry SmithA special option is available to *accelerate* the convergence of the BNK 17687f296bb3SBarry Smithalgorithms by taking a finite number of BNCG iterations at each Newton 17697f296bb3SBarry Smithiteration. By default, the number of BNCG iterations is set to zero and 17707f296bb3SBarry Smiththe algorithms do not take any BNCG steps. This can be changed using the 17717f296bb3SBarry Smithoption flag `-tao_bnk_max_cg_its <i>`. While this reduces the number 17727f296bb3SBarry Smithof Newton iterations, in practice it simply trades off the Hessian 17737f296bb3SBarry Smithevaluations in the BNK solver for more function and gradient evaluations 17747f296bb3SBarry Smithin the BNCG solver. However, it may be useful for certain types of 17757f296bb3SBarry Smithproblems where the Hessian evaluation is disproportionately more 17767f296bb3SBarry Smithexpensive than the objective function or its gradient. 17777f296bb3SBarry Smith 17787f296bb3SBarry Smith(sec_tao_bnls)= 17797f296bb3SBarry Smith 17807f296bb3SBarry Smith##### Bounded Newton Line Search (BNLS) 17817f296bb3SBarry Smith 17827f296bb3SBarry SmithBNLS safeguards the Newton step by falling back onto a BFGS, scaled 17837f296bb3SBarry Smithgradient, or gradient steps based on descent direction verifications. 17847f296bb3SBarry SmithFor problems with indefinite Hessian matrices, the step direction is 17857f296bb3SBarry Smithcalculated using a perturbed system of equations, 17867f296bb3SBarry Smith 17877f296bb3SBarry Smith$$ 17887f296bb3SBarry Smith(H_k + \rho_k I)p_k = -g_k, 17897f296bb3SBarry Smith$$ 17907f296bb3SBarry Smith 17917f296bb3SBarry Smithwhere $\rho_k$ is a dynamically adjusted positive constant. The 17927f296bb3SBarry Smithstep is globalized using a projected Moré-Thuente line search. If a 17937f296bb3SBarry Smithtrust-region conjugate gradient method is used for the Hessian 17947f296bb3SBarry Smithinversion, the trust radius is modified based on the line search step 17957f296bb3SBarry Smithlength. 17967f296bb3SBarry Smith 17977f296bb3SBarry Smith(sec_tao_bntr)= 17987f296bb3SBarry Smith 17997f296bb3SBarry Smith##### Bounded Newton Trust Region (BNTR) 18007f296bb3SBarry Smith 18017f296bb3SBarry SmithBNTR globalizes the Newton step using a trust region method based on the 18027f296bb3SBarry Smithpredicted versus actual reduction in the cost function. The trust radius 18037f296bb3SBarry Smithis increased only if the accepted step is at the trust region boundary. 18047f296bb3SBarry SmithThe reduction check features a safeguard for numerical values below 18057f296bb3SBarry Smithmachine epsilon, scaled by the latest function value, where the full 18067f296bb3SBarry SmithNewton step is accepted without modification. 18077f296bb3SBarry Smith 18087f296bb3SBarry Smith(sec_tao_bntl)= 18097f296bb3SBarry Smith 18107f296bb3SBarry Smith##### Bounded Newton Trust Region with Line Search (BNTL) 18117f296bb3SBarry Smith 18127f296bb3SBarry SmithBNTL safeguards the trust-region globalization such that a line search 18137f296bb3SBarry Smithis used in the event that the step is initially rejected by the 18147f296bb3SBarry Smithpredicted versus actual decrease comparison. If the line search fails to 18157f296bb3SBarry Smithfind a viable step length for the Newton step, it falls back onto a 18167f296bb3SBarry Smithscaled gradient or a gradient descent step. The trust radius is then 18177f296bb3SBarry Smithmodified based on the line search step length. 18187f296bb3SBarry Smith 18197f296bb3SBarry Smith(sec_tao_bqnls)= 18207f296bb3SBarry Smith 18217f296bb3SBarry Smith#### Bounded Quasi-Newton Line Search (BQNLS) 18227f296bb3SBarry Smith 18237f296bb3SBarry SmithThe BQNLS algorithm uses the BNLS infrastructure, but replaces the step 18247f296bb3SBarry Smithcalculation with a direct inverse application of the approximate Hessian 18257f296bb3SBarry Smithbased on quasi-Newton update formulas. No Krylov solver is used in the 18267f296bb3SBarry Smithsolution, and therefore the quasi-Newton method chosen must guarantee a 18277f296bb3SBarry Smithpositive-definite Hessian approximation. This algorithm is available via 18287f296bb3SBarry Smith`tao_type bqnls`. 18297f296bb3SBarry Smith 18307f296bb3SBarry Smith(sec_tao_bqnk)= 18317f296bb3SBarry Smith 18327f296bb3SBarry Smith#### Bounded Quasi-Newton-Krylov 18337f296bb3SBarry Smith 18347f296bb3SBarry SmithBQNK algorithms use the BNK infrastructure, but replace the exact 18357f296bb3SBarry SmithHessian with a quasi-Newton approximation. The matrix-free forward 18367f296bb3SBarry Smithproduct operation based on quasi-Newton update formulas are used in 18377f296bb3SBarry Smithconjunction with Krylov solvers to compute step directions. The 18387f296bb3SBarry Smithquasi-Newton inverse application is used to precondition the Krylov 18397f296bb3SBarry Smithsolution, and typically helps converge to a step direction in 18407f296bb3SBarry Smith$\mathcal{O}(10)$ iterations. This approach is most useful with 18417f296bb3SBarry Smithquasi-Newton update types such as Symmetric Rank-1 that cannot strictly 18427f296bb3SBarry Smithguarantee positive-definiteness. The BNLS framework with Hessian 18437f296bb3SBarry Smithshifting, or the BNTR framework with trust region safeguards, can 18447f296bb3SBarry Smithsuccessfully compensate for the Hessian approximation becoming 18457f296bb3SBarry Smithindefinite. 18467f296bb3SBarry Smith 18477f296bb3SBarry SmithSimilar to the full Newton-Krylov counterpart, BQNK algorithms come in 18487f296bb3SBarry Smiththree forms separated by the globalization technique: line search 18497f296bb3SBarry Smith(BQNKLS), trust region (BQNKTR) and trust region w/ line search 18507f296bb3SBarry Smithfall-back (BQNKTL). These algorithms are available via 18517f296bb3SBarry Smith`tao_type <bqnkls, bqnktr, bqnktl>`. 18527f296bb3SBarry Smith 18537f296bb3SBarry Smith(sec_tao_bncg)= 18547f296bb3SBarry Smith 18557f296bb3SBarry Smith#### Bounded Nonlinear Conjugate Gradient (BNCG) 18567f296bb3SBarry Smith 18577f296bb3SBarry SmithBNCG extends the unconstrained nonlinear conjugate gradient algorithm to 18587f296bb3SBarry Smithbound constraints via gradient projections and a bounded Moré-Thuente 18597f296bb3SBarry Smithline search. 18607f296bb3SBarry Smith 18617f296bb3SBarry SmithLike its unconstrained counterpart, BNCG offers gradient descent and a 18627f296bb3SBarry Smithvariety of CG updates: Fletcher-Reeves, Polak-Ribiére, 18637f296bb3SBarry SmithPolak-Ribiére-Plus, Hestenes-Stiefel, Dai-Yuan, Hager-Zhang, Dai-Kou, 18647f296bb3SBarry SmithKou-Dai, and the Self-Scaling Memoryless (SSML) BFGS, DFP, and Broyden 18657f296bb3SBarry Smithmethods. These methods can be specified by using the command line 18667f296bb3SBarry Smithargument 18677f296bb3SBarry Smith`-tao_bncg_type <gd,fr,pr,prp,hs,dy,hz,dk,kd,ssml_bfgs,ssml_dfp,ssml_brdn>`, 18687f296bb3SBarry Smithrespectively. The default value is `ssml_bfgs`. We have scalar 18697f296bb3SBarry Smithpreconditioning for these methods, and it is controlled by the flag 18707f296bb3SBarry Smith`tao_bncg_alpha`. To disable rescaling, use $\alpha = -1.0$, 18717f296bb3SBarry Smithotherwise $\alpha \in [0, 1]$. BNCG is available via the TAO 18727f296bb3SBarry Smithsolver `TAOBNCG` or the `-tao_type bncg` flag. 18737f296bb3SBarry Smith 18747f296bb3SBarry SmithSome individual methods also contain their own parameters. The 18757f296bb3SBarry SmithHager-Zhang and Dou-Kai methods have a parameter that determines the 18767f296bb3SBarry Smithminimum amount of contribution the previous search direction gives to 18777f296bb3SBarry Smiththe next search direction. The flags are `-tao_bncg_hz_eta` and 18787f296bb3SBarry Smith`-tao_bncg_dk_eta`, and by default are set to $0.4$ and 18797f296bb3SBarry Smith$0.5$ respectively. The Kou-Dai method has multiple parameters. 18807f296bb3SBarry Smith`-tao_bncg_zeta` serves the same purpose as the previous two; set to 18817f296bb3SBarry Smith$0.1$ by default. There is also a parameter to scale the 18827f296bb3SBarry Smithcontribution of $y_k \equiv \nabla f(x_k) - \nabla f(x_{k-1})$ in 18837f296bb3SBarry Smiththe search direction update. It is controlled by `-tao_bncg_xi`, and 18847f296bb3SBarry Smithis equal to $1.0$ by default. There are also times where we want 18857f296bb3SBarry Smithto maximize the descent as measured by $\nabla f(x_k)^T d_k$, and 18867f296bb3SBarry Smiththat may be done by using a negative value of $\xi$; this achieves 18877f296bb3SBarry Smithbetter performance when not using the diagonal preconditioner described 18887f296bb3SBarry Smithnext. This is enabled by default, and is controlled by 18897f296bb3SBarry Smith`-tao_bncg_neg_xi`. Finally, the Broyden method has its convex 18907f296bb3SBarry Smithcombination parameter, set with `-tao_bncg_theta`. We have this as 1.0 18917f296bb3SBarry Smithby default, i.e. it is by default the BFGS method. One can also 18927f296bb3SBarry Smithindividually tweak the BFGS and DFP contributions using the 18937f296bb3SBarry Smithmultiplicative constants `-tao_bncg_scale`; both are set to $1$ 18947f296bb3SBarry Smithby default. 18957f296bb3SBarry Smith 18967f296bb3SBarry SmithAll methods can be scaled using the parameter `-tao_bncg_alpha`, which 18977f296bb3SBarry Smithcontinuously varies in $[0, 1]$. The default value is set 18987f296bb3SBarry Smithdepending on the method from initial testing. 18997f296bb3SBarry Smith 19007f296bb3SBarry SmithBNCG also offers a special type of method scaling. It employs Broyden 19017f296bb3SBarry Smithdiagonal scaling as an option for its CG methods, turned on with the 19027f296bb3SBarry Smithflag `-tao_bncg_diag_scaling`. Formulations for both the forward 19037f296bb3SBarry Smith(regular) and inverse Broyden methods are developed, controlled by the 19047f296bb3SBarry Smithflag `-tao_bncg_mat_lmvm_forward`. It is set to True by default. 19057f296bb3SBarry SmithWhether one uses the forward or inverse formulations depends on the 19067f296bb3SBarry Smithmethod being used. For example, in our preliminary computations, the 19077f296bb3SBarry Smithforward formulation works better for the SSML_BFGS method, but the 19087f296bb3SBarry Smithinverse formulation works better for the Hestenes-Stiefel method. The 19097f296bb3SBarry Smithconvex combination parameter for the Broyden scaling is controlled by 19107f296bb3SBarry Smith`-tao_bncg_mat_lmvm_theta`, and is 0 by default. We also employ 19117f296bb3SBarry Smithrescaling of the Broyden diagonal, which aids the linesearch immensely. 19127f296bb3SBarry SmithThe rescaling parameter is controlled by `-tao_bncg_mat_lmvm_alpha`, 19137f296bb3SBarry Smithand should be $\in [0, 1]$. One can disable rescaling of the 19147f296bb3SBarry SmithBroyden diagonal entirely by setting 19157f296bb3SBarry Smith`-tao_bncg_mat_lmvm_sigma_hist 0`. 19167f296bb3SBarry Smith 19177f296bb3SBarry SmithOne can also supply their own preconditioner, serving as a Hessian 19187f296bb3SBarry Smithinitialization to the above diagonal scaling. The appropriate user 19197f296bb3SBarry Smithfunction in the code is `TaoBNCGSetH0(tao, H0)` where `H0` is the 19207f296bb3SBarry Smithuser-defined `Mat` object that serves as a preconditioner. For an 19217f296bb3SBarry Smithexample of similar usage, see `tao/tutorials/ex3.c`. 19227f296bb3SBarry Smith 19237f296bb3SBarry SmithThe active set estimation uses the Bertsekas-based method described in 19247f296bb3SBarry Smith{any}`sec_tao_bnk`, which can be deactivated using 19257f296bb3SBarry Smith`-tao_bncg_as_type none`, in which case the algorithm will use the 19267f296bb3SBarry Smithcurrent iterate to determine the bounded variables with no tolerances 19277f296bb3SBarry Smithand no look-ahead step. As in the BNK algorithm, the initial bound 19287f296bb3SBarry Smithtolerance and estimator step length used in the Bertsekas method can be 19297f296bb3SBarry Smithset via `-tao_bncg_as_tol` and `-tao_bncg_as_step`, respectively. 19307f296bb3SBarry Smith 19317f296bb3SBarry SmithIn addition to automatic scaled gradient descent restarts under certain 19327f296bb3SBarry Smithlocal curvature conditions, we also employ restarts based on a check on 19337f296bb3SBarry Smithdescent direction such that 19347f296bb3SBarry Smith$\nabla f(x_k)^T d_k \in [-10^{11}, -10^{-9}]$. Furthermore, we 19357f296bb3SBarry Smithallow for a variety of alternative restart strategies, all disabled by 19367f296bb3SBarry Smithdefault. The `-tao_bncg_unscaled_restart` flag allows one to disable 19377f296bb3SBarry Smithrescaling of the gradient for gradient descent steps. The 19387f296bb3SBarry Smith`-tao_bncg_spaced_restart` flag tells the solver to restart every 19397f296bb3SBarry Smith$Mn$ iterations, where $n$ is the problem dimension and 19407f296bb3SBarry Smith$M$ is a constant determined by `-tao_bncg_min_restart_num` and 19417f296bb3SBarry Smithis 6 by default. We also have dynamic restart strategies based on 19427f296bb3SBarry Smithchecking if a function is locally quadratic; if so, go do a gradient 19437f296bb3SBarry Smithdescent step. The flag is `-tao_bncg_dynamic_restart`, disabled by 19447f296bb3SBarry Smithdefault since the CG solver usually does better in those cases anyway. 19457f296bb3SBarry SmithThe minimum number of quadratic-like steps before a restart is set using 19467f296bb3SBarry Smith`-tao_bncg_min_quad` and is 6 by default. 19477f296bb3SBarry Smith 19487f296bb3SBarry Smith(sec_tao_constrained)= 19497f296bb3SBarry Smith 19507f296bb3SBarry Smith### Generally Constrained Solvers 19517f296bb3SBarry Smith 19527f296bb3SBarry SmithConstrained solvers solve optimization problems that incorporate either or both 19537f296bb3SBarry Smithequality and inequality constraints, and may optionally include bounds on 19547f296bb3SBarry Smithsolution variables. 19557f296bb3SBarry Smith 19567f296bb3SBarry Smith#### Alternating Direction Method of Multipliers (ADMM) 19577f296bb3SBarry Smith 19587f296bb3SBarry SmithThe TAOADMM algorithm is intended to blend the decomposability 19597f296bb3SBarry Smithof dual ascent with the superior convergence properties of the method of 19607f296bb3SBarry Smithmultipliers. {cite}`boyd` The algorithm solves problems in 19617f296bb3SBarry Smiththe form 19627f296bb3SBarry Smith 19637f296bb3SBarry Smith$$ 19647f296bb3SBarry Smith\begin{array}{ll} 19657f296bb3SBarry Smith\displaystyle \min_{x} & f(x) + g(z) \\ 19667f296bb3SBarry Smith\text{subject to} & Ax + Bz = c 19677f296bb3SBarry Smith\end{array} 19687f296bb3SBarry Smith$$ 19697f296bb3SBarry Smith 19707f296bb3SBarry Smithwhere $x \in \mathbb R^n$, $z \in \mathbb R^m$, 19717f296bb3SBarry Smith$A \in \mathbb R^{p \times n}$, 19727f296bb3SBarry Smith$B \in \mathbb R^{p \times m}$, and $c \in \mathbb R^p$. 19737f296bb3SBarry SmithEssentially, ADMM is a wrapper over two TAO solver, one for 19747f296bb3SBarry Smith$f(x)$, and one for $g(z)$. With method of multipliers, one 19757f296bb3SBarry Smithcan form the augmented Lagrangian 19767f296bb3SBarry Smith 19777f296bb3SBarry Smith$$ 19787f296bb3SBarry SmithL_{\rho}(x,z,y) = f(x) + g(z) + y^T(Ax+Bz-c) + (\rho/2)||Ax+Bz-c||_2^2 19797f296bb3SBarry Smith$$ 19807f296bb3SBarry Smith 19817f296bb3SBarry SmithThen, ADMM consists of the iterations 19827f296bb3SBarry Smith 19837f296bb3SBarry Smith$$ 19847f296bb3SBarry Smithx^{k+1} := \text{argmin}L_{\rho}(x,z^k,y^k) 19857f296bb3SBarry Smith$$ 19867f296bb3SBarry Smith 19877f296bb3SBarry Smith$$ 19887f296bb3SBarry Smithz^{k+1} := \text{argmin}L_{\rho}(x^{k+1},z,y^k) 19897f296bb3SBarry Smith$$ 19907f296bb3SBarry Smith 19917f296bb3SBarry Smith$$ 19927f296bb3SBarry Smithy^{k+1} := y^k + \rho(Ax^{k+1}+Bz^{k+1}-c) 19937f296bb3SBarry Smith$$ 19947f296bb3SBarry Smith 19957f296bb3SBarry SmithIn certain formulation of ADMM, solution of $z^{k+1}$ may have 19967f296bb3SBarry Smithclosed-form solution. Currently ADMM provides one default implementation 19977f296bb3SBarry Smithfor $z^{k+1}$, which is soft-threshold. It can be used with either 19987f296bb3SBarry Smith`TaoADMMSetRegularizerType_ADMM()` or 19997f296bb3SBarry Smith`-tao_admm_regularizer_type <regularizer_soft_thresh>`. User can also 20007f296bb3SBarry Smithpass spectral penalty value, $\rho$, with either 20017f296bb3SBarry Smith`TaoADMMSetSpectralPenalty()` or `-tao_admm_spectral_penalty`. 20027f296bb3SBarry SmithCurrently, user can use 20037f296bb3SBarry Smith 20047f296bb3SBarry Smith- `TaoADMMSetMisfitObjectiveAndGradientRoutine()` 20057f296bb3SBarry Smith- `TaoADMMSetRegularizerObjectiveAndGradientRoutine()` 20067f296bb3SBarry Smith- `TaoADMMSetMisfitHessianRoutine()` 20077f296bb3SBarry Smith- `TaoADMMSetRegularizerHessianRoutine()` 20087f296bb3SBarry Smith 20097f296bb3SBarry SmithAny other combination of routines is currently not supported. Hessian 20107f296bb3SBarry Smithmatrices can either be constant or non-constant, of which fact can be 20117f296bb3SBarry Smithset via `TaoADMMSetMisfitHessianChangeStatus()`, and 20127f296bb3SBarry Smith`TaoADMMSetRegularizerHessianChangeStatus()`. Also, it may appear in 20137f296bb3SBarry Smithcertain cases where augmented Lagrangian’s Hessian may become nearly 20147f296bb3SBarry Smithsingular depending on the $\rho$, which may change in the case of 20157f296bb3SBarry Smith`-tao_admm_dual_update <update_adaptive>, <update_adaptive_relaxed>`. 20167f296bb3SBarry SmithThis issue can be prevented by `TaoADMMSetMinimumSpectralPenalty()`. 20177f296bb3SBarry Smith 20187f296bb3SBarry Smith#### Augmented Lagrangian Method of Multipliers (ALMM) 20197f296bb3SBarry Smith 20207f296bb3SBarry SmithThe TAOALMM method solves generally constrained problems of the form 20217f296bb3SBarry Smith 20227f296bb3SBarry Smith$$ 20237f296bb3SBarry Smith\begin{array}{ll} 20247f296bb3SBarry Smith\displaystyle \min_{x} & f(x) \\ 20257f296bb3SBarry Smith\text{subject to} & g(x) = 0\\ 20267f296bb3SBarry Smith & h(x) \geq 0 \\ 20277f296bb3SBarry Smith & l \leq x \leq u 20287f296bb3SBarry Smith\end{array} 20297f296bb3SBarry Smith$$ 20307f296bb3SBarry Smith 20317f296bb3SBarry Smithwhere $g(x)$ are equality constraints, $h(x)$ are inequality 20327f296bb3SBarry Smithconstraints and $l$ and $u$ are lower and upper bounds on 20337f296bb3SBarry Smiththe optimization variables, respectively. 20347f296bb3SBarry Smith 20357f296bb3SBarry SmithTAOALMM converts the above general constrained problem into a sequence 20367f296bb3SBarry Smithof bound constrained problems at each outer iteration 20377f296bb3SBarry Smith$k = 1,2,\dots$ 20387f296bb3SBarry Smith 20397f296bb3SBarry Smith$$ 20407f296bb3SBarry Smith\begin{array}{ll} 20417f296bb3SBarry Smith\displaystyle \min_{x} & L(x, \lambda_k) \\ 20427f296bb3SBarry Smith\text{subject to} & l \leq x \leq u 20437f296bb3SBarry Smith\end{array} 20447f296bb3SBarry Smith$$ 20457f296bb3SBarry Smith 20467f296bb3SBarry Smithwhere $L(x, \lambda_k)$ is the augmented Lagrangian merit function 20477f296bb3SBarry Smithand $\lambda_k$ is the Lagrange multiplier estimates at outer 20487f296bb3SBarry Smithiteration $k$. 20497f296bb3SBarry Smith 20507f296bb3SBarry SmithTAOALMM offers two versions of the augmented Lagrangian formulation: the 20517f296bb3SBarry Smithcanonical Hestenes-Powell augmented 20527f296bb3SBarry SmithLagrangian {cite}`hestenes1969multiplier` {cite}`powell1969method` 20537f296bb3SBarry Smithwith inequality constrained converted to equality constraints via slack 20547f296bb3SBarry Smithvariables, and the slack-less Powell-Hestenes-Rockafellar 20557f296bb3SBarry Smithformulation {cite}`rockafellar1974augmented` that utilizes a 20567f296bb3SBarry Smithpointwise `max()` on the inequality constraints. For most 20577f296bb3SBarry Smithapplications, the canonical Hestenes-Powell formulation is likely to 20587f296bb3SBarry Smithperform better. However, the PHR formulation may be desirable for 20597f296bb3SBarry Smithproblems featuring very large numbers of inequality constraints as it 20607f296bb3SBarry Smithavoids inflating the dimension of the subproblem with slack variables. 20617f296bb3SBarry Smith 20627f296bb3SBarry SmithThe inner subproblem is solved using a nested bound-constrained 20637f296bb3SBarry Smithfirst-order TAO solver. By default, TAOALM uses a quasi-Newton-Krylov 20647f296bb3SBarry Smithtrust-region method (TAOBQNKTR). Other first-order methods such as 20657f296bb3SBarry SmithTAOBNCG and TAOBQNLS are also appropriate, but a trust-region 20667f296bb3SBarry Smithglobalization is strongly recommended for most applications. 20677f296bb3SBarry Smith 20687f296bb3SBarry Smith#### Primal-Dual Interior-Point Method (PDIPM) 20697f296bb3SBarry Smith 20707f296bb3SBarry SmithThe TAOPDIPM method (`-tao_type pdipm`) implements a primal-dual interior 20717f296bb3SBarry Smithpoint method for solving general nonlinear programming problems of the form 20727f296bb3SBarry Smith 20737f296bb3SBarry Smith$$ 20747f296bb3SBarry Smith\begin{array}{ll} 20757f296bb3SBarry Smith\displaystyle \min_{x} & f(x) \\ 20767f296bb3SBarry Smith\text{subject to} & g(x) = 0 \\ 20777f296bb3SBarry Smith & h(x) \geq 0 \\ 20787f296bb3SBarry Smith & x^- \leq x \leq x^+ 20797f296bb3SBarry Smith\end{array} 20807f296bb3SBarry Smith$$ (eq_nlp_gen1) 20817f296bb3SBarry Smith 20827f296bb3SBarry SmithHere, $f(x)$ is the nonlinear objective function, $g(x)$, 20837f296bb3SBarry Smith$h(x)$ are the equality and inequality constraints, and 20847f296bb3SBarry Smith$x^-$ and $x^+$ are the lower and upper bounds on decision 20857f296bb3SBarry Smithvariables $x$. 20867f296bb3SBarry Smith 20877f296bb3SBarry SmithPDIPM converts the inequality constraints to equalities using slack variables 20887f296bb3SBarry Smith$z$ and a log-barrier term, which transforms {eq}`eq_nlp_gen1` to 20897f296bb3SBarry Smith 20907f296bb3SBarry Smith$$ 20917f296bb3SBarry Smith\begin{aligned} 20927f296bb3SBarry Smith \text{min}~&f(x) - \mu\sum_{i=1}^{nci}\ln z_i\\ 20937f296bb3SBarry Smith \text{s.t.}& \\ 20947f296bb3SBarry Smith &ce(x) = 0 \\ 20957f296bb3SBarry Smith &ci(x) - z = 0 \\ 20967f296bb3SBarry Smith \end{aligned} 20977f296bb3SBarry Smith$$ (eq_nlp_gen2) 20987f296bb3SBarry Smith 20997f296bb3SBarry SmithHere, $ce(x)$ is set of equality constraints that include 21007f296bb3SBarry Smith$g(x)$ and fixed decision variables, i.e., $x^- = x = x^+$. 21017f296bb3SBarry SmithSimilarly, $ci(x)$ are inequality constraints including 21027f296bb3SBarry Smith$h(x)$ and lower/upper/box-constraints on $x$. $\mu$ 21037f296bb3SBarry Smithis a parameter that is driven to zero as the optimization progresses. 21047f296bb3SBarry Smith 21057f296bb3SBarry SmithThe Lagrangian for {eq}`eq_nlp_gen2`) is 21067f296bb3SBarry Smith 21077f296bb3SBarry Smith$$ 21087f296bb3SBarry 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 21097f296bb3SBarry Smith$$ (eq_lagrangian) 21107f296bb3SBarry Smith 21117f296bb3SBarry Smithwhere, $\lambda_{ce}$ and $\lambda_{ci}$ are the Lagrangian 21127f296bb3SBarry Smithmultipliers for the equality and inequality constraints, respectively. 21137f296bb3SBarry Smith 21147f296bb3SBarry SmithThe first order KKT conditions for optimality are as follows 21157f296bb3SBarry Smith 21167f296bb3SBarry Smith$$ 21177f296bb3SBarry Smith\nabla L_{\mu}(x,\lambda_{ce},\lambda_{ci},z) = 21187f296bb3SBarry Smith \begin{bmatrix} 21197f296bb3SBarry Smith \nabla f(x) + \nabla ce(x)^T\lambda_{ce} - \nabla ci(x)^T \lambda_{ci} \\ 21207f296bb3SBarry Smith ce(x) \\ 21217f296bb3SBarry Smith ci(x) - z \\ 21227f296bb3SBarry Smith Z\Lambda_{ci}e - \mu e 21237f296bb3SBarry Smith \end{bmatrix} 21247f296bb3SBarry Smith= 0 21257f296bb3SBarry Smith$$ (eq_nlp_kkt) 21267f296bb3SBarry Smith 21277f296bb3SBarry Smith{eq}`eq_nlp_kkt` is solved iteratively using Newton’s 21287f296bb3SBarry Smithmethod using PETSc’s SNES object. After each Newton iteration, a 21297f296bb3SBarry Smithline-search is performed to update $x$ and enforce 21307f296bb3SBarry Smith$z,\lambda_{ci} \geq 0$. The barrier parameter $\mu$ is also 21317f296bb3SBarry Smithupdated after each Newton iteration. The Newton update is obtained by 21327f296bb3SBarry Smithsolving the second-order KKT system $Hd = -\nabla L_{\mu}$. 21337f296bb3SBarry SmithHere,$H$ is the Hessian matrix of the KKT system. For 21347f296bb3SBarry Smithinterior-point methods such as PDIPM, the Hessian matrix tends to be 21357f296bb3SBarry Smithill-conditioned, thus necessitating the use of a direct solver. We 21367f296bb3SBarry Smithrecommend using LU preconditioner `-pc_type lu` and using direct 21377f296bb3SBarry Smithlinear solver packages such `SuperLU_Dist` or `MUMPS`. 21387f296bb3SBarry Smith 21397f296bb3SBarry Smith### PDE-Constrained Optimization 21407f296bb3SBarry Smith 21417f296bb3SBarry SmithTAO solves PDE-constrained optimization problems of the form 21427f296bb3SBarry Smith 21437f296bb3SBarry Smith$$ 21447f296bb3SBarry Smith\begin{array}{ll} 21457f296bb3SBarry Smith\displaystyle \min_{u,v} & f(u,v) \\ 21467f296bb3SBarry Smith\text{subject to} & g(u,v) = 0, 21477f296bb3SBarry Smith\end{array} 21487f296bb3SBarry Smith$$ 21497f296bb3SBarry Smith 21507f296bb3SBarry Smithwhere the state variable $u$ is the solution to the discretized 21517f296bb3SBarry Smithpartial differential equation defined by $g$ and parametrized by 21527f296bb3SBarry Smiththe design variable $v$, and $f$ is an objective function. 21537f296bb3SBarry SmithThe Lagrange multipliers on the constraint are denoted by $y$. 21547f296bb3SBarry SmithThis method is set by using the linearly constrained augmented 21557f296bb3SBarry SmithLagrangian TAO solver `tao_lcl`. 21567f296bb3SBarry Smith 21577f296bb3SBarry SmithWe make two main assumptions when solving these problems: the objective 21587f296bb3SBarry Smithfunction and PDE constraints have been discretized so that we can treat 21597f296bb3SBarry Smiththe optimization problem as finite dimensional and 21607f296bb3SBarry Smith$\nabla_u g(u,v)$ is invertible for all $u$ and $v$. 21617f296bb3SBarry Smith 21627f296bb3SBarry Smith(sec_tao_lcl)= 21637f296bb3SBarry Smith 21647f296bb3SBarry Smith#### Linearly-Constrained Augmented Lagrangian Method (LCL) 21657f296bb3SBarry Smith 21667f296bb3SBarry SmithGiven the current iterate $(u_k, v_k, y_k)$, the linearly 21677f296bb3SBarry Smithconstrained augmented Lagrangian method approximately solves the 21687f296bb3SBarry Smithoptimization problem 21697f296bb3SBarry Smith 21707f296bb3SBarry Smith$$ 21717f296bb3SBarry Smith\begin{array}{ll} 21727f296bb3SBarry Smith\displaystyle \min_{u,v} & \tilde{f}_k(u, v) \\ 21737f296bb3SBarry Smith\text{subject to} & A_k (u-u_k) + B_k (v-v_k) + g_k = 0, 21747f296bb3SBarry Smith\end{array} 21757f296bb3SBarry Smith$$ 21767f296bb3SBarry Smith 21777f296bb3SBarry Smithwhere $A_k = \nabla_u g(u_k,v_k)$, 21787f296bb3SBarry Smith$B_k = \nabla_v g(u_k,v_k)$, and $g_k = g(u_k, v_k)$ and 21797f296bb3SBarry Smith 21807f296bb3SBarry Smith$$ 21817f296bb3SBarry Smith\tilde{f}_k(u,v) = f(u,v) - g(u,v)^T y^k + \frac{\rho_k}{2} \| g(u,v) \|^2 21827f296bb3SBarry Smith$$ 21837f296bb3SBarry Smith 21847f296bb3SBarry Smithis the augmented Lagrangian function. This optimization problem is 21857f296bb3SBarry Smithsolved in two stages. The first computes the Newton direction and finds 21867f296bb3SBarry Smitha feasible point for the linear constraints. The second computes a 21877f296bb3SBarry Smithreduced-space direction that maintains feasibility with respect to the 21887f296bb3SBarry Smithlinearized constraints and improves the augmented Lagrangian merit 21897f296bb3SBarry Smithfunction. 21907f296bb3SBarry Smith 21917f296bb3SBarry Smith##### Newton Step 21927f296bb3SBarry Smith 21937f296bb3SBarry SmithThe Newton direction is obtained by fixing the design variables at their 21947f296bb3SBarry Smithcurrent value and solving the linearized constraint for the state 21957f296bb3SBarry Smithvariables. In particular, we solve the system of equations 21967f296bb3SBarry Smith 21977f296bb3SBarry Smith$$ 21987f296bb3SBarry SmithA_k du = -g_k 21997f296bb3SBarry Smith$$ 22007f296bb3SBarry Smith 22017f296bb3SBarry Smithto obtain a direction $du$. We need a direction that provides 22027f296bb3SBarry Smithsufficient descent for the merit function 22037f296bb3SBarry Smith 22047f296bb3SBarry Smith$$ 22057f296bb3SBarry Smith\frac{1}{2} \|g(u,v)\|^2. 22067f296bb3SBarry Smith$$ 22077f296bb3SBarry Smith 22087f296bb3SBarry SmithThat is, we require $g_k^T A_k du < 0$. 22097f296bb3SBarry Smith 22107f296bb3SBarry SmithIf the Newton direction is a descent direction, then we choose a penalty 22117f296bb3SBarry Smithparameter $\rho_k$ so that $du$ is also a sufficient descent 22127f296bb3SBarry Smithdirection for the augmented Lagrangian merit function. We then find 22137f296bb3SBarry Smith$\alpha$ to approximately minimize the augmented Lagrangian merit 22147f296bb3SBarry Smithfunction along the Newton direction. 22157f296bb3SBarry Smith 22167f296bb3SBarry Smith$$ 22177f296bb3SBarry Smith\displaystyle \min_{\alpha \geq 0} \; \tilde{f}_k(u_k + \alpha du, v_k). 22187f296bb3SBarry Smith$$ 22197f296bb3SBarry Smith 22207f296bb3SBarry SmithWe can enforce either the sufficient decrease condition or the Wolfe 22217f296bb3SBarry Smithconditions during the search procedure. The new point, 22227f296bb3SBarry Smith 22237f296bb3SBarry Smith$$ 22247f296bb3SBarry Smith\begin{array}{lcl} 22257f296bb3SBarry Smithu_{k+\frac{1}{2}} & = & u_k + \alpha_k du \\ 22267f296bb3SBarry Smithv_{k+\frac{1}{2}} & = & v_k, 22277f296bb3SBarry Smith\end{array} 22287f296bb3SBarry Smith$$ 22297f296bb3SBarry Smith 22307f296bb3SBarry Smithsatisfies the linear constraint 22317f296bb3SBarry Smith 22327f296bb3SBarry Smith$$ 22337f296bb3SBarry SmithA_k (u_{k+\frac{1}{2}} - u_k) + B_k (v_{k+\frac{1}{2}} - v_k) + \alpha_k g_k = 0. 22347f296bb3SBarry Smith$$ 22357f296bb3SBarry Smith 22367f296bb3SBarry SmithIf the Newton direction computed does not provide descent for the merit 22377f296bb3SBarry Smithfunction, then we can use the steepest descent direction 22387f296bb3SBarry Smith$du = -A_k^T g_k$ during the search procedure. However, the 22397f296bb3SBarry Smithimplication that the intermediate point approximately satisfies the 22407f296bb3SBarry Smithlinear constraint is no longer true. 22417f296bb3SBarry Smith 22427f296bb3SBarry Smith##### Modified Reduced-Space Step 22437f296bb3SBarry Smith 22447f296bb3SBarry SmithWe are now ready to compute a reduced-space step for the modified 22457f296bb3SBarry Smithoptimization problem: 22467f296bb3SBarry Smith 22477f296bb3SBarry Smith$$ 22487f296bb3SBarry Smith\begin{array}{ll} 22497f296bb3SBarry Smith\displaystyle \min_{u,v} & \tilde{f}_k(u, v) \\ 22507f296bb3SBarry Smith\text{subject to} & A_k (u-u_k) + B_k (v-v_k) + \alpha_k g_k = 0. 22517f296bb3SBarry Smith\end{array} 22527f296bb3SBarry Smith$$ 22537f296bb3SBarry Smith 22547f296bb3SBarry SmithWe begin with the change of variables 22557f296bb3SBarry Smith 22567f296bb3SBarry Smith$$ 22577f296bb3SBarry Smith\begin{array}{ll} 22587f296bb3SBarry Smith\displaystyle \min_{du,dv} & \tilde{f}_k(u_k+du, v_k+dv) \\ 22597f296bb3SBarry Smith\text{subject to} & A_k du + B_k dv + \alpha_k g_k = 0 22607f296bb3SBarry Smith\end{array} 22617f296bb3SBarry Smith$$ 22627f296bb3SBarry Smith 22637f296bb3SBarry Smithand make the substitution 22647f296bb3SBarry Smith 22657f296bb3SBarry Smith$$ 22667f296bb3SBarry Smithdu = -A_k^{-1}(B_k dv + \alpha_k g_k). 22677f296bb3SBarry Smith$$ 22687f296bb3SBarry Smith 22697f296bb3SBarry SmithHence, the unconstrained optimization problem we need to solve is 22707f296bb3SBarry Smith 22717f296bb3SBarry Smith$$ 22727f296bb3SBarry Smith\begin{array}{ll} 22737f296bb3SBarry Smith\displaystyle \min_{dv} & \tilde{f}_k(u_k-A_k^{-1}(B_k dv + \alpha_k g_k), v_k+dv), \\ 22747f296bb3SBarry Smith\end{array} 22757f296bb3SBarry Smith$$ 22767f296bb3SBarry Smith 22777f296bb3SBarry Smithwhich is equivalent to 22787f296bb3SBarry Smith 22797f296bb3SBarry Smith$$ 22807f296bb3SBarry Smith\begin{array}{ll} 22817f296bb3SBarry Smith\displaystyle \min_{dv} & \tilde{f}_k(u_{k+\frac{1}{2}} - A_k^{-1} B_k dv, v_{k+\frac{1}{2}}+dv). \\ 22827f296bb3SBarry Smith\end{array} 22837f296bb3SBarry Smith$$ 22847f296bb3SBarry Smith 22857f296bb3SBarry SmithWe apply one step of a limited-memory quasi-Newton method to this 22867f296bb3SBarry Smithproblem. The direction is obtain by solving the quadratic problem 22877f296bb3SBarry Smith 22887f296bb3SBarry Smith$$ 22897f296bb3SBarry Smith\begin{array}{ll} 22907f296bb3SBarry Smith\displaystyle \min_{dv} & \frac{1}{2} dv^T \tilde{H}_k dv + \tilde{g}_{k+\frac{1}{2}}^T dv, 22917f296bb3SBarry Smith\end{array} 22927f296bb3SBarry Smith$$ 22937f296bb3SBarry Smith 22947f296bb3SBarry Smithwhere $\tilde{H}_k$ is the limited-memory quasi-Newton 22957f296bb3SBarry Smithapproximation to the reduced Hessian matrix, a positive-definite matrix, 22967f296bb3SBarry Smithand $\tilde{g}_{k+\frac{1}{2}}$ is the reduced gradient. 22977f296bb3SBarry Smith 22987f296bb3SBarry Smith$$ 22997f296bb3SBarry Smith\begin{array}{lcl} 23007f296bb3SBarry Smith\tilde{g}_{k+\frac{1}{2}} & = & \nabla_v \tilde{f}_k(u_{k+\frac{1}{2}}, v_{k+\frac{1}{2}}) - 23017f296bb3SBarry Smith \nabla_u \tilde{f}_k(u_{k+\frac{1}{2}}, v_{k+\frac{1}{2}}) A_k^{-1} B_k \\ 23027f296bb3SBarry Smith & = & d_{k+\frac{1}{2}} + c_{k+\frac{1}{2}} A_k^{-1} B_k 23037f296bb3SBarry Smith\end{array} 23047f296bb3SBarry Smith$$ 23057f296bb3SBarry Smith 23067f296bb3SBarry SmithThe reduced gradient is obtained from one linearized adjoint solve 23077f296bb3SBarry Smith 23087f296bb3SBarry Smith$$ 23097f296bb3SBarry Smithy_{k+\frac{1}{2}} = A_k^{-T}c_{k+\frac{1}{2}} 23107f296bb3SBarry Smith$$ 23117f296bb3SBarry Smith 23127f296bb3SBarry Smithand some linear algebra 23137f296bb3SBarry Smith 23147f296bb3SBarry Smith$$ 23157f296bb3SBarry Smith\tilde{g}_{k+\frac{1}{2}} = d_{k+\frac{1}{2}} + y_{k+\frac{1}{2}}^T B_k. 23167f296bb3SBarry Smith$$ 23177f296bb3SBarry Smith 23187f296bb3SBarry SmithBecause the Hessian approximation is positive definite and we know its 23197f296bb3SBarry Smithinverse, we obtain the direction 23207f296bb3SBarry Smith 23217f296bb3SBarry Smith$$ 23227f296bb3SBarry Smithdv = -H_k^{-1} \tilde{g}_{k+\frac{1}{2}} 23237f296bb3SBarry Smith$$ 23247f296bb3SBarry Smith 23257f296bb3SBarry Smithand recover the full-space direction from one linearized forward solve, 23267f296bb3SBarry Smith 23277f296bb3SBarry Smith$$ 23287f296bb3SBarry Smithdu = -A_k^{-1} B_k dv. 23297f296bb3SBarry Smith$$ 23307f296bb3SBarry Smith 23317f296bb3SBarry SmithHaving the full-space direction, which satisfies the linear constraint, 23327f296bb3SBarry Smithwe now approximately minimize the augmented Lagrangian merit function 23337f296bb3SBarry Smithalong the direction. 23347f296bb3SBarry Smith 23357f296bb3SBarry Smith$$ 23367f296bb3SBarry Smith\begin{array}{lcl} 23377f296bb3SBarry Smith\displaystyle \min_{\beta \geq 0} & \tilde{f_k}(u_{k+\frac{1}{2}} + \beta du, v_{k+\frac{1}{2}} + \beta dv) 23387f296bb3SBarry Smith\end{array} 23397f296bb3SBarry Smith$$ 23407f296bb3SBarry Smith 23417f296bb3SBarry SmithWe enforce the Wolfe conditions during the search procedure. The new 23427f296bb3SBarry Smithpoint is 23437f296bb3SBarry Smith 23447f296bb3SBarry Smith$$ 23457f296bb3SBarry Smith\begin{array}{lcl} 23467f296bb3SBarry Smithu_{k+1} & = & u_{k+\frac{1}{2}} + \beta_k du \\ 23477f296bb3SBarry Smithv_{k+1} & = & v_{k+\frac{1}{2}} + \beta_k dv. 23487f296bb3SBarry Smith\end{array} 23497f296bb3SBarry Smith$$ 23507f296bb3SBarry Smith 23517f296bb3SBarry SmithThe reduced gradient at the new point is computed from 23527f296bb3SBarry Smith 23537f296bb3SBarry Smith$$ 23547f296bb3SBarry Smith\begin{array}{lcl} 23557f296bb3SBarry Smithy_{k+1} & = & A_k^{-T}c_{k+1} \\ 23567f296bb3SBarry Smith\tilde{g}_{k+1} & = & d_{k+1} - y_{k+1}^T B_k, 23577f296bb3SBarry Smith\end{array} 23587f296bb3SBarry Smith$$ 23597f296bb3SBarry Smith 23607f296bb3SBarry Smithwhere $c_{k+1} = \nabla_u \tilde{f}_k (u_{k+1},v_{k+1})$ and 23617f296bb3SBarry Smith$d_{k+1} = \nabla_v \tilde{f}_k (u_{k+1},v_{k+1})$. The 23627f296bb3SBarry Smithmultipliers $y_{k+1}$ become the multipliers used in the next 23637f296bb3SBarry Smithiteration of the code. The quantities $v_{k+\frac{1}{2}}$, 23647f296bb3SBarry Smith$v_{k+1}$, $\tilde{g}_{k+\frac{1}{2}}$, and 23657f296bb3SBarry Smith$\tilde{g}_{k+1}$ are used to update $H_k$ to obtain the 23667f296bb3SBarry Smithlimited-memory quasi-Newton approximation to the reduced Hessian matrix 23677f296bb3SBarry Smithused in the next iteration of the code. The update is skipped if it 23687f296bb3SBarry Smithcannot be performed. 23697f296bb3SBarry Smith 23707f296bb3SBarry Smith(sec_tao_leastsquares)= 23717f296bb3SBarry Smith 23727f296bb3SBarry Smith### Nonlinear Least-Squares 23737f296bb3SBarry Smith 23747f296bb3SBarry SmithGiven a function $F: \mathbb R^n \to \mathbb R^m$, the nonlinear 23757f296bb3SBarry Smithleast-squares problem minimizes 23767f296bb3SBarry Smith 23777f296bb3SBarry Smith$$ 23787f296bb3SBarry Smithf(x)= \| F(x) \|_2^2 = \sum_{i=1}^m F_i(x)^2. 23797f296bb3SBarry Smith$$ (eq_nlsf) 23807f296bb3SBarry Smith 23817f296bb3SBarry SmithThe nonlinear equations $F$ should be specified with the function 23827f296bb3SBarry Smith`TaoSetResidual()`. 23837f296bb3SBarry Smith 23847f296bb3SBarry Smith(sec_tao_pounders)= 23857f296bb3SBarry Smith 23867f296bb3SBarry Smith#### Bound-constrained Regularized Gauss-Newton (BRGN) 23877f296bb3SBarry Smith 23887f296bb3SBarry SmithThe TAOBRGN algorithms is a Gauss-Newton method is used to iteratively solve nonlinear least 23897f296bb3SBarry Smithsquares problem with the iterations 23907f296bb3SBarry Smith 23917f296bb3SBarry Smith$$ 23927f296bb3SBarry Smithx_{k+1} = x_k - \alpha_k(J_k^T J_k)^{-1} J_k^T r(x_k) 23937f296bb3SBarry Smith$$ 23947f296bb3SBarry Smith 23957f296bb3SBarry Smithwhere $r(x)$ is the least-squares residual vector, 23967f296bb3SBarry Smith$J_k = \partial r(x_k)/\partial x$ is the Jacobian of the 23977f296bb3SBarry Smithresidual, and $\alpha_k$ is the step length parameter. In other 23987f296bb3SBarry Smithwords, the Gauss-Newton method approximates the Hessian of the objective 23997f296bb3SBarry Smithas $H_k \approx (J_k^T J_k)$ and the gradient of the objective as 24007f296bb3SBarry Smith$g_k \approx -J_k r(x_k)$. The least-squares Jacobian, $J$, 24017f296bb3SBarry Smithshould be provided to Tao using `TaoSetJacobianResidual()` routine. 24027f296bb3SBarry Smith 24037f296bb3SBarry SmithThe BRGN (`-tao_type brgn`) implementation adds a regularization term $\beta(x)$ such 24047f296bb3SBarry Smiththat 24057f296bb3SBarry Smith 24067f296bb3SBarry Smith$$ 24077f296bb3SBarry Smith\min_{x} \; \frac{1}{2}||R(x)||_2^2 + \lambda\beta(x), 24087f296bb3SBarry Smith$$ 24097f296bb3SBarry Smith 24107f296bb3SBarry Smithwhere $\lambda$ is the scalar weight of the regularizer. BRGN 24117f296bb3SBarry Smithprovides two default implementations for $\beta(x)$: 24127f296bb3SBarry Smith 24137f296bb3SBarry Smith- **L2-norm** - $\beta(x) = \frac{1}{2}||x_k||_2^2$ 24147f296bb3SBarry Smith- **L2-norm Proximal Point** - 24157f296bb3SBarry Smith $\beta(x) = \frac{1}{2}||x_k - x_{k-1}||_2^2$ 24167f296bb3SBarry Smith- **L1-norm with Dictionary** - 24177f296bb3SBarry Smith $\beta(x) = ||Dx||_1 \approx \sum_{i} \sqrt{y_i^2 + \epsilon^2}-\epsilon$ 24187f296bb3SBarry Smith where $y = Dx$ and $\epsilon$ is the smooth approximation 24197f296bb3SBarry Smith parameter. 24207f296bb3SBarry Smith 24217f296bb3SBarry SmithThe regularizer weight can be controlled with either 24227f296bb3SBarry Smith`TaoBRGNSetRegularizerWeight()` or `-tao_brgn_regularizer_weight` 24237f296bb3SBarry Smithcommand line option, while the smooth approximation parameter can be set 24247f296bb3SBarry Smithwith either `TaoBRGNSetL1SmoothEpsilon()` or 24257f296bb3SBarry Smith`-tao_brgn_l1_smooth_epsilon`. For the L1-norm term, the user can 24267f296bb3SBarry Smithsupply a dictionary matrix with `TaoBRGNSetDictionaryMatrix()`. If no 24277f296bb3SBarry Smithdictionary is provided, the dictionary is assumed to be an identity 24287f296bb3SBarry Smithmatrix and the regularizer reduces to a sparse solution term. 24297f296bb3SBarry Smith 24307f296bb3SBarry SmithThe regularization selection can be made using the command line option 24317f296bb3SBarry Smith`-tao_brgn_regularization_type <l2pure, l2prox, l1dict, user>` where the `user` option allows 24327f296bb3SBarry Smiththe user to define a custom $\mathcal{C}2$-continuous 24337f296bb3SBarry Smithregularization term. This custom term can be defined by using the 24347f296bb3SBarry Smithinterface functions: 24357f296bb3SBarry Smith 24367f296bb3SBarry Smith- `TaoBRGNSetRegularizerObjectiveAndGradientRoutine()` - Provide 24377f296bb3SBarry Smith user-call back for evaluating the function value and gradient 24387f296bb3SBarry Smith evaluation for the regularization term. 24397f296bb3SBarry Smith- `TaoBRGNSetRegularizerHessianRoutine()` - Provide user call-back 24407f296bb3SBarry Smith for evaluating the Hessian of the regularization term. 24417f296bb3SBarry Smith 24427f296bb3SBarry Smith#### POUNDERS 24437f296bb3SBarry Smith 24447f296bb3SBarry SmithOne algorithm for solving the least squares problem 24457f296bb3SBarry Smith({eq}`eq_nlsf`) when the Jacobian of the residual vector 24467f296bb3SBarry Smith$F$ is unavailable is the model-based POUNDERS (Practical 24477f296bb3SBarry SmithOptimization Using No Derivatives for sums of Squares) algorithm 24487f296bb3SBarry Smith(`tao_pounders`). POUNDERS employs a derivative-free trust-region 24497f296bb3SBarry Smithframework as described in {cite}`dfobook` in order to 24507f296bb3SBarry Smithconverge to local minimizers. An example of this version of POUNDERS 24517f296bb3SBarry Smithapplied to a practical least-squares problem can be found in 24527f296bb3SBarry Smith{cite}`unedf0`. 24537f296bb3SBarry Smith 24547f296bb3SBarry Smith##### Derivative-Free Trust-Region Algorithm 24557f296bb3SBarry Smith 24567f296bb3SBarry SmithIn each iteration $k$, the algorithm maintains a model 24577f296bb3SBarry Smith$m_k(x)$, described below, of the nonlinear least squares function 24587f296bb3SBarry Smith$f$ centered about the current iterate $x_k$. 24597f296bb3SBarry Smith 24607f296bb3SBarry SmithIf one assumes that the maximum number of function evaluations has not 24617f296bb3SBarry Smithbeen reached and that $\|\nabla m_k(x_k)\|_2>$`gtol`, the next 24627f296bb3SBarry Smithpoint $x_+$ to be evaluated is obtained by solving the 24637f296bb3SBarry Smithtrust-region subproblem 24647f296bb3SBarry Smith 24657f296bb3SBarry Smith$$ 24667f296bb3SBarry Smith\min\left\{ 24677f296bb3SBarry Smith m_k(x) : 24687f296bb3SBarry Smith \|x-x_k\|_{p} \leq \Delta_k, 24697f296bb3SBarry Smith \right \}, 24707f296bb3SBarry Smith$$ (eq_poundersp) 24717f296bb3SBarry Smith 24727f296bb3SBarry Smithwhere $\Delta_k$ is the current trust-region radius. By default we 24737f296bb3SBarry Smithuse a trust-region norm with $p=\infty$ and solve 24747f296bb3SBarry Smith({eq}`eq_poundersp`) with the BLMVM method described in 24757f296bb3SBarry Smith{any}`sec_tao_blmvm`. While the subproblem is a 24767f296bb3SBarry Smithbound-constrained quadratic program, it may not be convex and the BQPIP 24777f296bb3SBarry Smithand GPCG methods may not solve the subproblem. Therefore, a bounded 24787f296bb3SBarry SmithNewton-Krylov Method should be used; the default is the BNTR 24797f296bb3SBarry Smithalgorithm. Note: BNTR uses its own internal 24807f296bb3SBarry Smithtrust region that may interfere with the infinity-norm trust region used 24817f296bb3SBarry Smithin the model problem ({eq}`eq_poundersp`). 24827f296bb3SBarry Smith 24837f296bb3SBarry SmithThe residual vector is then evaluated to obtain $F(x_+)$ and hence 24847f296bb3SBarry Smith$f(x_+)$. The ratio of actual decrease to predicted decrease, 24857f296bb3SBarry Smith 24867f296bb3SBarry Smith$$ 24877f296bb3SBarry Smith\rho_k = \frac{f(x_k)-f(x_+)}{m_k(x_k)-m_k(x_+)}, 24887f296bb3SBarry Smith$$ 24897f296bb3SBarry Smith 24907f296bb3SBarry Smithas well as an indicator, `valid`, on the model’s quality of 24917f296bb3SBarry Smithapproximation on the trust region is then used to update the iterate, 24927f296bb3SBarry Smith 24937f296bb3SBarry Smith$$ 24947f296bb3SBarry Smithx_{k+1} = \left\{\begin{array}{ll} 24957f296bb3SBarry Smithx_+ & \text{if } \rho_k \geq \eta_1 \\ 24967f296bb3SBarry Smithx_+ & \text{if } 0<\rho_k <\eta_1 \text{ and \texttt{valid}=\texttt{true}} 24977f296bb3SBarry Smith\\ 24987f296bb3SBarry Smithx_k & \text{else}, 24997f296bb3SBarry Smith\end{array} 25007f296bb3SBarry Smith\right. 25017f296bb3SBarry Smith$$ 25027f296bb3SBarry Smith 25037f296bb3SBarry Smithand trust-region radius, 25047f296bb3SBarry Smith 25057f296bb3SBarry Smith$$ 25067f296bb3SBarry Smith\Delta_{k+1} = \left\{\begin{array}{ll} 25077f296bb3SBarry Smith \text{min}(\gamma_1\Delta_k, \Delta_{\max}) & \text{if } \rho_k \geq 25087f296bb3SBarry Smith\eta_1 \text{ and } \|x_+-x_k\|_p\geq \omega_1\Delta_k \\ 25097f296bb3SBarry Smith\gamma_0\Delta_k & \text{if } \rho_k < \eta_1 \text{ and 25107f296bb3SBarry Smith\texttt{valid}=\texttt{true}} \\ 25117f296bb3SBarry Smith\Delta_k & \text{else,} 25127f296bb3SBarry Smith\end{array} 25137f296bb3SBarry Smith\right. 25147f296bb3SBarry Smith$$ 25157f296bb3SBarry Smith 25167f296bb3SBarry Smithwhere $0 < \eta_1 < 1$, $0 < \gamma_0 < 1 < \gamma_1$, 25177f296bb3SBarry Smith$0<\omega_1<1$, and $\Delta_{\max}$ are constants. 25187f296bb3SBarry Smith 25197f296bb3SBarry SmithIf $\rho_k\leq 0$ and `valid` is `false`, the iterate and 25207f296bb3SBarry Smithtrust-region radius remain unchanged after the above updates, and the 25217f296bb3SBarry Smithalgorithm tests whether the direction $x_+-x_k$ improves the 25227f296bb3SBarry Smithmodel. If not, the algorithm performs an additional evaluation to obtain 25237f296bb3SBarry Smith$F(x_k+d_k)$, where $d_k$ is a model-improving direction. 25247f296bb3SBarry Smith 25257f296bb3SBarry SmithThe iteration counter is then updated, and the next model $m_{k}$ 25267f296bb3SBarry Smithis obtained as described next. 25277f296bb3SBarry Smith 25287f296bb3SBarry Smith##### Forming the Trust-Region Model 25297f296bb3SBarry Smith 25307f296bb3SBarry SmithIn each iteration, POUNDERS uses a subset of the available evaluated 25317f296bb3SBarry Smithresidual vectors $\{ F(y_1), F(y_2), \cdots \}$ to form an 25327f296bb3SBarry Smithinterpolatory quadratic model of each residual component. The $m$ 25337f296bb3SBarry Smithquadratic models 25347f296bb3SBarry Smith 25357f296bb3SBarry Smith$$ 25367f296bb3SBarry Smithq_k^{(i)}(x) = 25377f296bb3SBarry 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), 25387f296bb3SBarry Smith \qquad i = 1, \ldots, m 25397f296bb3SBarry Smith$$ (eq_models) 25407f296bb3SBarry Smith 25417f296bb3SBarry Smiththus satisfy the interpolation conditions 25427f296bb3SBarry Smith 25437f296bb3SBarry Smith$$ 25447f296bb3SBarry Smithq_k^{(i)}(y_j) = F_i(y_j), \qquad i=1, \ldots, m; \, j=1,\ldots , l_k 25457f296bb3SBarry Smith$$ 25467f296bb3SBarry Smith 25477f296bb3SBarry Smithon a common interpolation set $\{y_1, \cdots , y_{l_k}\}$ of size 25487f296bb3SBarry Smith$l_k\in[n+1,$`npmax`$]$. 25497f296bb3SBarry Smith 25507f296bb3SBarry SmithThe gradients and Hessians of the models in 25517f296bb3SBarry Smith{any}`eq_models` are then used to construct the main 25527f296bb3SBarry Smithmodel, 25537f296bb3SBarry Smith 25547f296bb3SBarry Smith$$ 25557f296bb3SBarry Smithm_k(x) = f(x_k) + 25567f296bb3SBarry Smith$$ (eq_newton2) 25577f296bb3SBarry Smith 25587f296bb3SBarry Smith$$ 25597f296bb3SBarry 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). 25607f296bb3SBarry Smith$$ 25617f296bb3SBarry Smith 25627f296bb3SBarry SmithThe process of forming these models also computes the indicator 25637f296bb3SBarry Smith`valid` of the model’s local quality. 25647f296bb3SBarry Smith 25657f296bb3SBarry Smith##### Parameters 25667f296bb3SBarry Smith 25677f296bb3SBarry SmithPOUNDERS supports the following parameters that can be set from the 25687f296bb3SBarry Smithcommand line or PETSc options file: 25697f296bb3SBarry Smith 25707f296bb3SBarry Smith`-tao_pounders_delta <delta>` 25717f296bb3SBarry Smith 25727f296bb3SBarry Smith: The initial trust-region radius ($>0$, real). This is used to 25737f296bb3SBarry Smith determine the size of the initial neighborhood within which the 25747f296bb3SBarry Smith algorithm should look. 25757f296bb3SBarry Smith 25767f296bb3SBarry Smith`-tao_pounders_npmax <npmax>` 25777f296bb3SBarry Smith 25787f296bb3SBarry Smith: The maximum number of interpolation points used ($n+2\leq$ 25797f296bb3SBarry Smith `npmax` $\leq 0.5(n+1)(n+2)$). This input is made available 25807f296bb3SBarry Smith to advanced users. We recommend the default value 25817f296bb3SBarry Smith (`npmax`$=2n+1$) be used by others. 25827f296bb3SBarry Smith 25837f296bb3SBarry Smith`-tao_pounders_gqt` 25847f296bb3SBarry Smith 25857f296bb3SBarry Smith: Use the gqt algorithm to solve the 25867f296bb3SBarry Smith subproblem ({eq}`eq_poundersp`) (uses $p=2$) 25877f296bb3SBarry Smith instead of BQPIP. 25887f296bb3SBarry Smith 25897f296bb3SBarry Smith`-pounders_subsolver` 25907f296bb3SBarry Smith 25917f296bb3SBarry Smith: If the default BQPIP algorithm is used to solve the 25927f296bb3SBarry Smith subproblem ({eq}`eq_poundersp`), the parameters of 25937f296bb3SBarry Smith the subproblem solver can be accessed using the command line options 25947f296bb3SBarry Smith prefix `-pounders_subsolver_`. For example, 25957f296bb3SBarry Smith 25967f296bb3SBarry Smith ``` 25977f296bb3SBarry Smith -pounders_subsolver_tao_gatol 1.0e-5 25987f296bb3SBarry Smith ``` 25997f296bb3SBarry Smith 26007f296bb3SBarry Smith sets the gradient tolerance of the subproblem solver to 26017f296bb3SBarry Smith $10^{-5}$. 26027f296bb3SBarry Smith 26037f296bb3SBarry SmithAdditionally, the user provides an initial solution vector, a vector for 26047f296bb3SBarry Smithstoring the separable objective function, and a routine for evaluating 26057f296bb3SBarry Smiththe residual vector $F$. These are described in detail in 26067f296bb3SBarry Smith{any}`sec_tao_fghj` and 26077f296bb3SBarry Smith{any}`sec_tao_evalsof`. Here we remark that because gradient 26087f296bb3SBarry Smithinformation is not available for scaling purposes, it can be useful to 26097f296bb3SBarry Smithensure that the problem is reasonably well scaled. A simple way to do so 26107f296bb3SBarry Smithis to rescale the decision variables $x$ so that their typical 26117f296bb3SBarry Smithvalues are expected to lie within the unit hypercube $[0,1]^n$. 26127f296bb3SBarry Smith 26137f296bb3SBarry Smith##### Convergence Notes 26147f296bb3SBarry Smith 26157f296bb3SBarry SmithBecause the gradient function is not provided to POUNDERS, the norm of 26167f296bb3SBarry Smiththe gradient of the objective function is not available. Therefore, for 26177f296bb3SBarry Smithconvergence criteria, this norm is approximated by the norm of the model 26187f296bb3SBarry Smithgradient and used only when the model gradient is deemed to be a 26197f296bb3SBarry Smithreasonable approximation of the gradient of the objective. In practice, 26207f296bb3SBarry Smiththe typical grounds for termination for expensive derivative-free 26217f296bb3SBarry Smithproblems is the maximum number of function evaluations allowed. 26227f296bb3SBarry Smith 26237f296bb3SBarry Smith(sec_tao_complementarity)= 26247f296bb3SBarry Smith 26257f296bb3SBarry Smith### Complementarity 26267f296bb3SBarry Smith 26277f296bb3SBarry SmithMixed complementarity problems, or box-constrained variational 26287f296bb3SBarry Smithinequalities, are related to nonlinear systems of equations. They are 26297f296bb3SBarry Smithdefined by a continuously differentiable function, 26307f296bb3SBarry Smith$F:\mathbb R^n \to \mathbb R^n$, and bounds, 26317f296bb3SBarry Smith$\ell \in \{\mathbb R\cup \{-\infty\}\}^n$ and 26327f296bb3SBarry Smith$u \in \{\mathbb R\cup \{\infty\}\}^n$, on the variables such that 26337f296bb3SBarry Smith$\ell \leq u$. Given this information, 26347f296bb3SBarry Smith$\mathbf{x}^* \in [\ell,u]$ is a solution to 26357f296bb3SBarry SmithMCP($F$, $\ell$, $u$) if for each 26367f296bb3SBarry Smith$i \in \{1, \ldots, n\}$ we have at least one of the following: 26377f296bb3SBarry Smith 26387f296bb3SBarry Smith$$ 26397f296bb3SBarry Smith\begin{aligned} 26407f296bb3SBarry Smith\begin{array}{ll} 26417f296bb3SBarry SmithF_i(x^*) \geq 0 & \text{if } x^*_i = \ell_i \\ 26427f296bb3SBarry SmithF_i(x^*) = 0 & \text{if } \ell_i < x^*_i < u_i \\ 26437f296bb3SBarry SmithF_i(x^*) \leq 0 & \text{if } x^*_i = u_i. 26447f296bb3SBarry Smith\end{array}\end{aligned} 26457f296bb3SBarry Smith$$ 26467f296bb3SBarry Smith 26477f296bb3SBarry SmithNote that when $\ell = \{-\infty\}^n$ and 26487f296bb3SBarry Smith$u = \{\infty\}^n$, we have a nonlinear system of equations, and 26497f296bb3SBarry Smith$\ell = \{0\}^n$ and $u = \{\infty\}^n$ correspond to the 26507f296bb3SBarry Smithnonlinear complementarity problem {cite}`cottle:nonlinear`. 26517f296bb3SBarry Smith 26527f296bb3SBarry SmithSimple complementarity conditions arise from the first-order optimality 26537f296bb3SBarry Smithconditions from optimization 26547f296bb3SBarry Smith{cite}`karush:minima` {cite}`kuhn.tucker:nonlinear`. In the simple 26557f296bb3SBarry Smithbound-constrained optimization case, these conditions correspond to 26567f296bb3SBarry SmithMCP($\nabla f$, $\ell$, $u$), where 26577f296bb3SBarry Smith$f: \mathbb R^n \to \mathbb R$ is the objective function. In a 26587f296bb3SBarry Smithone-dimensional setting these conditions are intuitive. If the solution 26597f296bb3SBarry Smithis at the lower bound, then the function must be increasing and 26607f296bb3SBarry Smith$\nabla f \geq 0$. If the solution is at the upper bound, then the 26617f296bb3SBarry Smithfunction must be decreasing and $\nabla f \leq 0$. If the solution 26627f296bb3SBarry Smithis strictly between the bounds, we must be at a stationary point and 26637f296bb3SBarry Smith$\nabla f = 0$. Other complementarity problems arise in economics 26647f296bb3SBarry Smithand engineering {cite}`ferris.pang:engineering`, game theory 26657f296bb3SBarry Smith{cite}`nash:equilibrium`, and finance 26667f296bb3SBarry Smith{cite}`huang.pang:option`. 26677f296bb3SBarry Smith 26687f296bb3SBarry SmithEvaluation routines for $F$ and its Jacobian must be supplied 26697f296bb3SBarry Smithprior to solving the application. The bounds, $[\ell,u]$, on the 26707f296bb3SBarry Smithvariables must also be provided. If no starting point is supplied, a 26717f296bb3SBarry Smithdefault starting point of all zeros is used. 26727f296bb3SBarry Smith 26737f296bb3SBarry Smith#### Semismooth Methods 26747f296bb3SBarry Smith 26757f296bb3SBarry SmithTAO has two implementations of semismooth algorithms 26767f296bb3SBarry Smith{cite}`munson.facchinei.ea:semismooth` {cite}`deluca.facchinei.ea:semismooth` 26777f296bb3SBarry Smith{cite}`facchinei.fischer.ea:semismooth` for solving mixed complementarity 26787f296bb3SBarry Smithproblems. Both are based on a reformulation of the mixed complementarity 26797f296bb3SBarry Smithproblem as a nonsmooth system of equations using the Fischer-Burmeister 26807f296bb3SBarry Smithfunction {cite}`fischer:special`. A nonsmooth Newton method 26817f296bb3SBarry Smithis applied to the reformulated system to calculate a solution. The 26827f296bb3SBarry Smiththeoretical properties of such methods are detailed in the 26837f296bb3SBarry Smithaforementioned references. 26847f296bb3SBarry Smith 26857f296bb3SBarry SmithThe Fischer-Burmeister function, $\phi:\mathbb R^2 \to \mathbb R$, 26867f296bb3SBarry Smithis defined as 26877f296bb3SBarry Smith 26887f296bb3SBarry Smith$$ 26897f296bb3SBarry Smith\begin{aligned} 26907f296bb3SBarry Smith\phi(a,b) := \sqrt{a^2 + b^2} - a - b.\end{aligned} 26917f296bb3SBarry Smith$$ 26927f296bb3SBarry Smith 26937f296bb3SBarry SmithThis function has the following key property, 26947f296bb3SBarry Smith 26957f296bb3SBarry Smith$$ 26967f296bb3SBarry Smith\begin{aligned} 26977f296bb3SBarry Smith\begin{array}{lcr} 26987f296bb3SBarry Smith \phi(a,b) = 0 & \Leftrightarrow & a \geq 0,\; b \geq 0,\; ab = 0, 26997f296bb3SBarry Smith\end{array}\end{aligned} 27007f296bb3SBarry Smith$$ 27017f296bb3SBarry Smith 27027f296bb3SBarry Smithused when reformulating the mixed complementarity problem as the system 27037f296bb3SBarry Smithof equations $\Phi(x) = 0$, where 27047f296bb3SBarry Smith$\Phi:\mathbb R^n \to \mathbb R^n$. The reformulation is defined 27057f296bb3SBarry Smithcomponentwise as 27067f296bb3SBarry Smith 27077f296bb3SBarry Smith$$ 27087f296bb3SBarry Smith\begin{aligned} 27097f296bb3SBarry Smith\Phi_i(x) := \left\{ \begin{array}{ll} 27107f296bb3SBarry Smith \phi(x_i - l_i, F_i(x)) & \text{if } -\infty < l_i < u_i = \infty, \\ 27117f296bb3SBarry Smith -\phi(u_i-x_i, -F_i(x)) & \text{if } -\infty = l_i < u_i < \infty, \\ 27127f296bb3SBarry Smith \phi(x_i - l_i, \phi(u_i - x_i, - F_i(x))) & \text{if } -\infty < l_i < u_i < \infty, \\ 27137f296bb3SBarry Smith -F_i(x) & \text{if } -\infty = l_i < u_i = \infty, \\ 27147f296bb3SBarry Smith l_i - x_i & \text{if } -\infty < l_i = u_i < \infty. 27157f296bb3SBarry Smith \end{array} \right.\end{aligned} 27167f296bb3SBarry Smith$$ 27177f296bb3SBarry Smith 27187f296bb3SBarry SmithWe note that $\Phi$ is not differentiable everywhere but satisfies 27197f296bb3SBarry Smitha semismoothness property 27207f296bb3SBarry Smith{cite}`mifflin:semismooth` {cite}`qi:convergence` {cite}`qi.sun:nonsmooth`. 27217f296bb3SBarry SmithFurthermore, the natural merit function, 27227f296bb3SBarry Smith$\Psi(x) := \frac{1}{2} \| \Phi(x) \|_2^2$, is continuously 27237f296bb3SBarry Smithdifferentiable. 27247f296bb3SBarry Smith 27257f296bb3SBarry SmithThe two semismooth TAO solvers both solve the system $\Phi(x) = 0$ 27267f296bb3SBarry Smithby applying a nonsmooth Newton method with a line search. We calculate a 27277f296bb3SBarry Smithdirection, $d^k$, by solving the system 27287f296bb3SBarry Smith$H^kd^k = -\Phi(x^k)$, where $H^k$ is an element of the 27297f296bb3SBarry Smith$B$-subdifferential {cite}`qi.sun:nonsmooth` of 27307f296bb3SBarry Smith$\Phi$ at $x^k$. If the direction calculated does not 27317f296bb3SBarry Smithsatisfy a suitable descent condition, then we use the negative gradient 27327f296bb3SBarry Smithof the merit function, $-\nabla \Psi(x^k)$, as the search 27337f296bb3SBarry Smithdirection. A standard Armijo search 27347f296bb3SBarry Smith{cite}`armijo:minimization` is used to find the new 27357f296bb3SBarry Smithiteration. Nonmonotone searches 27367f296bb3SBarry Smith{cite}`grippo.lampariello.ea:nonmonotone` are also available 27377f296bb3SBarry Smithby setting appropriate runtime options. See 27387f296bb3SBarry Smith{any}`sec_tao_linesearch` for further details. 27397f296bb3SBarry Smith 27407f296bb3SBarry SmithThe first semismooth algorithm available in TAO is not guaranteed to 27417f296bb3SBarry Smithremain feasible with respect to the bounds, $[\ell, u]$, and is 27427f296bb3SBarry Smithtermed an infeasible semismooth method. This method can be specified by 27437f296bb3SBarry Smithusing the `tao_ssils` solver. In this case, the descent test used is 27447f296bb3SBarry Smiththat 27457f296bb3SBarry Smith 27467f296bb3SBarry Smith$$ 27477f296bb3SBarry Smith\begin{aligned} 27487f296bb3SBarry Smith\nabla \Psi(x^k)^Td^k \leq -\delta\| d^k \|^\rho.\end{aligned} 27497f296bb3SBarry Smith$$ 27507f296bb3SBarry Smith 27517f296bb3SBarry SmithBoth $\delta > 0$ and $\rho > 2$ can be modified by using 27527f296bb3SBarry Smiththe runtime options `-tao_ssils_delta <delta>` and 27537f296bb3SBarry Smith`-tao_ssils_rho <rho>`, respectively. By default, 27547f296bb3SBarry Smith$\delta = 10^{-10}$ and $\rho = 2.1$. 27557f296bb3SBarry Smith 27567f296bb3SBarry SmithAn alternative is to remain feasible with respect to the bounds by using 27577f296bb3SBarry Smitha projected Armijo line search. This method can be specified by using 27587f296bb3SBarry Smiththe `tao_ssfls` solver. The descent test used is the same as above 27597f296bb3SBarry Smithwhere the direction in this case corresponds to the first part of the 27607f296bb3SBarry Smithpiecewise linear arc searched by the projected line search. Both 27617f296bb3SBarry Smith$\delta > 0$ and $\rho > 2$ can be modified by using the 27627f296bb3SBarry Smithruntime options `-tao_ssfls_delta <delta>` and 27637f296bb3SBarry Smith`-tao_ssfls_rho <rho>` respectively. By default, 27647f296bb3SBarry Smith$\delta = 10^{-10}$ and $\rho = 2.1$. 27657f296bb3SBarry Smith 27667f296bb3SBarry SmithThe recommended algorithm is the infeasible semismooth method, 27677f296bb3SBarry Smith`tao_ssils`, because of its strong global and local convergence 27687f296bb3SBarry Smithproperties. However, if it is known that $F$ is not defined 27697f296bb3SBarry Smithoutside of the box, $[\ell,u]$, perhaps because of the presence of 27707f296bb3SBarry Smith$\log$ functions, the feasibility-enforcing version of the 27717f296bb3SBarry Smithalgorithm, `tao_ssfls`, is a reasonable alternative. 27727f296bb3SBarry Smith 27737f296bb3SBarry Smith#### Active-Set Methods 27747f296bb3SBarry Smith 27757f296bb3SBarry SmithTAO also contained two active-set semismooth methods for solving 27767f296bb3SBarry Smithcomplementarity problems. These methods solve a reduced system 27777f296bb3SBarry Smithconstructed by block elimination of active constraints. The 27787f296bb3SBarry Smithsubdifferential in these cases enables this block elimination. 27797f296bb3SBarry Smith 27807f296bb3SBarry SmithThe first active-set semismooth algorithm available in TAO is not guaranteed to 27817f296bb3SBarry Smithremain feasible with respect to the bounds, $[\ell, u]$, and is 27827f296bb3SBarry Smithtermed an infeasible active-set semismooth method. This method can be 27837f296bb3SBarry Smithspecified by using the `tao_asils` solver. 27847f296bb3SBarry Smith 27857f296bb3SBarry SmithAn alternative is to remain feasible with respect to the bounds by using 27867f296bb3SBarry Smitha projected Armijo line search. This method can be specified by using 27877f296bb3SBarry Smiththe `tao_asfls` solver. 27887f296bb3SBarry Smith 27897f296bb3SBarry Smith(sec_tao_quadratic)= 27907f296bb3SBarry Smith 27917f296bb3SBarry Smith### Quadratic Solvers 27927f296bb3SBarry Smith 27937f296bb3SBarry SmithQuadratic solvers solve optimization problems of the form 27947f296bb3SBarry Smith 27957f296bb3SBarry Smith$$ 27967f296bb3SBarry Smith\begin{array}{ll} 27977f296bb3SBarry Smith\displaystyle \min_{x} & \frac{1}{2}x^T Q x + c^T x \\ 27987f296bb3SBarry Smith\text{subject to} & l \geq x \geq u 27997f296bb3SBarry Smith\end{array} 28007f296bb3SBarry Smith$$ 28017f296bb3SBarry Smith 28027f296bb3SBarry Smithwhere the gradient and the Hessian of the objective are both constant. 28037f296bb3SBarry Smith 28047f296bb3SBarry Smith#### Gradient Projection Conjugate Gradient Method (GPCG) 28057f296bb3SBarry Smith 28067f296bb3SBarry SmithThe GPCG {cite}`more-toraldo` algorithm is much like the 28077f296bb3SBarry SmithTRON algorithm, discussed in Section {any}`sec_tao_tron`, except that 28087f296bb3SBarry Smithit assumes that the objective function is quadratic and convex. 28097f296bb3SBarry SmithTherefore, it evaluates the function, gradient, and Hessian only once. 28107f296bb3SBarry SmithSince the objective function is quadratic, the algorithm does not use a 28117f296bb3SBarry Smithtrust region. All the options that apply to TRON except for trust-region 28127f296bb3SBarry Smithoptions also apply to GPCG. It can be set by using the TAO solver 28137f296bb3SBarry Smith`tao_gpcg` or via the optio flag `-tao_type gpcg`. 28147f296bb3SBarry Smith 28157f296bb3SBarry Smith(sec_tao_bqpip)= 28167f296bb3SBarry Smith 28177f296bb3SBarry Smith#### Interior-Point Newton’s Method (BQPIP) 28187f296bb3SBarry Smith 28197f296bb3SBarry SmithThe BQPIP algorithm is an interior-point method for bound constrained 28207f296bb3SBarry Smithquadratic optimization. It can be set by using the TAO solver of 28217f296bb3SBarry Smith`tao_bqpip` or via the option flag `-tao_type bgpip`. Since it 28227f296bb3SBarry Smithassumes the objective function is quadratic, it evaluates the function, 28237f296bb3SBarry Smithgradient, and Hessian only once. This method also requires the solution 28247f296bb3SBarry Smithof systems of linear equations, whose solver can be accessed and 28257f296bb3SBarry Smithmodified with the command `TaoGetKSP()`. 28267f296bb3SBarry Smith 28277f296bb3SBarry Smith### Legacy and Contributed Solvers 28287f296bb3SBarry Smith 28297f296bb3SBarry Smith#### Bundle Method for Regularized Risk Minimization (BMRM) 28307f296bb3SBarry Smith 28317f296bb3SBarry SmithBMRM is a numerical approach to optimizing an 28327f296bb3SBarry Smithunconstrained objective in the form of 28337f296bb3SBarry Smith$f(x) + 0.5 * \lambda \| x \|^2$. Here $f$ is a convex 28347f296bb3SBarry Smithfunction that is finite on the whole space. $\lambda$ is a 28357f296bb3SBarry Smithpositive weight parameter, and $\| x \|$ is the Euclidean norm of 28367f296bb3SBarry Smith$x$. The algorithm only requires a routine which, given an 28377f296bb3SBarry Smith$x$, returns the value of $f(x)$ and the gradient of 28387f296bb3SBarry Smith$f$ at $x$. 28397f296bb3SBarry Smith 28407f296bb3SBarry Smith#### Orthant-Wise Limited-memory Quasi-Newton (OWLQN) 28417f296bb3SBarry Smith 28427f296bb3SBarry SmithOWLQN {cite}`owlqn` is a numerical approach to optimizing 28437f296bb3SBarry Smithan unconstrained objective in the form of 28447f296bb3SBarry Smith$f(x) + \lambda \|x\|_1$. Here f is a convex and differentiable 28457f296bb3SBarry Smithfunction, $\lambda$ is a positive weight parameter, and 28467f296bb3SBarry Smith$\| x \|_1$ is the $\ell_1$ norm of $x$: 28477f296bb3SBarry Smith$\sum_i |x_i|$. The algorithm only requires evaluating the value 28487f296bb3SBarry Smithof $f$ and its gradient. 28497f296bb3SBarry Smith 28507f296bb3SBarry Smith(sec_tao_tron)= 28517f296bb3SBarry Smith 28527f296bb3SBarry Smith#### Trust-Region Newton Method (TRON) 28537f296bb3SBarry Smith 28547f296bb3SBarry SmithThe TRON {cite}`lin_c3` algorithm is an active-set method 28557f296bb3SBarry Smiththat uses a combination of gradient projections and a preconditioned 28567f296bb3SBarry Smithconjugate gradient method to minimize an objective function. Each 28577f296bb3SBarry Smithiteration of the TRON algorithm requires function, gradient, and Hessian 28587f296bb3SBarry Smithevaluations. In each iteration, the algorithm first applies several 28597f296bb3SBarry Smithconjugate gradient iterations. After these iterates, the TRON solver 28607f296bb3SBarry Smithmomentarily ignores the variables that equal one of its bounds and 28617f296bb3SBarry Smithapplies a preconditioned conjugate gradient method to a quadratic model 28627f296bb3SBarry Smithof the remaining set of *free* variables. 28637f296bb3SBarry Smith 28647f296bb3SBarry SmithThe TRON algorithm solves a reduced linear system defined by the rows 28657f296bb3SBarry Smithand columns corresponding to the variables that lie between the upper 28667f296bb3SBarry Smithand lower bounds. The TRON algorithm applies a trust region to the 28677f296bb3SBarry Smithconjugate gradients to ensure convergence. The initial trust-region 28687f296bb3SBarry Smithradius can be set by using the command 28697f296bb3SBarry Smith`TaoSetInitialTrustRegionRadius()`, and the current trust region size 28707f296bb3SBarry Smithcan be found by using the command `TaoGetCurrentTrustRegionRadius()`. 28717f296bb3SBarry SmithThe initial trust region can significantly alter the rate of convergence 28727f296bb3SBarry Smithfor the algorithm and should be tuned and adjusted for optimal 28737f296bb3SBarry Smithperformance. 28747f296bb3SBarry Smith 28757f296bb3SBarry SmithThis algorithm will be deprecated in the next version in favor of the 28767f296bb3SBarry SmithBounded Newton Trust Region (BNTR) algorithm. 28777f296bb3SBarry Smith 28787f296bb3SBarry Smith(sec_tao_blmvm)= 28797f296bb3SBarry Smith 28807f296bb3SBarry Smith#### Bound-constrained Limited-Memory Variable-Metric Method (BLMVM) 28817f296bb3SBarry Smith 28827f296bb3SBarry SmithBLMVM is a limited-memory, variable-metric method and is the 28837f296bb3SBarry Smithbound-constrained variant of the LMVM method for unconstrained 28847f296bb3SBarry Smithoptimization. It uses projected gradients to approximate the Hessian, 28857f296bb3SBarry Smitheliminating the need for Hessian evaluations. The method can be set by 28867f296bb3SBarry Smithusing the TAO solver `tao_blmvm`. For more details, please see the 28877f296bb3SBarry SmithLMVM section in the unconstrained algorithms as well as the LMVM matrix 28887f296bb3SBarry Smithdocumentation in the PETSc manual. 28897f296bb3SBarry Smith 28907f296bb3SBarry SmithThis algorithm will be deprecated in the next version in favor of the 28917f296bb3SBarry SmithBounded Quasi-Newton Line Search (BQNLS) algorithm. 28927f296bb3SBarry Smith 28937f296bb3SBarry Smith## Advanced Options 28947f296bb3SBarry Smith 28957f296bb3SBarry SmithThis section discusses options and routines that apply to most TAO 28967f296bb3SBarry Smithsolvers and problem classes. In particular, we focus on linear solvers, 28977f296bb3SBarry Smithconvergence tests, and line searches. 28987f296bb3SBarry Smith 28997f296bb3SBarry Smith(sec_tao_linearsolvers)= 29007f296bb3SBarry Smith 29017f296bb3SBarry Smith### Linear Solvers 29027f296bb3SBarry Smith 29037f296bb3SBarry SmithOne of the most computationally intensive phases of many optimization 29047f296bb3SBarry Smithalgorithms involves the solution of linear systems of equations. The 29057f296bb3SBarry Smithperformance of the linear solver may be critical to an efficient 29067f296bb3SBarry Smithcomputation of the solution. Since linear equation solvers often have a 29077f296bb3SBarry Smithwide variety of options associated with them, TAO allows the user to 29087f296bb3SBarry Smithaccess the linear solver with the 29097f296bb3SBarry Smith 29107f296bb3SBarry Smith``` 29117f296bb3SBarry SmithTaoGetKSP(Tao, KSP *); 29127f296bb3SBarry Smith``` 29137f296bb3SBarry Smith 29147f296bb3SBarry Smithcommand. With access to the KSP object, users can customize it for their 29157f296bb3SBarry Smithapplication to achieve improved performance. Additional details on the 29167f296bb3SBarry SmithKSP options in PETSc can be found in the {doc}`/manual/index`. 29177f296bb3SBarry Smith 29187f296bb3SBarry Smith### Monitors 29197f296bb3SBarry Smith 29207f296bb3SBarry SmithBy default the TAO solvers run silently without displaying information 29217f296bb3SBarry Smithabout the iterations. The user can initiate monitoring with the command 29227f296bb3SBarry Smith 29237f296bb3SBarry Smith``` 29247f296bb3SBarry SmithTaoMonitorSet(Tao, PetscErrorCode (*mon)(Tao,void*), void*); 29257f296bb3SBarry Smith``` 29267f296bb3SBarry Smith 29277f296bb3SBarry SmithThe routine `mon` indicates a user-defined monitoring routine, and 29287f296bb3SBarry Smith`void*` denotes an optional user-defined context for private data for 29297f296bb3SBarry Smiththe monitor routine. 29307f296bb3SBarry Smith 29317f296bb3SBarry SmithThe routine set by `TaoMonitorSet()` is called once during each 29327f296bb3SBarry Smithiteration of the optimization solver. Hence, the user can employ this 29337f296bb3SBarry Smithroutine for any application-specific computations that should be done 29347f296bb3SBarry Smithafter the solution update. 29357f296bb3SBarry Smith 29367f296bb3SBarry Smith(sec_tao_convergence)= 29377f296bb3SBarry Smith 29387f296bb3SBarry Smith### Convergence Tests 29397f296bb3SBarry Smith 29407f296bb3SBarry SmithConvergence of a solver can be defined in many ways. The methods TAO 29417f296bb3SBarry Smithuses by default are mentioned in {any}`sec_tao_customize`. 29427f296bb3SBarry SmithThese methods include absolute and relative convergence tolerances as 29437f296bb3SBarry Smithwell as a maximum number of iterations of function evaluations. If these 29447f296bb3SBarry Smithchoices are not sufficient, the user can specify a customized test 29457f296bb3SBarry Smith 29467f296bb3SBarry SmithUsers can set their own customized convergence tests of the form 29477f296bb3SBarry Smith 29487f296bb3SBarry Smith``` 29497f296bb3SBarry SmithPetscErrorCode conv(Tao, void*); 29507f296bb3SBarry Smith``` 29517f296bb3SBarry Smith 29527f296bb3SBarry SmithThe second argument is a pointer to a structure defined by the user. 29537f296bb3SBarry SmithWithin this routine, the solver can be queried for the solution vector, 29547f296bb3SBarry Smithgradient vector, or other statistic at the current iteration through 29557f296bb3SBarry Smithroutines such as `TaoGetSolutionStatus()` and `TaoGetTolerances()`. 29567f296bb3SBarry Smith 29577f296bb3SBarry SmithTo use this convergence test within a TAO solver, one uses the command 29587f296bb3SBarry Smith 29597f296bb3SBarry Smith``` 29607f296bb3SBarry SmithTaoSetConvergenceTest(Tao, PetscErrorCode (*conv)(Tao,void*), void*); 29617f296bb3SBarry Smith``` 29627f296bb3SBarry Smith 29637f296bb3SBarry SmithThe second argument of this command is the convergence routine, and the 29647f296bb3SBarry Smithfinal argument of the convergence test routine denotes an optional 29657f296bb3SBarry Smithuser-defined context for private data. The convergence routine receives 29667f296bb3SBarry Smiththe TAO solver and this private data structure. The termination flag can 29677f296bb3SBarry Smithbe set by using the routine 29687f296bb3SBarry Smith 29697f296bb3SBarry Smith``` 29707f296bb3SBarry SmithTaoSetConvergedReason(Tao, TaoConvergedReason); 29717f296bb3SBarry Smith``` 29727f296bb3SBarry Smith 29737f296bb3SBarry Smith(sec_tao_linesearch)= 29747f296bb3SBarry Smith 29757f296bb3SBarry Smith### Line Searches 29767f296bb3SBarry Smith 29777f296bb3SBarry SmithBy using the command line option `-tao_ls_type`. Available line 29787f296bb3SBarry Smithsearches include Moré-Thuente {cite}`more:92`, Armijo, gpcg, 29797f296bb3SBarry Smithand unit. 29807f296bb3SBarry Smith 29817f296bb3SBarry SmithThe line search routines involve several parameters, which are set to 29827f296bb3SBarry Smithdefaults that are reasonable for many applications. The user can 29837f296bb3SBarry Smithoverride the defaults by using the following options 29847f296bb3SBarry Smith 29857f296bb3SBarry Smith- `-tao_ls_max_funcs <max>` 29867f296bb3SBarry Smith- `-tao_ls_stepmin <min>` 29877f296bb3SBarry Smith- `-tao_ls_stepmax <max>` 29887f296bb3SBarry Smith- `-tao_ls_ftol <ftol>` 29897f296bb3SBarry Smith- `-tao_ls_gtol <gtol>` 29907f296bb3SBarry Smith- `-tao_ls_rtol <rtol>` 29917f296bb3SBarry Smith 29927f296bb3SBarry SmithOne should run a TAO program with the option `-help` for details. 29937f296bb3SBarry SmithUsers may write their own customized line search codes by modeling them 29947f296bb3SBarry Smithafter one of the defaults provided. 29957f296bb3SBarry Smith 29967f296bb3SBarry Smith(sec_tao_recyclehistory)= 29977f296bb3SBarry Smith 29987f296bb3SBarry Smith### Recycling History 29997f296bb3SBarry Smith 30007f296bb3SBarry SmithSome TAO algorithms can re-use information accumulated in the previous 30017f296bb3SBarry Smith`TaoSolve()` call to hot-start the new solution. This can be enabled 30027f296bb3SBarry Smithusing the `-tao_recycle_history` flag, or in code via the 30037f296bb3SBarry Smith`TaoSetRecycleHistory()` interface. 30047f296bb3SBarry Smith 30057f296bb3SBarry SmithFor the nonlinear conjugate gradient solver (`TAOBNCG`), this option 30067f296bb3SBarry Smithre-uses the latest search direction from the previous `TaoSolve()` 30077f296bb3SBarry Smithcall to compute the initial search direction of a new `TaoSolve()`. By 30087f296bb3SBarry Smithdefault, the feature is disabled and the algorithm sets the initial 30097f296bb3SBarry Smithdirection as the negative gradient. 30107f296bb3SBarry Smith 30117f296bb3SBarry SmithFor the quasi-Newton family of methods (`TAOBQNLS`, `TAOBQNKLS`, 30127f296bb3SBarry Smith`TAOBQNKTR`, `TAOBQNKTL`), this option re-uses the accumulated 30137f296bb3SBarry Smithquasi-Newton Hessian approximation from the previous `TaoSolve()` 30147f296bb3SBarry Smithcall. By default, the feature is disabled and the algorithm will reset 30157f296bb3SBarry Smiththe quasi-Newton approximation to the identity matrix at the beginning 30167f296bb3SBarry Smithof every new `TaoSolve()`. 30177f296bb3SBarry Smith 30187f296bb3SBarry SmithThe option flag has no effect on other TAO solvers. 30197f296bb3SBarry Smith 30207f296bb3SBarry Smith(sec_tao_addsolver)= 30217f296bb3SBarry Smith 30227f296bb3SBarry Smith## Adding a Solver 30237f296bb3SBarry Smith 30247f296bb3SBarry SmithOne of the strengths of both TAO and PETSc is the ability to allow users 30257f296bb3SBarry Smithto extend the built-in solvers with new user-defined algorithms. It is 30267f296bb3SBarry Smithcertainly possible to develop new optimization algorithms outside of TAO 30277f296bb3SBarry Smithframework, but Using TAO to implement a solver has many advantages, 30287f296bb3SBarry Smith 30297f296bb3SBarry Smith1. TAO includes other optimization solvers with an identical interface, 30307f296bb3SBarry Smith so application problems may conveniently switch solvers to compare 30317f296bb3SBarry Smith their effectiveness. 30327f296bb3SBarry Smith2. TAO provides support for function evaluations and derivative 30337f296bb3SBarry Smith information. It allows for the direct evaluation of this information 30347f296bb3SBarry Smith by the application developer, contains limited support for finite 30357f296bb3SBarry Smith difference approximations, and allows the uses of matrix-free 30367f296bb3SBarry Smith methods. The solvers can obtain this function and derivative 30377f296bb3SBarry Smith information through a simple interface while the details of its 30387f296bb3SBarry Smith computation are handled within the toolkit. 30397f296bb3SBarry Smith3. TAO provides line searches, convergence tests, monitoring routines, 30407f296bb3SBarry Smith and other tools that are helpful in an optimization algorithm. The 30417f296bb3SBarry Smith availability of these tools means that the developers of the 30427f296bb3SBarry Smith optimization solver do not have to write these utilities. 30437f296bb3SBarry Smith4. PETSc offers vectors, matrices, index sets, and linear solvers that 30447f296bb3SBarry Smith can be used by the solver. These objects are standard mathematical 30457f296bb3SBarry Smith constructions that have many different implementations. The objects 30467f296bb3SBarry Smith may be distributed over multiple processors, restricted to a single 30477f296bb3SBarry Smith processor, have a dense representation, use a sparse data structure, 30487f296bb3SBarry Smith or vary in many other ways. TAO solvers do not need to know how these 30497f296bb3SBarry Smith objects are represented or how the operations defined on them have 30507f296bb3SBarry Smith been implemented. Instead, the solvers apply these operations through 30517f296bb3SBarry Smith an abstract interface that leaves the details to PETSc and external 30527f296bb3SBarry Smith libraries. This abstraction allows solvers to work seamlessly with a 30537f296bb3SBarry Smith variety of data structures while allowing application developers to 30547f296bb3SBarry Smith select data structures tailored for their purposes. 30557f296bb3SBarry Smith5. PETSc provides the user a convenient method for setting options at 30567f296bb3SBarry Smith runtime, performance profiling, and debugging. 30577f296bb3SBarry Smith 30587f296bb3SBarry Smith(header_file_1)= 30597f296bb3SBarry Smith 30607f296bb3SBarry Smith### Header File 30617f296bb3SBarry Smith 30627f296bb3SBarry SmithTAO solver implementation files must include the TAO implementation file 30637f296bb3SBarry Smith`taoimpl.h`: 30647f296bb3SBarry Smith 30657f296bb3SBarry Smith``` 30667f296bb3SBarry Smith#include "petsc/private/taoimpl.h" 30677f296bb3SBarry Smith``` 30687f296bb3SBarry Smith 30697f296bb3SBarry SmithThis file contains data elements that are generally kept hidden from 30707f296bb3SBarry Smithapplication programmers, but may be necessary for solver implementations 30717f296bb3SBarry Smithto access. 30727f296bb3SBarry Smith 30737f296bb3SBarry Smith### TAO Interface with Solvers 30747f296bb3SBarry Smith 30757f296bb3SBarry SmithTAO solvers must be written in C or C++ and include several routines 30767f296bb3SBarry Smithwith a particular calling sequence. Two of these routines are mandatory: 30777f296bb3SBarry Smithone that initializes the TAO structure with the appropriate information 30787f296bb3SBarry Smithand one that applies the algorithm to a problem instance. Additional 30797f296bb3SBarry Smithroutines may be written to set options within the solver, view the 30807f296bb3SBarry Smithsolver, setup appropriate data structures, and destroy these data 30817f296bb3SBarry Smithstructures. In order to implement the conjugate gradient algorithm, for 30827f296bb3SBarry Smithexample, the following structure is useful. 30837f296bb3SBarry Smith 30847f296bb3SBarry Smith``` 30857f296bb3SBarry Smithtypedef struct{ 30867f296bb3SBarry Smith 30877f296bb3SBarry Smith PetscReal beta; 30887f296bb3SBarry Smith PetscReal eta; 30897f296bb3SBarry Smith PetscInt ngradtseps; 30907f296bb3SBarry Smith PetscInt nresetsteps; 30917f296bb3SBarry Smith Vec X_old; 30927f296bb3SBarry Smith Vec G_old; 30937f296bb3SBarry Smith 30947f296bb3SBarry Smith} TAO_CG; 30957f296bb3SBarry Smith``` 30967f296bb3SBarry Smith 30977f296bb3SBarry SmithThis structure contains two parameters, two counters, and two work 30987f296bb3SBarry Smithvectors. Vectors for the solution and gradient are not needed here 30997f296bb3SBarry Smithbecause the TAO structure has pointers to them. 31007f296bb3SBarry Smith 31017f296bb3SBarry Smith#### Solver Routine 31027f296bb3SBarry Smith 31037f296bb3SBarry SmithAll TAO solvers have a routine that accepts a TAO structure and computes 31047f296bb3SBarry Smitha solution. TAO will call this routine when the application program uses 31057f296bb3SBarry Smiththe routine `TaoSolve()` and will pass to the solver information about 31067f296bb3SBarry Smiththe objective function and constraints, pointers to the variable vector 31077f296bb3SBarry Smithand gradient vector, and support for line searches, linear solvers, and 31087f296bb3SBarry Smithconvergence monitoring. As an example, consider the following code that 31097f296bb3SBarry Smithsolves an unconstrained minimization problem using the conjugate 31107f296bb3SBarry Smithgradient method. 31117f296bb3SBarry Smith 31127f296bb3SBarry Smith``` 31137f296bb3SBarry SmithPetscErrorCode TaoSolve_CG(Tao tao) 31147f296bb3SBarry Smith{ 31157f296bb3SBarry Smith TAO_CG *cg = (TAO_CG *) tao->data; 31167f296bb3SBarry Smith Vec x = tao->solution; 31177f296bb3SBarry Smith Vec g = tao->gradient; 31187f296bb3SBarry Smith Vec s = tao->stepdirection; 31197f296bb3SBarry Smith PetscInt iter=0; 31207f296bb3SBarry Smith PetscReal gnormPrev,gdx,f,gnorm,steplength=0; 31217f296bb3SBarry Smith TaoLineSearchConvergedReason lsflag=TAO_LINESEARCH_CONTINUE_ITERATING; 31227f296bb3SBarry Smith TaoConvergedReason reason=TAO_CONTINUE_ITERATING; 31237f296bb3SBarry Smith 31247f296bb3SBarry Smith PetscFunctionBegin; 31257f296bb3SBarry Smith 31267f296bb3SBarry Smith PetscCall(TaoComputeObjectiveAndGradient(tao,x,&f,g)); 31277f296bb3SBarry Smith PetscCall(VecNorm(g,NORM_2,&gnorm)); 31287f296bb3SBarry Smith 31297f296bb3SBarry Smith PetscCall(VecSet(s,0)); 31307f296bb3SBarry Smith 31317f296bb3SBarry Smith cg->beta=0; 31327f296bb3SBarry Smith gnormPrev = gnorm; 31337f296bb3SBarry Smith 31347f296bb3SBarry Smith /* Enter loop */ 31357f296bb3SBarry Smith while (1){ 31367f296bb3SBarry Smith 31377f296bb3SBarry Smith /* Test for convergence */ 31387f296bb3SBarry Smith PetscCall(TaoMonitor(tao,iter,f,gnorm,0.0,step,&reason)); 31397f296bb3SBarry Smith if (reason!=TAO_CONTINUE_ITERATING) break; 31407f296bb3SBarry Smith 31417f296bb3SBarry Smith cg->beta=(gnorm*gnorm)/(gnormPrev*gnormPrev); 31427f296bb3SBarry Smith PetscCall(VecScale(s,cg->beta)); 31437f296bb3SBarry Smith PetscCall(VecAXPY(s,-1.0,g)); 31447f296bb3SBarry Smith 31457f296bb3SBarry Smith PetscCall(VecDot(s,g,&gdx)); 31467f296bb3SBarry Smith if (gdx>=0){ /* If not a descent direction, use gradient */ 31477f296bb3SBarry Smith PetscCall(VecCopy(g,s)); 31487f296bb3SBarry Smith PetscCall(VecScale(s,-1.0)); 31497f296bb3SBarry Smith gdx=-gnorm*gnorm; 31507f296bb3SBarry Smith } 31517f296bb3SBarry Smith 31527f296bb3SBarry Smith /* Line Search */ 31537f296bb3SBarry Smith gnormPrev = gnorm; step=1.0; 31547f296bb3SBarry Smith PetscCall(TaoLineSearchSetInitialStepLength(tao->linesearch,1.0)); 31557f296bb3SBarry Smith PetscCall(TaoLineSearchApply(tao->linesearch,x,&f,g,s,&steplength,&lsflag)); 31567f296bb3SBarry Smith PetscCall(TaoAddLineSearchCounts(tao)); 31577f296bb3SBarry Smith PetscCall(VecNorm(g,NORM_2,&gnorm)); 31587f296bb3SBarry Smith iter++; 31597f296bb3SBarry Smith } 31607f296bb3SBarry Smith 31617f296bb3SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 31627f296bb3SBarry Smith} 31637f296bb3SBarry Smith``` 31647f296bb3SBarry Smith 31657f296bb3SBarry SmithThe first line of this routine casts the second argument to a pointer to 31667f296bb3SBarry Smitha `TAO_CG` data structure. This structure contains pointers to three 31677f296bb3SBarry Smithvectors and a scalar that will be needed in the algorithm. 31687f296bb3SBarry Smith 31697f296bb3SBarry SmithAfter declaring an initializing several variables, the solver lets TAO 31707f296bb3SBarry Smithevaluate the function and gradient at the current point in the using the 31717f296bb3SBarry Smithroutine `TaoComputeObjectiveAndGradient()`. Other routines may be used 31727f296bb3SBarry Smithto evaluate the Hessian matrix or evaluate constraints. TAO may obtain 31737f296bb3SBarry Smiththis information using direct evaluation or other means, but these 31747f296bb3SBarry Smithdetails do not affect our implementation of the algorithm. 31757f296bb3SBarry Smith 31767f296bb3SBarry SmithThe norm of the gradient is a standard measure used by unconstrained 31777f296bb3SBarry Smithminimization solvers to define convergence. This quantity is always 31787f296bb3SBarry Smithnonnegative and equals zero at the solution. The solver will pass this 31797f296bb3SBarry Smithquantity, the current function value, the current iteration number, and 31807f296bb3SBarry Smitha measure of infeasibility to TAO with the routine 31817f296bb3SBarry Smith 31827f296bb3SBarry Smith``` 31837f296bb3SBarry SmithPetscErrorCode TaoMonitor(Tao tao, PetscInt iter, PetscReal f, 31847f296bb3SBarry Smith PetscReal res, PetscReal cnorm, PetscReal steplength, 31857f296bb3SBarry Smith TaoConvergedReason *reason); 31867f296bb3SBarry Smith``` 31877f296bb3SBarry Smith 31887f296bb3SBarry SmithMost optimization algorithms are iterative, and solvers should include 31897f296bb3SBarry Smiththis command somewhere in each iteration. This routine records this 31907f296bb3SBarry Smithinformation, and applies any monitoring routines and convergence tests 31917f296bb3SBarry Smithset by default or the user. In this routine, the second argument is the 31927f296bb3SBarry Smithcurrent iteration number, and the third argument is the current function 31937f296bb3SBarry Smithvalue. The fourth argument is a nonnegative error measure associated 31947f296bb3SBarry Smithwith the distance between the current solution and the optimal solution. 31957f296bb3SBarry SmithExamples of this measure are the norm of the gradient or the square root 31967f296bb3SBarry Smithof a duality gap. The fifth argument is a nonnegative error that usually 31977f296bb3SBarry Smithrepresents a measure of the infeasibility such as the norm of the 31987f296bb3SBarry Smithconstraints or violation of bounds. This number should be zero for 31997f296bb3SBarry Smithunconstrained solvers. The sixth argument is a nonnegative steplength, 32007f296bb3SBarry Smithor the multiple of the step direction added to the previous iterate. The 32017f296bb3SBarry Smithresults of the convergence test are returned in the last argument. If 32027f296bb3SBarry Smiththe termination reason is `TAO_CONTINUE_ITERATING`, the algorithm 32037f296bb3SBarry Smithshould continue. 32047f296bb3SBarry Smith 32057f296bb3SBarry SmithAfter this monitoring routine, the solver computes a step direction 32067f296bb3SBarry Smithusing the conjugate gradient algorithm and computations using Vec 32077f296bb3SBarry Smithobjects. These methods include adding vectors together and computing an 32087f296bb3SBarry Smithinner product. A full list of these methods can be found in the manual 32097f296bb3SBarry Smithpages. 32107f296bb3SBarry Smith 32117f296bb3SBarry SmithNonlinear conjugate gradient algorithms also require a line search. TAO 32127f296bb3SBarry Smithprovides several line searches and support for using them. The routine 32137f296bb3SBarry Smith 32147f296bb3SBarry Smith``` 32157f296bb3SBarry SmithTaoLineSearchApply(TaoLineSearch ls, Vec x, PetscReal *f, Vec g, 32167f296bb3SBarry Smith TaoVec *s, PetscReal *steplength, 32177f296bb3SBarry Smith TaoLineSearchConvergedReason *lsflag) 32187f296bb3SBarry Smith``` 32197f296bb3SBarry Smith 32207f296bb3SBarry Smithpasses the current solution, gradient, and objective value to the line 32217f296bb3SBarry Smithsearch and returns a new solution, gradient, and objective value. More 32227f296bb3SBarry Smithdetails on line searches can be found in 32237f296bb3SBarry Smith{any}`sec_tao_linesearch`. The details of the 32247f296bb3SBarry Smithline search applied are specified elsewhere, when the line search is 32257f296bb3SBarry Smithcreated. 32267f296bb3SBarry Smith 32277f296bb3SBarry SmithTAO also includes support for linear solvers using PETSc KSP objects. 32287f296bb3SBarry SmithAlthough this algorithm does not require one, linear solvers are an 32297f296bb3SBarry Smithimportant part of many algorithms. Details on the use of these solvers 32307f296bb3SBarry Smithcan be found in the PETSc users manual. 32317f296bb3SBarry Smith 32327f296bb3SBarry Smith#### Creation Routine 32337f296bb3SBarry Smith 32347f296bb3SBarry SmithThe TAO solver is initialized for a particular algorithm in a separate 32357f296bb3SBarry Smithroutine. This routine sets default convergence tolerances, creates a 32367f296bb3SBarry Smithline search or linear solver if needed, and creates structures needed by 32377f296bb3SBarry Smiththis solver. For example, the routine that creates the nonlinear 32387f296bb3SBarry Smithconjugate gradient algorithm shown above can be implemented as follows. 32397f296bb3SBarry Smith 32407f296bb3SBarry Smith``` 32417f296bb3SBarry SmithPETSC_EXTERN PetscErrorCode TaoCreate_CG(Tao tao) 32427f296bb3SBarry Smith{ 32437f296bb3SBarry Smith TAO_CG *cg = (TAO_CG*)tao->data; 32447f296bb3SBarry Smith const char *morethuente_type = TAOLINESEARCH_MT; 32457f296bb3SBarry Smith 32467f296bb3SBarry Smith PetscFunctionBegin; 32477f296bb3SBarry Smith 32487f296bb3SBarry Smith PetscCall(PetscNew(&cg)); 32497f296bb3SBarry Smith tao->data = (void*)cg; 32507f296bb3SBarry Smith cg->eta = 0.1; 32517f296bb3SBarry Smith cg->delta_min = 1e-7; 32527f296bb3SBarry Smith cg->delta_max = 100; 32537f296bb3SBarry Smith cg->cg_type = CG_PolakRibierePlus; 32547f296bb3SBarry Smith 32557f296bb3SBarry Smith tao->max_it = 2000; 32567f296bb3SBarry Smith tao->max_funcs = 4000; 32577f296bb3SBarry Smith 32587f296bb3SBarry Smith tao->ops->setup = TaoSetUp_CG; 32597f296bb3SBarry Smith tao->ops->solve = TaoSolve_CG; 32607f296bb3SBarry Smith tao->ops->view = TaoView_CG; 32617f296bb3SBarry Smith tao->ops->setfromoptions = TaoSetFromOptions_CG; 32627f296bb3SBarry Smith tao->ops->destroy = TaoDestroy_CG; 32637f296bb3SBarry Smith 32647f296bb3SBarry Smith PetscCall(TaoLineSearchCreate(((PetscObject)tao)->comm, &tao->linesearch)); 32657f296bb3SBarry Smith PetscCall(TaoLineSearchSetType(tao->linesearch, morethuente_type)); 32667f296bb3SBarry Smith PetscCall(TaoLineSearchUseTaoRoutines(tao->linesearch, tao)); 32677f296bb3SBarry Smith 32687f296bb3SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 32697f296bb3SBarry Smith} 32707f296bb3SBarry SmithEXTERN_C_END 32717f296bb3SBarry Smith``` 32727f296bb3SBarry Smith 32737f296bb3SBarry SmithThis routine declares some variables and then allocates memory for the 32747f296bb3SBarry Smith`TAO_CG` data structure. Notice that the `Tao` object now has a 32757f296bb3SBarry Smithpointer to this data structure (`tao->data`) so it can be accessed by 32767f296bb3SBarry Smiththe other functions written for this solver implementation. 32777f296bb3SBarry Smith 32787f296bb3SBarry SmithThis routine also sets some default parameters particular to the 32797f296bb3SBarry Smithconjugate gradient algorithm, sets default convergence tolerances, and 32807f296bb3SBarry Smithcreates a particular line search. These defaults could be specified in 32817f296bb3SBarry Smiththe routine that solves the problem, but specifying them here gives the 32827f296bb3SBarry Smithuser the opportunity to modify these parameters either by using direct 32837f296bb3SBarry Smithcalls setting parameters or by using options. 32847f296bb3SBarry Smith 32857f296bb3SBarry SmithFinally, this solver passes to TAO the names of all the other routines 32867f296bb3SBarry Smithused by the solver. 32877f296bb3SBarry Smith 32887f296bb3SBarry SmithNote that the lines `EXTERN_C_BEGIN` and `EXTERN_C_END` surround 32897f296bb3SBarry Smiththis routine. These macros are required to preserve the name of this 32907f296bb3SBarry Smithfunction without any name-mangling from the C++ compiler (if used). 32917f296bb3SBarry Smith 32927f296bb3SBarry Smith#### Destroy Routine 32937f296bb3SBarry Smith 32947f296bb3SBarry SmithAnother routine needed by most solvers destroys the data structures 32957f296bb3SBarry Smithcreated by earlier routines. For the nonlinear conjugate gradient method 32967f296bb3SBarry Smithdiscussed earlier, the following routine destroys the two work vectors 32977f296bb3SBarry Smithand the `TAO_CG` structure. 32987f296bb3SBarry Smith 32997f296bb3SBarry Smith``` 33007f296bb3SBarry SmithPetscErrorCode TaoDestroy_CG(TAO_SOLVER tao) 33017f296bb3SBarry Smith{ 33027f296bb3SBarry Smith TAO_CG *cg = (TAO_CG *) tao->data; 33037f296bb3SBarry Smith 33047f296bb3SBarry Smith PetscFunctionBegin; 33057f296bb3SBarry Smith 33067f296bb3SBarry Smith PetscCall(VecDestroy(&cg->X_old)); 33077f296bb3SBarry Smith PetscCall(VecDestroy(&cg->G_old)); 33087f296bb3SBarry Smith 33097f296bb3SBarry Smith PetscFree(tao->data); 33107f296bb3SBarry Smith tao->data = NULL; 33117f296bb3SBarry Smith 33127f296bb3SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 33137f296bb3SBarry Smith} 33147f296bb3SBarry Smith``` 33157f296bb3SBarry Smith 33167f296bb3SBarry SmithThis routine is called from within the `TaoDestroy()` routine. Only 33177f296bb3SBarry Smithalgorithm-specific data objects are destroyed in this routine; any 33187f296bb3SBarry Smithobjects indexed by TAO (`tao->linesearch`, `tao->ksp`, 33197f296bb3SBarry Smith`tao->gradient`, etc.) will be destroyed by TAO immediately after the 33207f296bb3SBarry Smithalgorithm-specific destroy routine completes. 33217f296bb3SBarry Smith 33227f296bb3SBarry Smith#### SetUp Routine 33237f296bb3SBarry Smith 33247f296bb3SBarry SmithIf the SetUp routine has been set by the initialization routine, TAO 33257f296bb3SBarry Smithwill call it during the execution of `TaoSolve()`. While this routine 33267f296bb3SBarry Smithis optional, it is often provided to allocate the gradient vector, work 33277f296bb3SBarry Smithvectors, and other data structures required by the solver. It should 33287f296bb3SBarry Smithhave the following form. 33297f296bb3SBarry Smith 33307f296bb3SBarry Smith``` 33317f296bb3SBarry SmithPetscErrorCode TaoSetUp_CG(Tao tao) 33327f296bb3SBarry Smith{ 33337f296bb3SBarry Smith TAO_CG *cg = (TAO_CG*)tao->data; 33347f296bb3SBarry Smith PetscFunctionBegin; 33357f296bb3SBarry Smith 33367f296bb3SBarry Smith PetscCall(VecDuplicate(tao->solution,&tao->gradient)); 33377f296bb3SBarry Smith PetscCall(VecDuplicate(tao->solution,&tao->stepdirection)); 33387f296bb3SBarry Smith PetscCall(VecDuplicate(tao->solution,&cg->X_old)); 33397f296bb3SBarry Smith PetscCall(VecDuplicate(tao->solution,&cg->G_old)); 33407f296bb3SBarry Smith 33417f296bb3SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 33427f296bb3SBarry Smith} 33437f296bb3SBarry Smith``` 33447f296bb3SBarry Smith 33457f296bb3SBarry Smith#### SetFromOptions Routine 33467f296bb3SBarry Smith 33477f296bb3SBarry SmithThe SetFromOptions routine should be used to check for any 33487f296bb3SBarry Smithalgorithm-specific options set by the user and will be called when the 33497f296bb3SBarry Smithapplication makes a call to `TaoSetFromOptions()`. It should have the 33507f296bb3SBarry Smithfollowing form. 33517f296bb3SBarry Smith 33527f296bb3SBarry Smith``` 33537f296bb3SBarry SmithPetscErrorCode TaoSetFromOptions_CG(Tao tao, void *solver); 33547f296bb3SBarry Smith{ 33557f296bb3SBarry Smith TAO_CG *cg = (TAO_CG*)solver; 33567f296bb3SBarry Smith PetscFunctionBegin; 33577f296bb3SBarry Smith PetscCall(PetscOptionsReal("-tao_cg_eta","restart tolerance","",cg->eta,&cg->eta,0)); 33587f296bb3SBarry Smith PetscCall(PetscOptionsReal("-tao_cg_delta_min","minimum delta value","",cg->delta_min,&cg->delta_min,0)); 33597f296bb3SBarry Smith PetscCall(PetscOptionsReal("-tao_cg_delta_max","maximum delta value","",cg->delta_max,&cg->delta_max,0)); 33607f296bb3SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 33617f296bb3SBarry Smith} 33627f296bb3SBarry Smith``` 33637f296bb3SBarry Smith 33647f296bb3SBarry Smith#### View Routine 33657f296bb3SBarry Smith 33667f296bb3SBarry SmithThe View routine should be used to output any algorithm-specific 33677f296bb3SBarry Smithinformation or statistics at the end of a solve. This routine will be 33687f296bb3SBarry Smithcalled when the application makes a call to `TaoView()` or when the 33697f296bb3SBarry Smithcommand line option `-tao_view` is used. It should have the following 33707f296bb3SBarry Smithform. 33717f296bb3SBarry Smith 33727f296bb3SBarry Smith``` 33737f296bb3SBarry SmithPetscErrorCode TaoView_CG(Tao tao, PetscViewer viewer) 33747f296bb3SBarry Smith{ 33757f296bb3SBarry Smith TAO_CG *cg = (TAO_CG*)tao->data; 33767f296bb3SBarry Smith 33777f296bb3SBarry Smith PetscFunctionBegin; 33787f296bb3SBarry Smith PetscCall(PetscViewerASCIIPushTab(viewer)); 33797f296bb3SBarry Smith PetscCall(PetscViewerASCIIPrintf(viewer,"Grad. steps: %d\n",cg->ngradsteps)); 33807f296bb3SBarry Smith PetscCall(PetscViewerASCIIPrintf(viewer,"Reset steps: %d\n",cg->nresetsteps)); 33817f296bb3SBarry Smith PetscCall(PetscViewerASCIIPopTab(viewer)); 33827f296bb3SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 33837f296bb3SBarry Smith} 33847f296bb3SBarry Smith``` 33857f296bb3SBarry Smith 33867f296bb3SBarry Smith#### Registering the Solver 33877f296bb3SBarry Smith 33887f296bb3SBarry SmithOnce a new solver is implemented, TAO needs to know the name of the 33897f296bb3SBarry Smithsolver and what function to use to create the solver. To this end, one 33907f296bb3SBarry Smithcan use the routine 33917f296bb3SBarry Smith 33927f296bb3SBarry Smith``` 33937f296bb3SBarry SmithTaoRegister(const char *name, 33947f296bb3SBarry Smith const char *path, 33957f296bb3SBarry Smith const char *cname, 33967f296bb3SBarry Smith PetscErrorCode (*create) (Tao)); 33977f296bb3SBarry Smith``` 33987f296bb3SBarry Smith 33997f296bb3SBarry Smithwhere `name` is the name of the solver (i.e., `tao_blmvm`), `path` 34007f296bb3SBarry Smithis the path to the library containing the solver, `cname` is the name 34017f296bb3SBarry Smithof the routine that creates the solver (in our case, `TaoCreate_CG`), 34027f296bb3SBarry Smithand `create` is a pointer to that creation routine. If one is using 34037f296bb3SBarry Smithdynamic loading, then the fourth argument will be ignored. 34047f296bb3SBarry Smith 34057f296bb3SBarry SmithOnce the solver has been registered, the new solver can be selected 34067f296bb3SBarry Smitheither by using the `TaoSetType()` function or by using the 34077f296bb3SBarry Smith`-tao_type` command line option. 34087f296bb3SBarry Smith 34097f296bb3SBarry Smith```{rubric} Footnotes 34107f296bb3SBarry Smith``` 34117f296bb3SBarry Smith 34127f296bb3SBarry Smith[^mpi]: For more on MPI and PETSc, see {any}`sec_running`. 34137f296bb3SBarry Smith 34147f296bb3SBarry Smith```{eval-rst} 34157f296bb3SBarry Smith.. bibliography:: /petsc.bib 34167f296bb3SBarry Smith :filter: docname in docnames 34177f296bb3SBarry Smith``` 3418