Skip to content

ensqp⚓︎

Ensemble-based sequential quadratic programming (EnSQP) for constrained optimization.

EnSQP ⚓︎

Bases: OptimizerBase

Ensemble-based sequential quadratic programming.

Solves

\[ \min_x f(x) \quad \text{s.t.} \quad c_{eq}(x) = 0, \quad c_{iq}(x) \geq 0, \quad lb \leq x \leq ub \]

with every derivative estimated from one ensemble of perturbed controls per iteration: the gradient of the objective, the Jacobian of the constraints and, optionally, the Hessian of the Lagrangian \(L = f - \lambda_{eq}^T c_{eq} - \lambda_{iq}^T c_{iq}\). Each iteration draws the ensemble, solves a quadratic program for the step and the multipliers, and backtracks on the \(\ell_1\) merit function \(f + \mu (\|c_{eq}\|_1 + \|\min(c_{iq}, 0)\|_1)\). The simulations per iteration are those of EnOpt: one ensemble plus the trial points of the line search.

With fewer ensemble members than controls the derivatives are known only along the perturbations. The step is then sought in the subspace they span, where the linear model of objective and constraints is reliable, and the Hessian is updated with the curvature measured along each accepted step.

The objective returns the constraint values with the objective value, from the same simulation: {'f': ..., 'c_eq': ..., 'c_iq': ...}. With a popt ensemble::

EnSQP.minimize(ens.get_state(), ens.function_and_constraints, jac=ens.gradient,
               con_jac=ens.constraint_jacobian, hess=ens.lagrangian_hessian,
               args=(ens.get_cov(),), bounds=ens.get_bounds(), **options)

__init__(x0, fun, jac=None, hess=None, args=(), bounds=None, callback=None, con_jac=None, **options) ⚓︎

Initialize an EnSQP optimizer instance.

Parameters:

Name Type Description Default
x0 ndarray

Initial control vector.

required
fun callable

Objective and constraints at a control vector: a dict with 'f' and, for the kinds of constraint the problem has, 'c_eq' and 'c_iq' (one value per constraint, or one column per geological model). An inequality is satisfied when c_iq >= 0. A bare objective value means no constraints other than the bounds.

required
jac callable

Ensemble gradient of the objective.

None
hess callable

Ensemble Hessian of the Lagrangian, taking the multipliers as the keyword multipliers. Needed with hessian='ensemble'.

None
args tuple

The first element is the covariance the ensemble is drawn with. Leave empty for callables that take the control vector only.

()
bounds sequence

Lower and upper bounds for each control.

None
callback callable

Called with the optimizer after every accepted step.

None
con_jac callable

Ensemble Jacobian of the constraints, a dict with 'c_eq' and/or 'c_iq' of shape (number of constraints, number of controls), computed from the ensemble of the last jac call. Needed when fun returns constraints.

None
**options

EnSQP configuration, plus everything :class:OptimizerBase takes except epf. - hessian: 'bfgs' (default) builds the Hessian of the Lagrangian from the changes in the ensemble gradients between iterations, with Powell's damping; 'ensemble' takes it from hess on every iteration's ensemble and makes it positive definite. The sampling error of an ensemble Hessian is as large as the Hessian itself until the members far outnumber the controls, so 'ensemble' is for few controls or large ensembles. With fewer members than controls (and scaling='sample') neither is possible, and the Hessian is built from the curvature along the accepted steps. - scaling: How an ensemble (natural) gradient or Jacobian, a covariance times the derivative, is turned into the derivative. 'sample' (default) divides by the covariance of the perturbations as sampled, which is exact for linear functions, and with fewer members than controls looks for the step in the subspace the perturbations span. 'cov' divides by the covariance they were drawn from, as EnOpt's averaged gradient does. 'sample' needs the ensemble's sample_covariance. - hess_min_eig: Smallest eigenvalue allowed in the ensemble Hessian, as a fraction of its largest (default: 1e-4). Eigenvalues are replaced by their absolute value and raised to this. - ctol: Largest constraint violation accepted at convergence (default: 1e-6). - max_step: Largest change of any control in one iteration, in the coordinates the optimizer works in (the unit cube with transform). Default: no limit beyond the bounds. - alpha_maxiter: Maximum number of step halvings per iteration (default: 10). - armijo_c1: Fraction of the predicted decrease of the merit function a step must achieve (default: 1e-4). - resample: Number of new ensembles, with a smaller covariance, to try when no step is accepted (default: 0). - cov_factor: Covariance shrink factor applied on each resampling (default: 0.5). - mu0: Initial penalty parameter of the merit function (default: 0). It only grows, staying above the largest multiplier. - natural_gradient: Whether jac, con_jac and hess return ensemble (natural) estimates, i.e. multiplied by the covariance, which are then divided by it. Default: the natural_gradient setting of the ensemble that jac is bound to, else False.

{}

check_function_convergence() ⚓︎

A small change in the objective only counts at a feasible point (and see :meth:_patience).

check_state_convergence() ⚓︎

A small step only counts at a feasible point (and see :meth:_patience).

log_columns() ⚓︎

The row of the iteration log: iteration, step halvings, objective, violation, penalty, step and KKT residual.

update_step() ⚓︎

One SQP iteration: ensemble derivatives, QP, and a line search on the merit function.