petsc4py.PETSc.TAO¶
- class petsc4py.PETSc.TAO¶
Bases:
Object
Optimization solver.
TAO is described in the
PETSc manual
.See also
petsc.Tao
Enumerations
TAO Bound Constrained Conjugate Gradient (BNCG) Update Type.
TAO solver termination reason.
TAO solver type.
Methods Summary
appendOptionsPrefix
(prefix)Append to the prefix used for searching for options in the database.
Cancel all the monitors of the solver.
computeConstraints
(x, c)Compute the vector corresponding to the constraints.
computeDualVariables
(xl, xu)Compute the dual vectors corresponding to variables' bounds.
computeGradient
(x, g)Compute the gradient of the objective function.
computeHessian
(x, H[, P])Compute the Hessian of the objective function.
computeJacobian
(x, J[, P])Compute the Jacobian.
Compute the value of the objective function.
computeObjectiveGradient
(x, g)Compute the gradient of the objective function and its value.
computeResidual
(x, f)Compute the residual.
computeVariableBounds
(xl, xu)Compute the vectors corresponding to variables' bounds.
create
([comm])Create a TAO solver.
createPython
([context, comm])Create an optimization solver of Python type.
destroy
()Destroy the solver.
Return the application context.
Return the type of the BNCG solver.
Return the damping vector.
Return the subsolver inside the BRGN solver.
Return the constraints tolerance parameters used in the convergence tests.
Return the termination flag.
Return the callback used to test for solver convergence.
Return the vector used to store the gradient and the evaluation callback.
Return the matrix used to compute inner products.
Return the matrices used to store the Hessian and the evaluation callback.
Return the current iteration number.
getKSP
()Return the linear solver used by the nonlinear solver.
Return the initial Hessian for the quasi-Newton approximation.
Return the
KSP
for the inverse of the initial Hessian approximation.Return the TAO Line Search object.
Return the maximum number of objective evaluations within the solver.
Return the maximum number of solver iterations.
Return the callback used to monitor solver convergence.
Return the vector used to store the gradient and the evaluation callback.
Return the current value of the objective function.
Return the prefix used for searching for options in the database.
Return the instance of the class implementing the required Python methods.
Return the fully qualified Python name of the class used by the solver.
Return the vector holding the solution.
Return the objective function value and the norms of gradient and constraints.
Return the solution status.
Return the tolerance parameters used in the solver convergence tests.
getType
()Return the type of the solver.
Return the callback to compute the update.
Return the upper and lower bounds vectors.
monitor
([its, f, res, cnorm, step])Monitor the solver.
setAppCtx
(appctx)Set the application context.
setBNCGType
(cg_type)Set the type of the BNCG solver.
Set the dictionary matrix.
setBRGNRegularizerHessian
(hessian[, H, ...])Set the callback to compute the regularizer Hessian.
setBRGNRegularizerObjectiveGradient
(objgrad)Set the callback to compute the regularizer objective and gradient.
setBRGNRegularizerWeight
(weight)Set the regularizer weight.
setBRGNSmoothL1Epsilon
(epsilon)Set the smooth L1 epsilon.
setConstraintTolerances
([catol, crtol])Set the constraints tolerance parameters used in the solver convergence tests.
setConstraints
(constraints[, C, args, kargs])Set the callback to compute constraints.
setConvergedReason
(reason)Set the termination flag.
setConvergenceTest
(converged[, args, kargs])Set the callback used to test for solver convergence.
setEqualityConstraints
(equality_constraints, c)Set equality constraints callback.
Configure the solver from the options database.
setGradient
(gradient[, g, args, kargs])Set the gradient evaluation callback.
setGradientNorm
(mat)Set the matrix used to compute inner products.
setHessian
(hessian[, H, P, args, kargs])Set the callback to compute the Hessian matrix.
setInitialTrustRegionRadius
(radius)Set the initial trust region radius.
setIterationNumber
(its)Set the current iteration number.
setJacobian
(jacobian[, J, P, args, kargs])Set the callback to compute the Jacobian.
setJacobianDesign
(jacobian_design[, J, ...])Set Jacobian design callback.
setJacobianEquality
(jacobian_equality[, J, ...])Set Jacobian equality constraints callback.
setJacobianResidual
(jacobian[, J, P, args, ...])Set the callback to compute the least-squares residual Jacobian.
setJacobianState
(jacobian_state[, J, P, I, ...])Set Jacobian state callback.
setLMVMH0
(mat)Set the initial Hessian for the quasi-Newton approximation.
Set the maximum number of objective evaluations within the solver.
setMaximumIterations
(mit)Set the maximum number of solver iterations.
setMonitor
(monitor[, args, kargs])Set the callback used to monitor solver convergence.
setObjective
(objective[, args, kargs])Set the objective function evaluation callback.
setObjectiveGradient
(objgrad[, g, args, kargs])Set the objective function and gradient evaluation callback.
setOptionsPrefix
(prefix)Set the prefix used for searching for options in the database.
setPythonContext
(context)Set the instance of the class implementing the required Python methods.
setPythonType
(py_type)Set the fully qualified Python name of the class to be used.
setResidual
(residual[, R, args, kargs])Set the residual evaluation callback for least-squares applications.
setSolution
(x)Set the vector used to store the solution.
setStateDesignIS
([state, design])Set the index sets indicating state and design variables.
setTolerances
([gatol, grtol, gttol])Set the tolerance parameters used in the solver convergence tests.
setType
(tao_type)Set the type of the solver.
setUp
()Set up the internal data structures for using the solver.
setUpdate
(update[, args, kargs])Set the callback to compute update at each optimization step.
setVariableBounds
(varbounds[, args, kargs])Set the upper and lower bounds for the optimization problem.
solve
([x])Solve the optimization problem.
view
([viewer])View the solver.
Attributes Summary
Application context.
Constraints norm.
Boolean indicating if the solver has converged.
Broken.
Boolean indicating if the solver has failed.
Broken.
Objective value.
Gradient norm.
Gradient vector.
Broken.
Boolean indicating if the solver has not converged yet.
Number of iterations.
Linear solver.
Objective value.
Converged reason.
Solution vector.
Methods Documentation
- appendOptionsPrefix(prefix)¶
Append to the prefix used for searching for options in the database.
Logically collective.
See also
Working with PETSc options (TODO),
setOptionsPrefix
,petsc.TaoAppendOptionsPrefix
- cancelMonitor()¶
Cancel all the monitors of the solver.
Logically collective.
See also
setMonitor
,petsc.TaoCancelMonitors
Source code at petsc4py/PETSc/TAO.pyx:1210
- Return type:
- computeConstraints(x, c)¶
Compute the vector corresponding to the constraints.
Collective.
- Parameters:
- Return type:
See also
setVariableBounds
,petsc.TaoComputeVariableBounds
- computeDualVariables(xl, xu)¶
Compute the dual vectors corresponding to variables’ bounds.
Collective.
See also
petsc.TaoComputeDualVariables
- computeGradient(x, g)¶
Compute the gradient of the objective function.
Collective.
See also
setGradient
,petsc.TaoComputeGradient
- computeHessian(x, H, P=None)¶
Compute the Hessian of the objective function.
Collective.
- Parameters:
- Return type:
See also
setHessian
,petsc.TaoComputeHessian
- computeJacobian(x, J, P=None)¶
Compute the Jacobian.
Collective.
- Parameters:
- Return type:
See also
setJacobian
,petsc.TaoComputeJacobian
- computeObjective(x)¶
Compute the value of the objective function.
Collective.
See also
setObjective
,petsc.TaoComputeObjective
- computeObjectiveGradient(x, g)¶
Compute the gradient of the objective function and its value.
Collective.
- Parameters:
- Return type:
See also
setObjectiveGradient
,setGradient
,setObjective
,petsc.TaoComputeObjectiveAndGradient
- computeResidual(x, f)¶
Compute the residual.
Collective.
See also
setResidual
,petsc.TaoComputeResidual
- computeVariableBounds(xl, xu)¶
Compute the vectors corresponding to variables’ bounds.
Collective.
See also
setVariableBounds
,petsc.TaoComputeVariableBounds
- create(comm=None)¶
Create a TAO solver.
Collective.
- Parameters:
comm (Comm | None) – MPI communicator, defaults to
Sys.getDefaultComm
.- Return type:
See also
Sys.getDefaultComm
,petsc.TaoCreate
- createPython(context=None, comm=None)¶
Create an optimization solver of Python type.
Collective.
- Parameters:
context (Any) – An instance of the Python class implementing the required methods.
comm (Comm | None) – MPI communicator, defaults to
Sys.getDefaultComm
.
- Return type:
- destroy()¶
Destroy the solver.
Collective.
See also
petsc.TaoDestroy
Source code at petsc4py/PETSc/TAO.pyx:129
- Return type:
- getAppCtx()¶
Return the application context.
Source code at petsc4py/PETSc/TAO.pyx:283
- Return type:
- getBNCGType()¶
Return the type of the BNCG solver.
Not collective.
See also
setBNCGType
,petsc.TaoBNCGGetType
Source code at petsc4py/PETSc/TAO.pyx:1406
- Return type:
- getBRGNDampingVector()¶
Return the damping vector.
Not collective.
Source code at petsc4py/PETSc/TAO.pyx:1637
- Return type:
- getBRGNSubsolver()¶
Return the subsolver inside the BRGN solver.
Not collective.
See also
petsc.TaoBRGNGetSubsolver
Source code at petsc4py/PETSc/TAO.pyx:1554
- Return type:
- getConstraintTolerances()¶
Return the constraints tolerance parameters used in the convergence tests.
Not collective.
- Returns:
- Return type:
See also
setConstraintTolerances
,petsc.TaoGetConstraintTolerances
- getConvergedReason()¶
Return the termination flag.
Not collective.
See also
setConvergedReason
,petsc.TaoGetConvergedReason
Source code at petsc4py/PETSc/TAO.pyx:1155
- Return type:
- getConvergenceTest()¶
Return the callback used to test for solver convergence.
Not collective.
See also
- getGradient()¶
Return the vector used to store the gradient and the evaluation callback.
Not collective.
See also
setGradient
,setHessian
,petsc.TaoGetGradient
Source code at petsc4py/PETSc/TAO.pyx:415
- Return type:
- getGradientNorm()¶
Return the matrix used to compute inner products.
Not collective.
See also
setGradientNorm
,petsc.TaoGetGradientNorm
Source code at petsc4py/PETSc/TAO.pyx:1321
- Return type:
- getHessian()¶
Return the matrices used to store the Hessian and the evaluation callback.
Not collective.
See also
setHessian
,petsc.TaoGetHessian
Source code at petsc4py/PETSc/TAO.pyx:577
- Return type:
- getIterationNumber()¶
Return the current iteration number.
Not collective.
See also
setIterationNumber
,petsc.TaoGetIterationNumber
Source code at petsc4py/PETSc/TAO.pyx:1433
- Return type:
- getKSP()¶
Return the linear solver used by the nonlinear solver.
Not collective.
See also
petsc.TaoGetKSP
Source code at petsc4py/PETSc/TAO.pyx:1537
- Return type:
- getLMVMH0()¶
Return the initial Hessian for the quasi-Newton approximation.
Not collective.
See also
setLMVMH0
,petsc.TaoLMVMGetH0
Source code at petsc4py/PETSc/TAO.pyx:1348
- Return type:
- getLMVMH0KSP()¶
Return the
KSP
for the inverse of the initial Hessian approximation.Not collective.
See also
setLMVMH0
,petsc.TaoLMVMGetH0KSP
Source code at petsc4py/PETSc/TAO.pyx:1363
- Return type:
- getLineSearch()¶
Return the TAO Line Search object.
Not collective.
See also
petsc.TaoGetLineSearch
Source code at petsc4py/PETSc/TAO.pyx:1734
- Return type:
- getMaximumFunctionEvaluations()¶
Return the maximum number of objective evaluations within the solver.
Not collective.
See also
setMaximumFunctionEvaluations
,petsc.TaoGetMaximumFunctionEvaluations
Source code at petsc4py/PETSc/TAO.pyx:1045
- Return type:
- getMaximumIterations()¶
Return the maximum number of solver iterations.
Not collective.
See also
setMaximumIterations
,petsc.TaoGetMaximumIterations
Source code at petsc4py/PETSc/TAO.pyx:1018
- Return type:
- getMonitor()¶
Return the callback used to monitor solver convergence.
Not collective.
See also
- getObjectiveAndGradient()¶
Return the vector used to store the gradient and the evaluation callback.
Not collective.
See also
setObjectiveGradient
,petsc.TaoGetObjectiveAndGradient
Source code at petsc4py/PETSc/TAO.pyx:461
- Return type:
- getObjectiveValue()¶
Return the current value of the objective function.
Not collective.
See also
setObjective
,petsc.TaoGetSolutionStatus
Source code at petsc4py/PETSc/TAO.pyx:1447
- Return type:
- getOptionsPrefix()¶
Return the prefix used for searching for options in the database.
Not collective.
See also
Working with PETSc options (TODO),
setOptionsPrefix
,petsc.TaoGetOptionsPrefix
Source code at petsc4py/PETSc/TAO.pyx:224
- Return type:
- getPythonContext()¶
Return the instance of the class implementing the required Python methods.
Not collective.
Source code at petsc4py/PETSc/TAO.pyx:1689
- Return type:
- getPythonType()¶
Return the fully qualified Python name of the class used by the solver.
Not collective.
See also
PETSc Python optimization solver type (TODO),
setPythonContext
,setPythonType
,petsc.TaoPythonGetType
Source code at petsc4py/PETSc/TAO.pyx:1719
- Return type:
- getSolution()¶
Return the vector holding the solution.
Not collective.
See also
setSolution
,petsc.TaoGetSolution
Source code at petsc4py/PETSc/TAO.pyx:1294
- Return type:
- getSolutionNorm()¶
Return the objective function value and the norms of gradient and constraints.
Not collective.
- Returns:
- Return type:
See also
getSolutionStatus
,petsc.TaoGetSolutionStatus
- getSolutionStatus()¶
Return the solution status.
Not collective.
- Returns:
its (
int
) – Current number of iterations.f (
float
) – Current value of the objective function.res (
float
) – Current value of the residual norm.cnorm (
float
) – Current value of the constrains norm.step (
float
) – Current value of the step.reason (
ConvergedReason
) – Current value of converged reason.
- Return type:
See also
petsc.TaoGetSolutionStatus
- getTolerances()¶
Return the tolerance parameters used in the solver convergence tests.
Not collective.
- Returns:
- Return type:
See also
setTolerances
,petsc.TaoGetTolerances
- getType()¶
Return the type of the solver.
Not collective.
See also
setType
,petsc.TaoGetType
Source code at petsc4py/PETSc/TAO.pyx:182
- Return type:
- getUpdate()¶
Return the callback to compute the update.
Not collective.
See also
- getVariableBounds()¶
Return the upper and lower bounds vectors.
Not collective.
See also
setVariableBounds
,petsc.TaoGetVariableBounds
- monitor(its=None, f=None, res=None, cnorm=None, step=None)¶
Monitor the solver.
Collective.
This function should be called without arguments, unless users want to modify the values internally stored by the solver.
- Parameters:
its (int) – Current number of iterations or
None
to use the value stored internally by the solver.f (float) – Current value of the objective function or
None
to use the value stored internally by the solver.res (float) – Current value of the residual norm or
None
to use the value stored internally by the solver.cnorm (float) – Current value of the constrains norm or
None
to use the value stored internally by the solver.step (float) – Current value of the step or
None
to use the value stored internally by the solver.
- Return type:
See also
setMonitor
,petsc.TaoMonitor
- setAppCtx(appctx)¶
Set the application context.
- setBNCGType(cg_type)¶
Set the type of the BNCG solver.
Collective.
See also
getBNCGType
,petsc.TaoBNCGSetType
- setBRGNDictionaryMatrix(D)¶
Set the dictionary matrix.
Collective.
See also
petsc.TaoBRGNSetDictionaryMatrix
- setBRGNRegularizerHessian(hessian, H=None, args=None, kargs=None)¶
Set the callback to compute the regularizer Hessian.
Logically collective.
See also
petsc.TaoBRGNSetRegularizerHessianRoutine
- setBRGNRegularizerObjectiveGradient(objgrad, args=None, kargs=None)¶
Set the callback to compute the regularizer objective and gradient.
Logically collective.
See also
petsc.TaoBRGNSetRegularizerObjectiveAndGradientRoutine
- setBRGNRegularizerWeight(weight)¶
Set the regularizer weight.
Collective.
- setBRGNSmoothL1Epsilon(epsilon)¶
Set the smooth L1 epsilon.
Collective.
See also
petsc.TaoBRGNSetL1SmoothEpsilon
- setConstraintTolerances(catol=None, crtol=None)¶
Set the constraints tolerance parameters used in the solver convergence tests.
Collective.
- Parameters:
- Return type:
See also
getConstraintTolerances
,petsc.TaoSetConstraintTolerances
- setConstraints(constraints, C=None, args=None, kargs=None)¶
Set the callback to compute constraints.
Logically collective.
- Parameters:
- Return type:
See also
petsc.TaoSetConstraintsRoutine
- setConvergedReason(reason)¶
Set the termination flag.
Collective.
See also
getConvergedReason
,petsc.TaoSetConvergedReason
Source code at petsc4py/PETSc/TAO.pyx:1142
- Parameters:
reason (ConvergedReason) –
- Return type:
- setConvergenceTest(converged, args=None, kargs=None)¶
Set the callback used to test for solver convergence.
Logically collective.
- Parameters:
- Return type:
See also
getConvergenceTest
,petsc.TaoSetConvergenceTest
- setEqualityConstraints(equality_constraints, c, args=None, kargs=None)¶
Set equality constraints callback.
Logically collective.
See also
petsc.TaoSetEqualityConstraintsRoutine
- setFromOptions()¶
Configure the solver from the options database.
Collective.
See also
Working with PETSc options (TODO),
petsc.TaoSetFromOptions
Source code at petsc4py/PETSc/TAO.pyx:238
- Return type:
- setGradient(gradient, g=None, args=None, kargs=None)¶
Set the gradient evaluation callback.
Logically collective.
- Parameters:
- Return type:
See also
setObjective
,setObjectiveGradient
,setHessian
,petsc.TaoSetGradient
- setGradientNorm(mat)¶
Set the matrix used to compute inner products.
Collective.
See also
getGradientNorm
,petsc.TaoSetGradientNorm
- setHessian(hessian, H=None, P=None, args=None, kargs=None)¶
Set the callback to compute the Hessian matrix.
Logically collective.
- Parameters:
- Return type:
See also
getHessian
,setObjective
,setObjectiveGradient
,setGradient
,petsc.TaoSetHessian
- setInitialTrustRegionRadius(radius)¶
Set the initial trust region radius.
Collective.
See also
petsc.TaoSetInitialTrustRegionRadius
- setIterationNumber(its)¶
Set the current iteration number.
Collective.
See also
getIterationNumber
,petsc.TaoSetIterationNumber
- setJacobian(jacobian, J=None, P=None, args=None, kargs=None)¶
Set the callback to compute the Jacobian.
Logically collective.
- Parameters:
- Return type:
See also
petsc.TaoSetJacobianRoutine
- setJacobianDesign(jacobian_design, J=None, args=None, kargs=None)¶
Set Jacobian design callback.
Logically collective.
See also
petsc.TaoSetJacobianDesignRoutine
- setJacobianEquality(jacobian_equality, J=None, P=None, args=None, kargs=None)¶
Set Jacobian equality constraints callback.
Logically collective.
See also
petsc.TaoSetJacobianEqualityRoutine
- setJacobianResidual(jacobian, J=None, P=None, args=None, kargs=None)¶
Set the callback to compute the least-squares residual Jacobian.
Logically collective.
- Parameters:
- Return type:
See also
setResidual
,petsc.TaoSetJacobianResidualRoutine
- setJacobianState(jacobian_state, J=None, P=None, I=None, args=None, kargs=None)¶
Set Jacobian state callback.
Logically collective.
See also
petsc.TaoSetJacobianStateRoutine
- setLMVMH0(mat)¶
Set the initial Hessian for the quasi-Newton approximation.
Collective.
See also
getLMVMH0
,petsc.TaoLMVMSetH0
- setMaximumFunctionEvaluations(mit)¶
Set the maximum number of objective evaluations within the solver.
Collective.
See also
setMaximumIterations
,petsc.TaoSetMaximumFunctionEvaluations
- setMaximumIterations(mit)¶
Set the maximum number of solver iterations.
Collective.
See also
setTolerances
,petsc.TaoSetMaximumIterations
- setMonitor(monitor, args=None, kargs=None)¶
Set the callback used to monitor solver convergence.
Logically collective.
- Parameters:
- Return type:
See also
getMonitor
,petsc.TaoSetMonitor
- setObjective(objective, args=None, kargs=None)¶
Set the objective function evaluation callback.
Logically collective.
- Parameters:
- Return type:
See also
setGradient
,setObjectiveGradient
,petsc.TaoSetObjective
- setObjectiveGradient(objgrad, g=None, args=None, kargs=None)¶
Set the objective function and gradient evaluation callback.
Logically collective.
- Parameters:
- Return type:
See also
setObjective
,setGradient
,setHessian
,getObjectiveAndGradient
,petsc.TaoSetObjectiveAndGradient
- setOptionsPrefix(prefix)¶
Set the prefix used for searching for options in the database.
Logically collective.
See also
Working with PETSc options (TODO),
petsc.TaoSetOptionsPrefix
- setPythonContext(context)¶
Set the instance of the class implementing the required Python methods.
Not collective.
- setPythonType(py_type)¶
Set the fully qualified Python name of the class to be used.
Collective.
See also
PETSc Python optimization solver type (TODO),
setPythonContext
,getPythonType
,petsc.TaoPythonSetType
- setResidual(residual, R=None, args=None, kargs=None)¶
Set the residual evaluation callback for least-squares applications.
Logically collective.
- Parameters:
- Return type:
See also
setJacobianResidual
,petsc.TaoSetResidualRoutine
- setSolution(x)¶
Set the vector used to store the solution.
Collective.
See also
getSolution
,petsc.TaoSetSolution
- setStateDesignIS(state=None, design=None)¶
Set the index sets indicating state and design variables.
Collective.
See also
petsc.TaoSetStateDesignIS
- setTolerances(gatol=None, grtol=None, gttol=None)¶
Set the tolerance parameters used in the solver convergence tests.
Collective.
- Parameters:
gatol (float) – The absolute norm of the gradient. Defaults to
DEFAULT
.grtol (float) – The relative norm of the gradient with respect to the initial norm of the objective. Defaults to
DEFAULT
.gttol (float) – The relative norm of the gradient with respect to the initial norm of the gradient. Defaults to
DEFAULT
.
- Return type:
See also
getTolerances
,petsc.TaoSetTolerances
- setType(tao_type)¶
Set the type of the solver.
Logically collective.
See also
getType
,petsc.TaoSetType
- setUp()¶
Set up the internal data structures for using the solver.
Collective.
See also
petsc.TaoSetUp
Source code at petsc4py/PETSc/TAO.pyx:250
- Return type:
- setUpdate(update, args=None, kargs=None)¶
Set the callback to compute update at each optimization step.
Logically collective.
- Parameters:
- Return type:
See also
getUpdate
,petsc.TaoSetUpdate
- setVariableBounds(varbounds, args=None, kargs=None)¶
Set the upper and lower bounds for the optimization problem.
Logically collective.
- Parameters:
- Return type:
See also
petsc.TaoSetVariableBounds
,petsc.TaoSetVariableBoundsRoutine
- solve(x=None)¶
Solve the optimization problem.
Collective.
- Parameters:
x (Vec | None) – The starting vector or
None
to use the vector stored internally.- Return type:
See also
setSolution
,getSolution
,petsc.TaoSolve
- view(viewer=None)¶
View the solver.
Collective.
See also
petsc.TaoView
Attributes Documentation
- appctx¶
Application context.
- cnorm¶
Constraints norm.
- converged¶
Boolean indicating if the solver has converged.
- ctol¶
Broken.
- diverged¶
Boolean indicating if the solver has failed.
- ftol¶
Broken.
- function¶
Objective value.
- gnorm¶
Gradient norm.
- gradient¶
Gradient vector.
- gtol¶
Broken.
- iterating¶
Boolean indicating if the solver has not converged yet.
- its¶
Number of iterations.
- ksp¶
Linear solver.
- objective¶
Objective value.
- reason¶
Converged reason.
- solution¶
Solution vector.