cosapp.drivers.optimizer

Driver`s for `System optimization calculation.

Classes

Optimizer(name[, owner])

Driver running an optimization problem on its System owner.

class cosapp.drivers.optimizer.Optimizer(name: str, owner: cosapp.systems.System | None = None, **kwargs)[source]

Bases: AbstractSolver

Driver running an optimization problem on its System owner.

In general, the optimization problems are of the form:

minimize f(x) subject to

g_i(x) >= 0,  i = 1,...,m
h_j(x)  = 0,  j = 1,...,p

where x is a vector of one or more variables. g_i(x) are the inequality constraints. h_j(x) are the equality constrains.

Optionally, the lower and upper bounds for each element in x can also be specified.

Parameters:
  • name (str) – Name of the driver

  • owner (System, optional) – System to which driver belongs; defaults to None

  • **kwargs (Any) – Keyword arguments will be used to set driver options

name

Name of the driver

Type:

str

parent

Top driver containing this driver; default None.

Type:

Driver, optional

owner

System to which this driver belong.

Type:

System

children

Drivers belonging to this one.

Type:

OrderedDict[Driver]

options
Options for the current driver
verbose : int, {0, 1}
Verbosity level of the driver; default 0 (i.e. minimal information)
eps : float, [1.5e-8, 1.]
Step size used for numerical approximation of the Jacobian; default 1.5e-8
ftol : float, [1.5e-8, 1.]
Iteration termination criteria (f^k - f^{k+1})/max{|f^k|,|f^{k+1}|,1} <= ftol;
default 1e-6
max_iter : int, [1, [
Maximum number of iterations; default 100
Type:

OptionsDictionary

solution
Type:

# TODO

Notes

This optimizer is a wrapper around scipy.optimize.minimize function. For more details please refer to: https://docs.scipy.org/doc/scipy-1.0.0/reference/generated/scipy.optimize.minimize.html

add_constraints(expression: str | List[str]) None[source]

Add constraints to the optimization problem.

Parameters:

List[str]] (- expression [str or) – Human-readable equality or inequality constraints, such as ‘x >= y**2’, ‘0 < alpha < 1’, ‘a == b’, or a list thereof.

Note

Expressions are parsed into non-negative constraints in the optimization problem. Strict inequalities are not enforced, and treated as non-strict inequalities. For instance, x < y translates into: y - x >= 0.

add_unknown(name: str | Iterable[dict | str | Unknown], max_abs_step: Number = inf, max_rel_step: Number = inf, lower_bound: Number = -inf, upper_bound: Number = inf) None[source]

Add unknown variables.

You can set variable one by one or provide a list of dictionary to set multiple variable at once. The dictionary key are the arguments of this method.

Parameters:
  • name (str or Iterable of dictionary or str) – Name of the variable or list of variable to add

  • max_rel_step (float, optional) – Maximal relative step by which the variable can be modified by the numerical solver; default numpy.inf

  • max_abs_step (float, optional) – Maximal absolute step by which the variable can be modified by the numerical solver; default numpy.inf

  • lower_bound (float, optional) – Lower bound on which the solver solution is saturated; default -numpy.inf

  • upper_bound (float, optional) – Upper bound on which the solver solution is saturated; default numpy.inf

Returns:

The modified MathematicalSystem

Return type:

MathematicalProblem

static available_methods() List[str][source]

Returns all possible values of option method. For more information, please refer to the online documentation of scipy.optimize.minimize.

compute() None[source]

Execute the optimization.

property constraints: Set[str]

representation of optimization constraints.

Type:

Set[str]

property objective
property objective_expr: str
resolution_method(fresidues: Callable[[Sequence[float]], float], x0: ndarray, args: Tuple[float | str, bool] = (), options: OptionsDictionary | None = None, bounds=None, constraints=None) SolverResults[source]

Function call to cancel the residues.

Parameters:
  • fresidues (Callable[[Sequence[float], Union[float, str]], float]) – Residues function taking two parameters (evaluation vector, time/ref) and returning the residues

  • x0 (numpy.ndarray) – The initial values vector to converge to the solution

  • args (Tuple[Union[float, str], bool], optional) – A tuple of additional argument for fresidues starting with the time/ref parameter

  • options (OptionsDictionary, optional) – Options for the numerical resolution method

Returns:

Solution container

Return type:

SolverResults

set_iteratives(x: Sequence[float]) None[source]
set_maximum(expression: str) None[source]

Set the scalar objective function to be maximized.

Parameters:

expression (str) – The objective expression to be maximized.

set_minimum(expression: str) None[source]

Set the scalar objective function to be minimized.

Parameters:

expression (str) – The objective expression to be minimized.

set_objective(expression: str) None[source]

Set the scalar quantity to be minimized. Same as set_minimum.

Note:

This method is deprecated, and should be replaced by either set_minimum or set_maximum, depending on the objective.

param expression:

The objective expression to be minimized.

type expression:

str

setup_run()[source]

Method called once before starting any simulation.