driver.py

Base class for Driver.

class openmdao.core.driver.Driver[source]

Bases: object

Base class for drivers in OpenMDAO. Drivers can only be placed in a Problem, and every problem has a Driver. Driver is the simplest driver that runs (solves using solve_nonlinear) a problem once.

add_constraint(name, lower=None, upper=None, equals=None, linear=False, jacs=None, indices=None, adder=0.0, scaler=1.0)[source]

Adds a constraint to this driver. For inequality constraints, lower or upper must be specified. For equality constraints, equals must be specified.

Args:

name : string

Promoted pathname of the output that will serve as the quantity to constrain.

lower : float or ndarray, optional

Constrain the quantity to be greater than this value.

upper : float or ndarray, optional

Constrain the quantity to be less than this value.

equals : float or ndarray, optional

Constrain the quantity to be equal to this value.

linear : bool, optional

Set to True if this constraint is linear with respect to all design variables so that it can be calculated once and cached.

jacs : dict of functions, optional

Dictionary of user-defined functions that return the flattened Jacobian of this constraint with repsect to the design vars of this driver, as indicated by the dictionary keys. Default is None to let OpenMDAO calculate all derivatives. Note, this is currently unsupported

indices : iter of int, optional

If a constraint is an array, these indicate which entries are of interest for derivatives.

adder : float or ndarray, optional

Value to add to the model value to get the scaled value. Adder is first in precedence.

scaler : float or ndarray, optional

value to multiply the model value to get the scaled value. Scaler is second in precedence.

add_desvar(name, low=None, high=None, indices=None, adder=0.0, scaler=1.0)[source]

Adds a parameter to this driver.

Args:

name : string

Name of the IndepVarComp in the root system.

low : float or ndarray, optional

Lower boundary for the param

high : upper or ndarray, optional

Lower boundary for the param

indices : iter of int, optional

If a param is an array, these indicate which entries are of interest for derivatives.

adder : float or ndarray, optional

Value to add to the model value to get the scaled value. Adder is first in precedence.

scaler : float or ndarray, optional

value to multiply the model value to get the scaled value. Scaler is second in precedence.

add_objective(name, indices=None, adder=0.0, scaler=1.0)[source]

Adds an objective to this driver.

Args:

name : string

Promoted pathname of the output that will serve as the objective.

indices : iter of int, optional

If an objective is an array, these indicate which entries are of interest for derivatives.

adder : float or ndarray, optional

Value to add to the model value to get the scaled value. Adder is first in precedence.

scaler : float or ndarray, optional

value to multiply the model value to get the scaled value. Scaler is second in precedence.

add_param(name, low=None, high=None, indices=None, adder=0.0, scaler=1.0)[source]

Deprecated. Use add_desvar instead.

add_recorder(recorder)[source]

Adds a recorder to the driver.

Args:

recorder : BaseRecorder

A recorder instance.

calc_gradient(indep_list, unknown_list, mode='auto', return_format='array', sparsity=None)[source]

Returns the scaled gradient for the system that is slotted in self.root, scaled by all scalers that were specified when the desvars and constraints were added.

Args:

indep_list : list of strings

List of independent variable names that derivatives are to be calculated with respect to. All params must have a IndepVarComp.

unknown_list : list of strings

List of output or state names that derivatives are to be calculated for. All must be valid unknowns in OpenMDAO.

mode : string, optional

Deriviative direction, can be ‘fwd’, ‘rev’, ‘fd’, or ‘auto’. Default is ‘auto’, which uses mode specified on the linear solver in root.

return_format : string, optional

Format for the derivatives, can be ‘array’ or ‘dict’.

sparsity : dict, optional

Dictionary that gives the relevant design variables for each constraint. This option is only supported in the dict return format.

Returns:

ndarray or dict

Jacobian of unknowns with respect to params.

desvars_of_interest()[source]
Returns:

list of tuples of str

The list of design vars, organized into tuples according to previously defined VOI groups.

generate_docstring()[source]

Generates a numpy-style docstring for a user-created Driver class.

Returns:

docstring : str

string that contains a basic numpy docstring.

get_constraint_metadata()[source]

Returns a dict of constraint metadata.

Returns:

dict

Keys are the constraint object names, and the values are the param values.

get_constraints(ctype='all', lintype='all')[source]

Gets all constraints for this driver.

Args:

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

Returns:

dict

Key is the constraint name string, value is an ndarray with the values.

get_desvar_metadata()[source]

Returns a dict of parameter metadata.

Returns:

dict

Keys are the param object names, and the values are the param values.

get_desvars()[source]

Returns a dict of possibly distributed parameters.

Returns:

dict

Keys are the param object names, and the values are the param values.

get_objectives(return_type='dict')[source]

Gets all objectives of this driver.

Args:

return_type : string

Set to ‘dict’ to return a dictionary, or set to ‘array’ to return a flat ndarray.

Returns:

dict (for return_type ‘dict’)

Key is the objective name string, value is an ndarray with the values.

ndarray (for return_type ‘array’)

Array containing all objective values in the order they were added.

outputs_of_interest()[source]
Returns:

list of tuples of str

The list of constraints and objectives, organized into tuples according to previously defined VOI groups.

parallel_derivs(vnames)[source]

Specifies that the named variables of interest are to be grouped together so that their derivatives can be solved for concurrently.

Args:

vnames : iter of str

The names of variables of interest that are to be grouped.

run(problem)[source]

Runs the driver. This function should be overriden when inheriting.

Args:

problem : Problem

Our parent Problem.

set_desvar(name, value)[source]

Sets a parameter.

Args:

name : string

Name of the IndepVarComp in the root system.

val : ndarray or float

value to set the parameter