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