gemseo.algos.stop_criteria module#
Various termination criteria for drivers.
- exception DesvarIsNan[source]#
Bases:
TerminationCriterion
Stops driver when the design variables are nan.
- exception FtolReached[source]#
Bases:
TerminationCriterion
Exception raised when the f_tol_rel or f_tol_abs criteria is reached.
- exception FunctionIsNan[source]#
Bases:
TerminationCriterion
Stops driver when a function has NaN value or NaN Jacobian.
- exception KKTReached[source]#
Bases:
TerminationCriterion
A termination criterion based on the Karush-Kuhn-Tucker (KKT) residual norm.
- exception MaxIterReachedException[source]#
Bases:
TerminationCriterion
Exception raised when the maximum number of iterations is reached.
- exception MaxTimeReached[source]#
Bases:
TerminationCriterion
Exception raised when the maximum execution time is reached.
- exception XtolReached[source]#
Bases:
TerminationCriterion
Exception raised when the x_tol_rel or x_tol_abs criteria is reached.
- class BaseToleranceTester(absolute=0.0, relative=0.0, n_last_iterations=3)[source]#
Bases:
object
The base class to test the tolerance with respect to a reference value.
The reference value corresponds to the coordinate-wise average of the values associated to the last iterations.
- Parameters:
- check(problem, raise_exception=False, **kwargs)[source]#
Check whether the tolerance criterion is met.
- Parameters:
problem (OptimizationProblem) -- The optimization problem to which the database is attached.
raise_exception (bool) --
Whether to raise an exception when the tolerance criterion is not met.
By default it is set to False.
**kwargs (Any) -- The options of the tester.
- Returns:
Whether the tolerance criterion is not met.
- Raises:
TerminationCriterion -- When the tolerance criterion is not met and
raise_exception
isTrue
.- Return type:
- termination_criterion: TerminationCriterion#
The termination criterion.
- class DesignToleranceTester(absolute=0.0, relative=0.0, n_last_iterations=3)[source]#
Bases:
BaseToleranceTester
A tolerance tester for the design_vector.
- Parameters:
- termination_criterion#
alias of
XtolReached
- class KKTConditionsTester(absolute=0.0, relative=0.0, n_last_iterations=3, ineq_tolerance=0.0, kkt_norm=0.0)[source]#
Bases:
BaseToleranceTester
A tester for the Karush-Kuhn-Tucker (KKT) conditions.
- Parameters:
- termination_criterion#
alias of
KKTReached
- class ObjectiveToleranceTester(absolute=0.0, relative=0.0, n_last_iterations=3)[source]#
Bases:
BaseToleranceTester
A tolerance tester for the objective.
- Parameters:
- termination_criterion#
alias of
FtolReached
- is_f_tol_reached(opt_problem, f_tol_rel=1e-06, f_tol_abs=1e-06, n_x=2)[source]#
Tests if the tolerance on the objective function are reached.
The average function value of the last n_x points are taken Then it is checked that all points are within the distance of the center with relative and absolute tolerances specified by the user.
- Parameters:
opt_problem (OptimizationProblem) -- the optimization problem containing the iterations
f_tol_rel (float) --
relative tolerance
By default it is set to 1e-06.
f_tol_abs (float) --
absolute tolerance
By default it is set to 1e-06.
n_x (int) --
number of design vectors to account for
By default it is set to 2.
- Return type:
bool | bool_
- is_kkt_residual_norm_reached(opt_problem, x_vect, kkt_abs_tol=0.0, kkt_rel_tol=0.0, ineq_tolerance=0.0001, reference_residual=1.0)[source]#
Test if the KKT conditions are satisfied.
- Parameters:
opt_problem (OptimizationProblem) -- The optimization problem containing an optimization history.
x_vect (ndarray) -- The design point vector where the KKT conditions are tested.
kkt_abs_tol (float) --
The absolute tolerance on the KKT condition residual.
By default it is set to 0.0.
kkt_rel_tol (float) --
The relative tolerance on the KKT condition residual.
By default it is set to 0.0.
ineq_tolerance (float) --
The tolerance to consider a constraint as active.
By default it is set to 0.0001.
reference_residual (float) --
The reference KKT condition residual.
By default it is set to 1.0.
- Returns:
Whether the absolute or the relative KKT residual norm criterion is reached.
- Return type:
- is_x_tol_reached(opt_problem, x_tol_rel=1e-06, x_tol_abs=1e-06, n_x=2)[source]#
Tests if the tolerance on the design variables are reached.
The coordinate wise average of the last n_x points are taken Then it is checked that all points are within the distance of the center with relative and absolute tolerances specified by the user.
- Parameters:
opt_problem (OptimizationProblem) -- the optimization problem containing the iterations
x_tol_rel (float) --
relative tolerance
By default it is set to 1e-06.
x_tol_abs (float) --
absolute tolerance
By default it is set to 1e-06.
n_x (int) --
number of design vectors to account for
By default it is set to 2.
- Return type:
bool | bool_
- kkt_residual_computation(opt_problem, x_vect, ineq_tolerance=0.0001)[source]#
Compute the KKT residual norm.
This implementation is inspired from Svanberg Matlab implementation of MMA algorithm see [Sva98]
- Parameters:
opt_problem (OptimizationProblem) -- The optimization problem containing an optimization history.
x_vect (ndarray) -- The design point vector where the KKT conditions are tested.
ineq_tolerance (float) --
The tolerance to consider a constraint as active.
By default it is set to 0.0001.
- Returns:
The KKT residual norm.
- Return type: