driver.py

Define a base class for all Drivers in OpenMDAO.

class openmdao.core.driver.Driver(**kwargs)[source]

Bases: object

Top-level container for the systems and drivers.

Attributes

fail (bool) Reports whether the driver ran successfully.
iter_count (int) Keep track of iterations for case recording.
options (<OptionsDictionary>) Dictionary with general pyoptsparse options.
recording_options (<OptionsDictionary>) Dictionary with driver recording options.
debug_print (<OptionsDictionary>) Dictionary with debugging printing options.
cite (str) Listing of relevant citataions that should be referenced when publishing work that uses this class.
supports (<OptionsDictionary>) Provides a consistant way for drivers to declare what features they support.
__init__(**kwargs)[source]

Initialize the driver.

Parameters:
**kwargs : dict of keyword arguments

Keyword arguments that will be mapped into the Driver options.

add_recorder(recorder)[source]

Add a recorder to the driver.

Parameters:
recorder : BaseRecorder

A recorder instance.

cleanup()[source]

Clean up resources prior to exit.

get_constraint_values(ctype='all', lintype='all', unscaled=False, filter=None)[source]

Return constraint values.

Parameters:
ctype : string

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

lintype : string

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

unscaled : bool

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

filter : list

List of constraint names used by recorders.

Returns:
dict

Dictionary containing values of each constraint.

get_design_var_values(filter=None, unscaled=False, ignore_indices=False)[source]

Return the design variable values.

This is called to gather the initial design variable state.

Parameters:
filter : list

List of desvar names used by recorders.

unscaled : bool

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

ignore_indices : bool

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(unscaled=False, filter=None)[source]

Return objective values.

Parameters:
unscaled : bool

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

filter : list

List of objective names used by recorders.

Returns:
dict

Dictionary containing values of each objective.

get_response_values(filter=None)[source]

Return response values.

Parameters:
filter : list

List of response names used by recorders.

Returns:
dict

Dictionary containing values of each response.

record_iteration()[source]

Record an iteration of the current Driver.

run()[source]

Execute this driver.

The base Driver just runs the model. All other drivers overload this method.

Returns:
boolean

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

set_design_var(name, value)[source]

Set the value of a design variable.

Parameters:
name : str

Global pathname of the design variable.

value : float or ndarray

Value for the design variable.

set_simul_deriv_color(simul_info)[source]

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

Parameters:
simul_info : str or tuple
# 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 tuple, the structure looks like this:

(
    # 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
            ...
    ],

    # The last tuple entry can be None, 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(sparsity)[source]

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:
sparsity : str 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.core.driver.RecordingDebugging(name, iter_count, recording_requester)[source]

Bases: openmdao.recorders.recording_iteration_stack.Recording

A class that acts as a context manager.

Handles doing the case recording and also the Driver debugging printing.

__init__(name, iter_count, recording_requester)

Initialize Recording.

Parameters:
name : str

Name of object getting recorded.

iter_count : int

Current counter of iterations completed.

recording_requester : object

The object that wants to be recorded.