# scipy_optimizer.py

# scipy_optimizer.py¶

OpenMDAO Wrapper for the scipy.optimize.minimize family of local optimizers.

class`openmdao.drivers.scipy_optimizer.`

`ScipyOptimizeDriver`

(**kwargs)[source]Bases:

`openmdao.core.driver.Driver`

Driver wrapper for the scipy.optimize.minimize family of local optimizers.

Inequality constraints are supported by COBYLA and SLSQP, but equality constraints are only supported by SLSQP. None of the other optimizers support constraints.

- ScipyOptimizeDriver supports the following:
equality_constraints inequality_constraints

- Parameters

**kwargsdict of keyword argumentsKeyword arguments that will be mapped into the Driver options.

- Attributes

failboolFlag that indicates failure of most recent optimization.

iter_countintCounter for function evaluations.

resultOptimizeResultResult returned from scipy.optimize call.

opt_settingsdictDictionary of solver-specific options. See the scipy.optimize.minimize documentation.

_check_jacboolUsed internally to control when to perform singular checks on computed total derivs.

_con_cachedictCached result of constraint evaluations because scipy asks for them in a separate function.

_con_idxdictUsed for constraint bookkeeping in the presence of 2-sided constraints.

_grad_cacheOrderedDictCached result of nonlinear constraint derivatives because scipy asks for them in a separate function.

_exc_info3 item tupleStorage for exception and traceback information.

_obj_and_nlconslistList of objective + nonlinear constraints. Used to compute total derivatives for all except linear constraints.

_dvlistlistCopy of _designvars.

_lincongrad_cachenp.ndarrayPre-calculated gradients of linear constraints.

`__init__`

(**kwargs)[source]Initialize the ScipyOptimizeDriver.

`add_recorder`

(recorder)Add a recorder to the driver.

- Parameters

recorderCaseRecorderA recorder instance.

`cleanup`

()Clean up resources prior to exit.

`declare_coloring`

(num_full_jacs=3,tol=1e-25,orders=None,perturb_size=1e-09,min_improve_pct=5.0,show_summary=True,show_sparsity=False)Set options for total deriv coloring.

- Parameters

num_full_jacsintNumber of times to repeat partial jacobian computation when computing sparsity.

tolfloatTolerance used to determine if an array entry is nonzero during sparsity determination.

ordersintNumber of orders above and below the tolerance to check during the tolerance sweep.

perturb_sizefloatSize of input/output perturbation during generation of sparsity.

min_improve_pctfloatIf coloring does not improve (decrease) the number of solves more than the given percentage, coloring will not be used.

show_summaryboolIf True, display summary information after generating coloring.

show_sparsityboolIf True, display sparsity with coloring info after generating coloring.

`get_constraint_values`

(ctype='all',lintype='all',driver_scaling=True)Return constraint values.

- Parameters

ctypestrDefault is ‘all’. Optionally return just the inequality constraints with ‘ineq’ or the equality constraints with ‘eq’.

lintypestrDefault is ‘all’. Optionally return just the linear constraints with ‘linear’ or the nonlinear constraints with ‘nonlinear’.

driver_scalingboolWhen True, return values that are scaled according to either the adder and scaler or the ref and ref0 values that were specified when add_design_var, add_objective, and add_constraint were called on the model. Default is True.

- Returns

- dict
Dictionary containing values of each constraint.

`get_design_var_values`

(get_remote=True,driver_scaling=True)Return the design variable values.

- Parameters

get_remotebool or NoneIf True, retrieve the value even if it is on a remote process. Note that if the variable is remote on ANY process, this function must be called on EVERY process in the Problem’s MPI communicator. If False, only retrieve the value if it is on the current process, or only the part of the value that’s on the current process for a distributed variable.

driver_scalingboolWhen True, return values that are scaled according to either the adder and scaler or the ref and ref0 values that were specified when add_design_var, add_objective, and add_constraint were called on the model. Default is True.

- Returns

- dict
Dictionary containing values of each design variable.

`get_objective_values`

(driver_scaling=True)Return objective values.

- Parameters

driver_scalingboolWhen True, return values that are scaled according to either the adder and scaler or the ref and ref0 values that were specified when add_design_var, add_objective, and add_constraint were called on the model. Default is True.

- Returns

- dict
Dictionary containing values of each objective.

property`msginfo`

Return info to prepend to messages.

- Returns

- str
Info to prepend to messages.

`record_iteration`

()Record an iteration of the current Driver.

`run`

()[source]Optimize the problem using selected Scipy optimizer.

- Returns

- bool
Failure flag; True if failed to converge, False is successful.

`scaling_report`

(outfile='driver_scaling_report.html',title=None,show_browser=True,jac=True)Generate a self-contained html file containing a detailed connection viewer.

Optionally pops up a web browser to view the file.

- Parameters

outfilestr, optionalThe name of the output html file. Defaults to ‘driver_scaling_report.html’.

titlestr, optionalSets the title of the web page.

show_browserbool, optionalIf True, pop up a browser to view the generated html file. Defaults to True.

jacboolIf True, show jacobian information.

- Returns

- dict
Data used to create html file.

`set_design_var`

(name,value,set_remote=True)Set the value of a design variable.

- Parameters

namestrGlobal pathname of the design variable.

valuefloat or ndarrayValue for the design variable.

set_remoteboolIf True, set the global value of the variable (value must be of the global size). If False, set the local value of the variable (value must be of the local size).

`use_fixed_coloring`

(coloring=<object object>)Tell the driver to use a precomputed coloring.

- Parameters

coloringstrA coloring filename. If no arg is passed, filename will be determined automatically.

`openmdao.drivers.scipy_optimizer.`

`signature_extender`

(fcn,extra_args)[source]Closure function, which appends extra arguments to the original function call.

The first argument is the design vector. The possible extra arguments from the callback of

`scipy.optimize.minimize()`

are not passed to the function.Some algorithms take a sequence of

`NonlinearConstraint`

as input for the constraints. For this class it is not possible to pass additional arguments. With this function the signature will be correct for both scipy and the driver.

- Parameters

fcncallableFunction, which takes the design vector as the first argument.

extra_argstuple or listExtra arguments for the function.

- Returns

- callable
The function with the signature expected by the driver.