pyoptsparse_driver.py

OpenMDAO Wrapper for pyoptsparse.

pyoptsparse is based on pyOpt, which is an object-oriented framework for formulating and solving nonlinear constrained optimization problems, with additional MPI capability.

class openmdao.drivers.pyoptsparse_driver.pyOptSparseDriver(**kwargs)[source]

Bases: openmdao.core.driver.Driver

Driver wrapper for pyoptsparse.

Pyoptsparse is based on pyOpt, which is an object-oriented framework for formulating and solving nonlinear constrained optimization problems, with additional MPI capability. pypptsparse has interfaces to the following optimizers: ALPSO, CONMIN, FSQP, IPOPT, NLPQLP, NSGA2, PSQP, SLSQP, SNOPT, NLPY_AUGLAG, NOMAD. Note that some of these are not open source and therefore not included in the pyoptsparse source code.

pyOptSparseDriver supports the following:

equality_constraints

inequality_constraints

two_sided_constraints

Attributes

fail

(bool) Flag that indicates failure of most recent optimization.

hist_file

(str or None) File location for saving pyopt_sparse optimization history. Default is None for no output.

hotstart_file

(str) Optional file to hot start the optimization.

opt_settings

(dict) Dictionary for setting optimizer-specific options.

pyopt_solution

(Solution) Pyopt_sparse solution object.

__init__(self, **kwargs)[source]

Initialize pyopt.

Parameters
**kwargsdict of keyword arguments

Keyword arguments that will be mapped into the Driver options.

add_recorder(self, recorder)

Add a recorder to the driver.

Parameters
recorderCaseRecorder

A recorder instance.

cleanup(self)

Clean up resources prior to exit.

declare_coloring(self, num_full_jacs=3, tol=1e-25, orders=None, perturb_size=1e-09, show_summary=True, show_sparsity=False)

Set options for total deriv coloring.

Parameters
num_full_jacsint

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

tolfloat

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

ordersint

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

perturb_sizefloat

Size of input/output perturbation during generation of sparsity.

show_summarybool

If True, display summary information after generating coloring.

show_sparsitybool

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

get_constraint_values(self, ctype='all', lintype='all', driver_scaling=True, filter=None, ignore_indices=False)

Return constraint values.

Parameters
ctypestring

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

lintypestring

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

driver_scalingbool

When 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.

filterlist

List of constraint names used by recorders.

ignore_indicesbool

Set to True if the full array is desired, not just those indicated by indices.

Returns
dict

Dictionary containing values of each constraint.

get_design_var_values(self, filter=None, driver_scaling=True, ignore_indices=False)

Return the design variable values.

This is called to gather the initial design variable state.

Parameters
filterlist

List of desvar names used by recorders.

driver_scalingbool

When 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.

ignore_indicesbool

Set to True if the full array is desired, not just those indicated by indices.

Returns
dict

Dictionary containing values of each design variable.

get_objective_values(self, driver_scaling=True, filter=None, ignore_indices=False)

Return objective values.

Parameters
driver_scalingbool

When 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.

filterlist

List of objective names used by recorders.

ignore_indicesbool

Set to True if the full array is desired, not just those indicated by indices.

Returns
dict

Dictionary containing values of each objective.

get_response_values(self, filter=None)

Return response values.

Parameters
filterlist

List of response names used by recorders.

Returns
dict

Dictionary containing values of each response.

property msginfo

Return info to prepend to messages.

Returns
str

Info to prepend to messages.

record_iteration(self)

Record an iteration of the current Driver.

run(self)[source]

Excute pyOptsparse.

Note that pyOpt controls the execution, and the individual optimizers (e.g., SNOPT) control the iteration.

Returns
boolean

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

set_design_var(self, name, value)

Set the value of a design variable.

Parameters
namestr

Global pathname of the design variable.

valuefloat or ndarray

Value for the design variable.

set_simul_deriv_color(self, coloring)

See use_fixed_coloring. This method is deprecated.

Parameters
coloringstr or Coloring

Information about simultaneous coloring for design vars and responses. If a string, then coloring is assumed to be the name of a file that contains the coloring information in pickle format. Otherwise it must be a Coloring object. See the docstring for Coloring for details.

set_total_jac_sparsity(self, sparsity)

Set the sparsity of sub-jacobians of the total jacobian.

Note: This currently will have no effect if you are not using the pyOptSparseDriver.

Parameters
sparsitystr or dict
# Sparsity is a nested dictionary where the outer keys are response
# names, the inner keys are design variable names, and the value is a tuple of
# the form (row_list, col_list, shape).
{
    resp1: {
        dv1: (rows, cols, shape),  # for sub-jac d_resp1/d_dv1
        dv2: (rows, cols, shape),
          ...
    },
    resp2: {
        ...
    }
    ...
}
use_fixed_coloring(self, coloring=<object object at 0x7f640240aad0>)

Tell the driver to use a precomputed coloring.

Parameters
coloringstr

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