Lines Matching defs:tao

1 #include <../src/tao/constrained/impls/almm/almm.h> /*I "petsctao.h" I*/
13 static PetscErrorCode TaoSolve_ALMM(Tao tao)
15 TAO_ALMM *auglag = (TAO_ALMM *)tao->data;
21 if (!tao->recycle) {
22 if (tao->ineq_constrained) {
24 PetscCall(TaoALMMCombinePrimal_Private(tao, auglag->Px, auglag->Ps, auglag->P));
27 if (tao->eq_constrained) PetscCall(VecSet(auglag->Ye, 0.0));
31 PetscCall((*auglag->sub_obj)(tao));
32 PetscCall(TaoALMMComputeOptimalityNorms_Private(tao));
34 PetscCall(PetscInfo(tao, "Solving with %s formulation\n", TaoALMMTypes[auglag->type]));
35 PetscCall(TaoLogConvergenceHistory(tao, auglag->Lval, auglag->gnorm, auglag->cnorm, tao->ksp_its));
36 PetscCall(TaoMonitor(tao, tao->niter, auglag->fval, auglag->gnorm, auglag->cnorm, 0.0));
37 PetscUseTypeMethod(tao, convergencetest, tao->cnvP);
45 if (tao->eq_constrained) PetscCall(VecDot(auglag->Ce, auglag->Ce, &auglag->cenorm));
47 if (tao->ineq_constrained) {
61 PetscCall(PetscInfo(tao, "Initial penalty: %.2g\n", (double)auglag->mu));
64 while (tao->reason == TAO_CONTINUE_ITERATING) {
65 ++tao->niter;
67 PetscCall(PetscInfo(tao, "Subsolver tolerance: ||G|| <= %e\n", (double)auglag->gtol));
74 tao->ksp_its += auglag->subsolver->ksp_its;
75 if (reason != TAO_CONVERGED_GATOL) PetscCall(PetscInfo(tao, "Subsolver failed to converge, reason: %s\n", TaoConvergedReasons[reason]));
77 PetscCall((*auglag->sub_obj)(tao));
78 PetscCall(TaoALMMComputeOptimalityNorms_Private(tao));
82 PetscCall(PetscInfo(tao, "Multipliers updated: ||C|| <= %e\n", (double)auglag->ytol));
84 if (tao->eq_constrained) {
91 if (tao->ineq_constrained) {
100 auglag->ytol = PetscMax(tao->catol, auglag->ytol / PetscPowReal(auglag->mu, auglag->mu_pow_good));
101 auglag->gtol = PetscMax(tao->gatol, auglag->gtol / auglag->mu);
109 auglag->ytol = PetscMax(tao->catol, 1.0 / PetscPowReal(auglag->mu, auglag->mu_pow_bad));
110 auglag->gtol = PetscMax(tao->gatol, 1.0 / auglag->mu);
112 PetscCall(PetscInfo(tao, "Penalty increased: mu = %.2g\n", (double)auglag->mu));
114 PetscCall(TaoLogConvergenceHistory(tao, auglag->fval, auglag->gnorm, auglag->cnorm, tao->ksp_its));
115 PetscCall(TaoMonitor(tao, tao->niter, auglag->fval, auglag->gnorm, auglag->cnorm, updated));
116 PetscUseTypeMethod(tao, convergencetest, tao->cnvP);
121 static PetscErrorCode TaoView_ALMM(Tao tao, PetscViewer viewer)
123 TAO_ALMM *auglag = (TAO_ALMM *)tao->data;
139 static PetscErrorCode TaoSetUp_ALMM(Tao tao)
141 TAO_ALMM *auglag = (TAO_ALMM *)tao->data;
147 PetscCheck(!tao->ineq_doublesided, PetscObjectComm((PetscObject)tao), PETSC_ERR_ARG_WRONGSTATE, "TAOALMM does not support double-sided inequality constraint definition. Please restructure your inequality constraint to fit the form c(x) >= 0.");
148 PetscCheck(tao->eq_constrained || tao->ineq_constrained, PetscObjectComm((PetscObject)tao), PETSC_ERR_ORDER, "Equality and/or inequality constraints must be defined before solver setup.");
149 PetscCall(TaoComputeVariableBounds(tao));
151 PetscCall(VecGetType(tao->solution, &vec_type));
152 auglag->Px = tao->solution;
153 if (!tao->gradient) { /* base gradient */
154 PetscCall(VecDuplicate(tao->solution, &tao->gradient));
156 auglag->LgradX = tao->gradient;
158 PetscCall(VecDuplicate(tao->solution, &auglag->Xwork));
160 if (tao->eq_constrained) {
161 auglag->Ce = tao->constraints_equality;
162 auglag->Ae = tao->jacobian_equality;
168 if (tao->ineq_constrained) {
169 auglag->Ci = tao->constraints_inequality;
170 auglag->Ai = tao->jacobian_inequality;
195 if (tao->eq_constrained) {
217 /* create tao primal solution and gradient to interface with subsolver */
225 auglag->gtol0 = tao->gatol;
226 if (tao->gatol != tao->default_gatol && tao->catol != tao->default_catol) {
227 PetscCall(PetscInfo(tao, "TAOALMM with PHR: different gradient and constraint tolerances are not supported, setting catol = gatol\n"));
228 tao->catol = tao->gatol;
246 if (tao->bounded) {
252 PetscCall(PetscInfo(tao, "TAOCG detected for bound-constrained problem, switching to TAOBNCG.\n"));
256 PetscCall(PetscInfo(tao, "TAOLMVM detected for bound-constrained problem, switching to TAOBQNLS.\n"));
261 if (tao->ineq_constrained) {
268 PetscCall(TaoALMMCombinePrimal_Private(tao, tao->XL, SL, auglag->PL));
269 PetscCall(TaoALMMCombinePrimal_Private(tao, tao->XU, SU, auglag->PU));
275 PetscCall(VecCopy(tao->XL, auglag->PL));
276 PetscCall(VecCopy(tao->XU, auglag->PU));
283 if (tao->ineq_constrained) {
309 PetscCall(PetscInfo(tao, "TAOCG detected for TAO_ALMM_CLASSIC, switching to TAOBNCG.\n"));
313 PetscCall(PetscInfo(tao, "TAOLMVM detected for TAO_ALMM_CLASSIC, switching to TAOBQNLS.\n"));
323 static PetscErrorCode TaoDestroy_ALMM(Tao tao)
325 TAO_ALMM *auglag = (TAO_ALMM *)tao->data;
331 if (tao->setupcalled) {
333 if (tao->eq_constrained) {
337 if (tao->ineq_constrained) {
351 if (tao->eq_constrained) {
363 if (tao->bounded) {
373 PetscCall(PetscObjectComposeFunction((PetscObject)tao, "TaoALMMGetType_C", NULL));
374 PetscCall(PetscObjectComposeFunction((PetscObject)tao, "TaoALMMSetType_C", NULL));
375 PetscCall(PetscObjectComposeFunction((PetscObject)tao, "TaoALMMGetSubsolver_C", NULL));
376 PetscCall(PetscObjectComposeFunction((PetscObject)tao, "TaoALMMSetSubsolver_C", NULL));
377 PetscCall(PetscObjectComposeFunction((PetscObject)tao, "TaoALMMGetMultipliers_C", NULL));
378 PetscCall(PetscObjectComposeFunction((PetscObject)tao, "TaoALMMSetMultipliers_C", NULL));
379 PetscCall(PetscObjectComposeFunction((PetscObject)tao, "TaoALMMGetPrimalIS_C", NULL));
380 PetscCall(PetscObjectComposeFunction((PetscObject)tao, "TaoALMMGetDualIS_C", NULL));
381 PetscCall(PetscFree(tao->data));
385 static PetscErrorCode TaoSetFromOptions_ALMM(Tao tao, PetscOptionItems PetscOptionsObject)
387 TAO_ALMM *auglag = (TAO_ALMM *)tao->data;
402 PetscCall(TaoSetOptionsPrefix(auglag->subsolver, ((PetscObject)tao)->prefix));
460 PETSC_EXTERN PetscErrorCode TaoCreate_ALMM(Tao tao)
467 tao->ops->destroy = TaoDestroy_ALMM;
468 tao->ops->setup = TaoSetUp_ALMM;
469 tao->ops->setfromoptions = TaoSetFromOptions_ALMM;
470 tao->ops->view = TaoView_ALMM;
471 tao->ops->solve = TaoSolve_ALMM;
473 PetscCall(TaoParametersInitialize(tao));
474 PetscObjectParameterSetDefault(tao, gatol, 1.e-5);
475 PetscObjectParameterSetDefault(tao, grtol, 0.0);
476 PetscObjectParameterSetDefault(tao, gttol, 0.0);
477 PetscObjectParameterSetDefault(tao, catol, 1.e-5);
478 PetscObjectParameterSetDefault(tao, crtol, 0.0);
480 tao->data = (void *)auglag;
481 auglag->parent = tao;
500 PetscCall(TaoCreate(PetscObjectComm((PetscObject)tao), &auglag->subsolver));
506 PetscCall(PetscObjectIncrementTabLevel((PetscObject)auglag->subsolver, (PetscObject)tao, 1));
508 PetscCall(PetscObjectComposeFunction((PetscObject)tao, "TaoALMMGetType_C", TaoALMMGetType_Private));
509 PetscCall(PetscObjectComposeFunction((PetscObject)tao, "TaoALMMSetType_C", TaoALMMSetType_Private));
510 PetscCall(PetscObjectComposeFunction((PetscObject)tao, "TaoALMMGetSubsolver_C", TaoALMMGetSubsolver_Private));
511 PetscCall(PetscObjectComposeFunction((PetscObject)tao, "TaoALMMSetSubsolver_C", TaoALMMSetSubsolver_Private));
512 PetscCall(PetscObjectComposeFunction((PetscObject)tao, "TaoALMMGetMultipliers_C", TaoALMMGetMultipliers_Private));
513 PetscCall(PetscObjectComposeFunction((PetscObject)tao, "TaoALMMSetMultipliers_C", TaoALMMSetMultipliers_Private));
514 PetscCall(PetscObjectComposeFunction((PetscObject)tao, "TaoALMMGetPrimalIS_C", TaoALMMGetPrimalIS_Private));
515 PetscCall(PetscObjectComposeFunction((PetscObject)tao, "TaoALMMGetDualIS_C", TaoALMMGetDualIS_Private));
519 static PetscErrorCode TaoALMMCombinePrimal_Private(Tao tao, Vec X, Vec S, Vec P)
521 TAO_ALMM *auglag = (TAO_ALMM *)tao->data;
524 if (tao->ineq_constrained) {
535 static PetscErrorCode TaoALMMCombineDual_Private(Tao tao, Vec EQ, Vec IN, Vec Y)
537 TAO_ALMM *auglag = (TAO_ALMM *)tao->data;
540 if (tao->eq_constrained) {
541 if (tao->ineq_constrained) {
555 static PetscErrorCode TaoALMMSplitPrimal_Private(Tao tao, Vec P, Vec X, Vec S)
557 TAO_ALMM *auglag = (TAO_ALMM *)tao->data;
560 if (tao->ineq_constrained) {
572 static PetscErrorCode TaoALMMComputeOptimalityNorms_Private(Tao tao)
574 TAO_ALMM *auglag = (TAO_ALMM *)tao->data;
578 if (tao->bounded) PetscCall(VecBoundGradientProjection(auglag->LgradX, auglag->Px, tao->XL, tao->XU, auglag->LgradX));
582 if (tao->eq_constrained) PetscCall(VecNorm(auglag->Ce, NORM_INFINITY, &auglag->cenorm));
584 if (tao->ineq_constrained) {
600 static PetscErrorCode TaoALMMEvaluateIterate_Private(Tao tao)
602 TAO_ALMM *auglag = (TAO_ALMM *)tao->data;
606 PetscCall(TaoALMMSplitPrimal_Private(tao, auglag->P, auglag->Px, auglag->Ps));
609 PetscCall(TaoComputeObjectiveAndGradient(tao, auglag->Px, &auglag->fval, auglag->LgradX));
610 if (tao->eq_constrained) {
611 PetscCall(TaoComputeEqualityConstraints(tao, auglag->Px, auglag->Ce));
612 PetscCall(TaoComputeJacobianEquality(tao, auglag->Px, auglag->Ae, auglag->Ae));
614 if (tao->ineq_constrained) {
615 PetscCall(TaoComputeInequalityConstraints(tao, auglag->Px, auglag->Ci));
616 PetscCall(TaoComputeJacobianInequality(tao, auglag->Px, auglag->Ai, auglag->Ai));
632 PetscCall(TaoALMMCombineDual_Private(tao, auglag->Ce, auglag->Ci, auglag->C));
643 static PetscErrorCode TaoALMMComputePHRLagAndGradient_Private(Tao tao)
645 TAO_ALMM *auglag = (TAO_ALMM *)tao->data;
649 PetscCall(TaoALMMEvaluateIterate_Private(tao));
650 if (tao->eq_constrained) {
658 if (tao->ineq_constrained) {
670 PetscCall(TaoALMMCombinePrimal_Private(tao, auglag->LgradX, auglag->LgradS, auglag->G));
683 static PetscErrorCode TaoALMMComputeAugLagAndGradient_Private(Tao tao)
685 TAO_ALMM *auglag = (TAO_ALMM *)tao->data;
689 PetscCall(TaoALMMEvaluateIterate_Private(tao));
690 if (tao->eq_constrained) {
700 if (tao->ineq_constrained) {
714 PetscCall(TaoALMMCombinePrimal_Private(tao, auglag->LgradX, auglag->LgradS, auglag->G));
720 PetscErrorCode TaoALMMSubsolverObjective_Private(Tao tao, Vec P, PetscReal *Lval, PetscCtx ctx)
731 PetscErrorCode TaoALMMSubsolverObjectiveAndGradient_Private(Tao tao, Vec P, PetscReal *Lval, Vec G, PetscCtx ctx)