PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
Public Member Functions | Protected Attributes | List of all members
pism::taoutil::TaoBasicSolver< Problem > Class Template Reference

An interface for solving an optimization problem with TAO where the problem itself is defined by a separate Problem class. More...

#include <TaoUtil.hh>

Public Member Functions

 TaoBasicSolver (MPI_Comm comm, const std::string &tao_type, Problem &prob)
 Construct a solver to solve prob using TAO algorithm tao_type. More...
 
virtual ~TaoBasicSolver ()
 
virtual std::shared_ptr< TerminationReasonsolve ()
 Solve the minimization problem. More...
 
virtual void setMaximumIterations (int max_it)
 
virtual Problem & problem ()
 

Protected Attributes

MPI_Comm m_comm
 
petsc::Tao m_tao
 
Problem & m_problem
 

Detailed Description

template<class Problem>
class pism::taoutil::TaoBasicSolver< Problem >

An interface for solving an optimization problem with TAO where the problem itself is defined by a separate Problem class.

The primary interface to a TAO optimization problem is mediated by a PETSc-style TaoSolver object. The PISM TaoBasicSolver C++ class wraps a TaoSolver and some of its initialization boilierplate, and allows a separate class to define the function to be minimized.

To use a TaoBasicSolver you create a Problem class that defines the objective function and initial guess, as well any auxilliary callbacks desired. The Problem class must define a

void Problem::connect(TaoSolver solver);

method which gives the Problem an opportunity to register its methods as callbacks to the solver, perhaps taking advantage of the various TaoFooCallback classes provided in TaoUtil.hh to facilitate this. For example, a problem class MyProblem that did nothing more than register a combined objective/gradient callback could define

void MyProblem::connect(TaoSolver tao) {
typedef TaoObjGradCallback<Problem,&MyProblem::evaluateObjectiveAndGradient> ObjGradCallback;
ObjGradCallback::connect(tao,*this);
}

In addition to the connect method, a Problem must define

TerminationReason::Ptr MyProblem::formInitialGuess(Vec *v)

which allows the problem to set the initial guess for optimization. If the minimization is successful, the solution will be found in the same vector that was returned by this method.

Assuming a MyProblem called problem has been constructed, solution of the minimization is done using, for example, the TAO algorithm tao_cg:

TaoBasicSolver<MyProblem> solver(com,"tao_cg",problem);
TerminationReason::Ptr reason = solver.solve();
if (reason->succeeded()) {
printf("Success: %s\n",reason->description().c_str());
} else {
printf("Failure: %s\n",reason->description().c_str());
}
virtual Problem & problem()
Definition: TaoUtil.hh:152
std::string printf(const char *format,...)

Definition at line 92 of file TaoUtil.hh.


The documentation for this class was generated from the following file: