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, active_tol=None)[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 or equal to this value.

upper : float or ndarray, optional

Constrain the quantity to be less than or equal to 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.

active_tol : float or ndarray, optional

Tolerance for determining if a constraint is active, and whether to calculate a gradient if the optimizer supports it.

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

Adds a design variable to this driver.

Args:

name : string

Name of the design variable in the root system.

lower : float or ndarray, optional

Lower boundary for the param

upper : upper or ndarray, optional

Upper 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, lower=None, upper=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, inactives=None)[source]

Returns the scaled gradient for the system that is contained 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.

inactives : dict, optional

Dictionary of all inactive constraints. Gradient calculation is skipped for these in adjoine mode. Key is the constraint name, and value is the indices that are inactive.

Returns:

ndarray or dict

Jacobian of unknowns with respect to params.

cleanup()[source]

Clean up resources prior to exit.

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 design variable 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 design variables.

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.

get_req_procs()[source]
Returns:

tuple

A tuple of the form (min_procs, max_procs), indicating the min and max processors usable by this Driver.

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 overridden when inheriting.

Args:

problem : Problem

Our parent Problem.

run_once(problem)[source]

Runs root’s solve_nonlinear one time

Args:

problem : Problem

Our parent Problem.

set_desvar(name, value, index=None)[source]

Sets a design variable.

Args:

name : string

Name of the design variable in the root system.

val : ndarray or float

value to assign to the design variable.

index : integer, optional

Index of the desvar to set.

set_root(pathname, root)[source]

Sets the root Group of this driver.

Args:

root : Group

Our root Group.