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

Attributes

fail

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

iter_count

(int) Counter for function evaluations.

result

(OptimizeResult) Result returned from scipy.optimize call.

opt_settings

(dict) Dictionary of solver-specific options. See the scipy.optimize.minimize documentation.

__init__(self, **kwargs)[source]

Initialize the ScipyOptimizeDriver.

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.

get_constraint_values(self, ctype='all', lintype='all', unscaled=False, 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’.

unscaledbool

Set to True if unscaled (physical) design variables are desired.

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, unscaled=False, 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.

unscaledbool

Set to True if unscaled (physical) design variables are desired.

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, unscaled=False, filter=None, ignore_indices=False)

Return objective values.

Parameters
unscaledbool

Set to True if unscaled (physical) design variables are desired.

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.

record_iteration(self)

Record an iteration of the current Driver.

run(self)[source]

Optimize the problem using selected Scipy optimizer.

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, simul_info)

Set the coloring (and possibly the sub-jac sparsity) for simultaneous total derivatives.

Parameters
simul_infostr or dict
# Information about simultaneous coloring for design vars and responses.  If a
# string, then simul_info is assumed to be the name of a file that contains the
# coloring information in JSON format.  If a dict, the structure looks like this:

{
"fwd": [
    # First, a list of column index lists, each index list representing columns
    # having the same color, except for the very first index list, which contains
    # indices of all columns that are not colored.
    [
        [i1, i2, i3, ...]    # list of non-colored columns
        [ia, ib, ...]    # list of columns in first color
        [ic, id, ...]    # list of columns in second color
           ...           # remaining color lists, one list of columns per color
    ],

    # Next is a list of lists, one for each column, containing the nonzero rows for
    # that column.  If a column is not colored, then it will have a None entry
    # instead of a list.
    [
        [r1, rn, ...]   # list of nonzero rows for column 0
        None,           # column 1 is not colored
        [ra, rb, ...]   # list of nonzero rows for column 2
            ...
    ],
],
# This example is not a bidirectional coloring, so the opposite direction, "rev"
# in this case, has an empty row index list.  It could also be removed entirely.
"rev": [[[]], []],
"sparsity":
    # The sparsity entry can be absent, indicating that no sparsity structure is
    # specified, or it can be 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_name: {
            dv1_name: (rows, cols, shape),  # for sub-jac d_resp1/d_dv1
            dv2_name: (rows, cols, shape),
              ...
        },
        resp2_name: {
            ...
        }
        ...
    }
}
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: {
        ...
    }
    ...
}
class openmdao.drivers.scipy_optimizer.ScipyOptimizer(**kwargs)[source]

Bases: openmdao.drivers.scipy_optimizer.ScipyOptimizeDriver

Deprecated. Use ScipyOptimizeDriver.

__init__(self, **kwargs)[source]

Initialize attributes.

Parameters
**kwargsdict

Named args.

add_recorder(self, recorder)

Add a recorder to the driver.

Parameters
recorderCaseRecorder

A recorder instance.

cleanup(self)

Clean up resources prior to exit.

get_constraint_values(self, ctype='all', lintype='all', unscaled=False, 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’.

unscaledbool

Set to True if unscaled (physical) design variables are desired.

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, unscaled=False, 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.

unscaledbool

Set to True if unscaled (physical) design variables are desired.

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, unscaled=False, filter=None, ignore_indices=False)

Return objective values.

Parameters
unscaledbool

Set to True if unscaled (physical) design variables are desired.

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.

record_iteration(self)

Record an iteration of the current Driver.

run(self)

Optimize the problem using selected Scipy optimizer.

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, simul_info)

Set the coloring (and possibly the sub-jac sparsity) for simultaneous total derivatives.

Parameters
simul_infostr or dict
# Information about simultaneous coloring for design vars and responses.  If a
# string, then simul_info is assumed to be the name of a file that contains the
# coloring information in JSON format.  If a dict, the structure looks like this:

{
"fwd": [
    # First, a list of column index lists, each index list representing columns
    # having the same color, except for the very first index list, which contains
    # indices of all columns that are not colored.
    [
        [i1, i2, i3, ...]    # list of non-colored columns
        [ia, ib, ...]    # list of columns in first color
        [ic, id, ...]    # list of columns in second color
           ...           # remaining color lists, one list of columns per color
    ],

    # Next is a list of lists, one for each column, containing the nonzero rows for
    # that column.  If a column is not colored, then it will have a None entry
    # instead of a list.
    [
        [r1, rn, ...]   # list of nonzero rows for column 0
        None,           # column 1 is not colored
        [ra, rb, ...]   # list of nonzero rows for column 2
            ...
    ],
],
# This example is not a bidirectional coloring, so the opposite direction, "rev"
# in this case, has an empty row index list.  It could also be removed entirely.
"rev": [[[]], []],
"sparsity":
    # The sparsity entry can be absent, indicating that no sparsity structure is
    # specified, or it can be 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_name: {
            dv1_name: (rows, cols, shape),  # for sub-jac d_resp1/d_dv1
            dv2_name: (rows, cols, shape),
              ...
        },
        resp2_name: {
            ...
        }
        ...
    }
}
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: {
        ...
    }
    ...
}
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
fcncallable

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

extra_argstuple or list

Extra arguments for the function

Returns
callable

The function with the signature expected by the driver.