# exec_comp.py¶

Define the ExecComp class, a component that evaluates an expression.

class`openmdao.components.exec_comp.`

`ExecComp`

(exprs=[],**kwargs)[source]Bases:

`openmdao.core.explicitcomponent.ExplicitComponent`

A component defined by an expression string.

- Parameters

exprsstr, tuple of str or list of strAn assignment statement or iter of them. These express how the outputs are calculated based on the inputs. In addition to standard Python operators, a subset of numpy and scipy functions is supported.

**kwargsdict of named argsInitial values of variables can be set by setting a named arg with the var name. If the value is a dict it is assumed to contain metadata. To set the initial value in addition to other metadata, assign the initial value to the ‘val’ entry of the dict.

- Attributes

_kwargsdict of named argsInitial values of variables.

_exprslistList of expressions.

_codeslistList of code objects.

_exprs_infolistList of tuples containing output and inputs for each expression.

_has_diag_partialsboolIf True, treat all array/array partials as diagonal if both arrays have size > 1. All arrays with size > 1 must have the same flattened size or an exception will be raised.

_unitsstr or NoneUnits to be assigned to all variables in this component. Default is None, which means units are provided for variables individually.

complex_stepsizedoubleStep size used for complex step which is used for derivatives.

_manual_decl_partialsboolIf True, at least one partial has been declared by the user.

_requires_fddictContains a mapping of ‘of’ variables to a tuple of the form (wrts, functs) for those ‘of’ variables that require finite difference to be used to compute their derivatives.

`__init__`

(exprs=[],**kwargs)[source]Create a <Component> using only an expression string.

Given a list of assignment statements, this component creates input and output variables at construction time. All variables appearing on the left-hand side of an assignment are outputs, and the rest are inputs. Each variable is assumed to be of type float unless the initial value for that variable is supplied in **kwargs. Derivatives are calculated using complex step.

The following functions are available for use in expressions:

Function

Description

abs(x)

Absolute value of x

acos(x)

Inverse cosine of x

acosh(x)

Inverse hyperbolic cosine of x

arange(start, stop, step)

Array creation

arccos(x)

Inverse cosine of x

arccosh(x)

Inverse hyperbolic cosine of x

arcsin(x)

Inverse sine of x

arcsinh(x)

Inverse hyperbolic sine of x

arctan(x)

Inverse tangent of x

arctan2(y, x)

4-quadrant arctangent function of y and x

asin(x)

Inverse sine of x

asinh(x)

Inverse hyperbolic sine of x

atan(x)

Inverse tangent of x

cos(x)

Cosine of x

cosh(x)

Hyperbolic cosine of x

dot(x, y)

Dot product of x and y

e

Euler’s number

erf(x)

Error function

erfc(x)

Complementary error function

exp(x)

Exponential function

expm1(x)

exp(x) - 1

factorial(x)

Factorial of all numbers in x (DEPRECATED, not available with SciPy >=1.5)

fmax(x, y)

Element-wise maximum of x and y

fmin(x, y)

Element-wise minimum of x and y

inner(x, y)

Inner product of arrays x and y

isinf(x)

Element-wise detection of np.inf

isnan(x)

Element-wise detection of np.nan

kron(x, y)

Kronecker product of arrays x and y

linspace(x, y, N)

Numpy linear spaced array creation

log(x)

Natural logarithm of x

log10(x)

Base-10 logarithm of x

log1p(x)

log(1+x)

matmul(x, y)

Matrix multiplication of x and y

maximum(x, y)

Element-wise maximum of x and y

minimum(x, y)

Element-wise minimum of x and y

ones(N)

Create an array of ones

outer(x, y)

Outer product of x and y

pi

Pi

power(x, y)

Element-wise x**y

prod(x)

The product of all elements in x

sin(x)

Sine of x

sinh(x)

Hyperbolic sine of x

sum(x)

The sum of all elements in x

tan(x)

Tangent of x

tanh(x)

Hyperbolic tangent of x

tensordot(x, y)

Tensor dot product of x and y

zeros(N)

Create an array of zeros

Notes

If a variable has an initial value that is anything other than 1.0, either because it has a different type than float or just because its initial value is != 1.0, you must use a keyword arg to set the initial value. For example, let’s say we have an ExecComp that takes an array ‘x’ as input and outputs a float variable ‘y’ which is the sum of the entries in ‘x’.

import numpy import openmdao.api as om excomp = om.ExecComp('y=sum(x)', x=numpy.ones(10, dtype=float))In this example, ‘y’ would be assumed to be the default type of float and would be given the default initial value of 1.0, while ‘x’ would be initialized with a size 10 float array of ones.

If you want to assign certain metadata for ‘x’ in addition to its initial value, you can do it as follows:

excomp = ExecComp('y=sum(x)', x={'val': numpy.ones(10, dtype=float), 'units': 'ft'})

`abs_name_iter`

(iotype,local=True,cont=True,discrete=False)Iterate over absolute variable names for this System.

By setting appropriate values for ‘cont’ and ‘discrete’, yielded variable names can be continuous only, discrete only, or both.

- Parameters

iotypestrEither ‘input’ or ‘output’.

localboolIf True, include only names of local variables. Default is True.

contboolIf True, include names of continuous variables. Default is True.

discreteboolIf True, include names of discrete variables. Default is False.

- Yields

- str

`add_constraint`

(name,lower=None,upper=None,equals=None,ref=None,ref0=None,adder=None,scaler=None,units=None,indices=None,linear=False,parallel_deriv_color=None,cache_linear_solution=False,flat_indices=False)Add a constraint variable to this system.

- Parameters

namestrName of the response variable in the system.

lowerfloat or ndarray, optionalLower boundary for the variable.

upperfloat or ndarray, optionalUpper boundary for the variable.

equalsfloat or ndarray, optionalEquality constraint value for the variable.

reffloat or ndarray, optionalValue of response variable that scales to 1.0 in the driver.

ref0float or ndarray, optionalValue of response variable that scales to 0.0 in the driver.

adderfloat or ndarray, optionalValue to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.

scalerfloat or ndarray, optionalValue to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.

unitsstr, optionalUnits to convert to before applying scaling.

indicessequence of int, optionalIf variable is an array, these indicate which entries are of interest for this particular response. These may be positive or negative integers.

linearboolSet to True if constraint is linear. Default is False.

parallel_deriv_colorstrIf specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.

cache_linear_solutionboolIf True, store the linear solution vectors for this variable so they can be used to start the next linear solution with an initial guess equal to the solution from the previous linear solve.

flat_indicesboolIf True, interpret specified indices as being indices into a flat source array.

Notes

The response can be scaled using ref and ref0. The argument

`ref0`

represents the physical value when the scaled value is 0. The argument`ref`

represents the physical value when the scaled value is 1. The arguments (`lower`

,`upper`

,`equals`

) can not be strings or variable names.

`add_design_var`

(name,lower=None,upper=None,ref=None,ref0=None,indices=None,adder=None,scaler=None,units=None,parallel_deriv_color=None,cache_linear_solution=False,flat_indices=False)Add a design variable to this system.

- Parameters

namestrName of the design variable in the system.

lowerfloat or ndarray, optionalLower boundary for the input.

upperupper or ndarray, optionalUpper boundary for the input.

reffloat or ndarray, optionalValue of design var that scales to 1.0 in the driver.

ref0float or ndarray, optionalValue of design var that scales to 0.0 in the driver.

indicesiter of int, optionalIf an input is an array, these indicate which entries are of interest for this particular design variable. These may be positive or negative integers.

adderfloat or ndarray, optionalValue to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.

scalerfloat or ndarray, optionalValue to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.

unitsstr, optionalUnits to convert to before applying scaling.

parallel_deriv_colorstrIf specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.

cache_linear_solutionboolIf True, store the linear solution vectors for this variable so they can be used to start the next linear solution with an initial guess equal to the solution from the previous linear solve.

flat_indicesboolIf True, interpret specified indices as being indices into a flat source array.

Notes

The response can be scaled using ref and ref0. The argument

`ref0`

represents the physical value when the scaled value is 0. The argument`ref`

represents the physical value when the scaled value is 1.

`add_discrete_input`

(name,val,desc='',tags=None)Add a discrete input variable to the component.

- Parameters

namestrName of the variable in this component’s namespace.

vala picklable objectThe initial value of the variable being added.

descstrDescription of the variable.

tagsstr or list of strsUser defined tags that can be used to filter what gets listed when calling list_inputs and list_outputs.

- Returns

- dict
Metadata for added variable.

`add_discrete_output`

(name,val,desc='',tags=None)Add an output variable to the component.

- Parameters

namestrName of the variable in this component’s namespace.

vala picklable objectThe initial value of the variable being added.

descstrDescription of the variable.

tagsstr or list of strs or set of strsUser defined tags that can be used to filter what gets listed when calling list_inputs and list_outputs.

- Returns

- dict
Metadata for added variable.

`add_expr`

(expr,**kwargs)[source]Add an expression to the ExecComp.

- Parameters

exprstrAn assignment statement that expresses how the outputs are calculated based on the inputs. In addition to standard Python operators, a subset of numpy and scipy functions is supported.

**kwargsdict of named argsInitial values of variables can be set by setting a named arg with the var name. If the value is a dict it is assumed to contain metadata. To set the initial value in addition to other metadata, assign the initial value to the ‘val’ entry of the dict. Do not include for inputs whose default kwargs have been declared on previous expressions.

`add_input`

(name,val=1.0,shape=None,src_indices=None,flat_src_indices=None,units=None,desc='',tags=None,shape_by_conn=False,copy_shape=None,distributed=None)Add an input variable to the component.

- Parameters

namestrName of the variable in this component’s namespace.

valfloat or list or tuple or ndarray or IterableThe initial value of the variable being added in user-defined units. Default is 1.0.

shapeint or tuple or list or NoneShape of this variable, only required if src_indices not provided and val is not an array. Default is None.

src_indicesint or list or tuple or int ndarray or Iterable or NoneThe global indices of the source variable to transfer data from. A value of None implies this input depends on all entries of the source array. Default is None. The shapes of the target and src_indices must match, and the form of the entries within is determined by the value of ‘flat_src_indices’.

flat_src_indicesboolIf True and the source is non-flat, each entry of src_indices is assumed to be an index into the flattened source. Ignored if the source is flat.

unitsstr or NoneUnits in which this input variable will be provided to the component during execution. Default is None, which means it is unitless.

descstrDescription of the variable.

tagsstr or list of strsUser defined tags that can be used to filter what gets listed when calling list_inputs and list_outputs.

shape_by_connboolIf True, shape this input to match its connected output.

copy_shapestr or NoneIf a str, that str is the name of a variable. Shape this input to match that of the named variable.

distributedboolIf True, this variable is a distributed variable, so it can have different sizes/values across MPI processes.

- Returns

- dict
Metadata for added variable.

`add_objective`

(name,ref=None,ref0=None,index=None,units=None,adder=None,scaler=None,parallel_deriv_color=None,cache_linear_solution=False,flat_indices=False)Add a response variable to this system.

- Parameters

namestrName of the response variable in the system.

reffloat or ndarray, optionalValue of response variable that scales to 1.0 in the driver.

ref0float or ndarray, optionalValue of response variable that scales to 0.0 in the driver.

indexint, optionalIf variable is an array, this indicates which entry is of interest for this particular response. This may be a positive or negative integer.

unitsstr, optionalUnits to convert to before applying scaling.

adderfloat or ndarray, optionalValue to add to the model value to get the scaled value for the driver. adder is first in precedence. adder and scaler are an alterantive to using ref and ref0.

scalerfloat or ndarray, optionalValue to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alterantive to using ref and ref0.

parallel_deriv_colorstrIf specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.

cache_linear_solutionboolIf True, store the linear solution vectors for this variable so they can be used to start the next linear solution with an initial guess equal to the solution from the previous linear solve.

flat_indicesboolIf True, interpret specified indices as being indices into a flat source array.

Notes

The objective can be scaled using scaler and adder, where

\[x_{scaled} = scaler(x + adder)\]or through the use of ref/ref0, which map to scaler and adder through the equations:

\[ \begin{align}\begin{aligned}0 = scaler(ref_0 + adder)\\1 = scaler(ref + adder)\end{aligned}\end{align} \]which results in:

\[ \begin{align}\begin{aligned}adder = -ref_0\\scaler = \frac{1}{ref + adder}\end{aligned}\end{align} \]

`add_output`

(name,val=1.0,shape=None,units=None,res_units=None,desc='',lower=None,upper=None,ref=1.0,ref0=0.0,res_ref=None,tags=None,shape_by_conn=False,copy_shape=None,distributed=None)Add an output variable to the component.

For ExplicitComponent, res_ref defaults to the value in res unless otherwise specified.

- Parameters

namestrName of the variable in this component’s namespace.

valfloat or list or tuple or ndarrayThe initial value of the variable being added in user-defined units. Default is 1.0.

shapeint or tuple or list or NoneShape of this variable, only required if val is not an array. Default is None.

unitsstr or NoneUnits in which the output variables will be provided to the component during execution. Default is None, which means it has no units.

res_unitsstr or NoneUnits in which the residuals of this output will be given to the user when requested. Default is None, which means it has no units.

descstrDescription of the variable.

lowerfloat or list or tuple or ndarray or NoneLower bound(s) in user-defined units. It can be (1) a float, (2) an array_like consistent with the shape arg (if given), or (3) an array_like matching the shape of val, if val is array_like. A value of None means this output has no lower bound. Default is None.

upperfloat or list or tuple or ndarray or NoneUpper bound(s) in user-defined units. It can be (1) a float, (2) an array_like consistent with the shape arg (if given), or (3) an array_like matching the shape of val, if val is array_like. A value of None means this output has no upper bound. Default is None.

reffloatScaling parameter. The value in the user-defined units of this output variable when the scaled value is 1. Default is 1.

ref0floatScaling parameter. The value in the user-defined units of this output variable when the scaled value is 0. Default is 0.

res_reffloatScaling parameter. The value in the user-defined res_units of this output’s residual when the scaled value is 1. Default is None, which means residual scaling matches output scaling.

tagsstr or list of strsUser defined tags that can be used to filter what gets listed when calling list_inputs and list_outputs and also when listing results from case recorders.

shape_by_connboolIf True, shape this output to match its connected input(s).

copy_shapestr or NoneIf a str, that str is the name of a variable. Shape this output to match that of the named variable.

distributedboolIf True, this variable is a distributed variable, so it can have different sizes/values across MPI processes.

- Returns

- dict
Metadata for added variable.

`add_recorder`

(recorder,recurse=False)Add a recorder to the system.

- Parameters

recorder<CaseRecorder>A recorder instance.

recurseboolFlag indicating if the recorder should be added to all the subsystems.

`add_response`

(name,type_,lower=None,upper=None,equals=None,ref=None,ref0=None,indices=None,index=None,units=None,adder=None,scaler=None,linear=False,parallel_deriv_color=None,cache_linear_solution=False,flat_indices=None)Add a response variable to this system.

The response can be scaled using ref and ref0. The argument

`ref0`

represents the physical value when the scaled value is 0. The argument`ref`

represents the physical value when the scaled value is 1.

- Parameters

namestrName of the response variable in the system.

type_strThe type of response. Supported values are ‘con’ and ‘obj’.

lowerfloat or ndarray, optionalLower boundary for the variable.

upperupper or ndarray, optionalUpper boundary for the variable.

equalsequals or ndarray, optionalEquality constraint value for the variable.

reffloat or ndarray, optionalValue of response variable that scales to 1.0 in the driver.

ref0upper or ndarray, optionalValue of response variable that scales to 0.0 in the driver.

indicessequence of int, optionalIf variable is an array, these indicate which entries are of interest for this particular response.

indexint, optionalIf variable is an array, this indicates which entry is of interest for this particular response.

unitsstr, optionalUnits to convert to before applying scaling.

adderfloat or ndarray, optionalscalerfloat or ndarray, optionallinearboolSet to True if constraint is linear. Default is False.

parallel_deriv_colorstrcache_linear_solutionboolflat_indicesboolIf True, interpret specified indices as being indices into a flat source array.

`all_connected_nodes`

(graph,start,local=False)Yield all downstream nodes starting at the given node.

- Parameters

graphnetwork.DiGraphGraph being traversed.

starthashable objectIdentifier of the starting node.

localboolIf True and a non-local node is encountered in the traversal, the traversal ends on that branch.

- Yields

- str
Each node found when traversal starts at start.

`check_config`

(logger)Perform optional error checks.

- Parameters

loggerobjectThe object that manages logging output.

`cleanup`

()Clean up resources prior to exit.

`compute`

(inputs,outputs)[source]Execute this component’s assignment statements.

- Parameters

inputsVectorVector containing inputs.

outputsVectorVector containing outputs.

`compute_jacvec_product`

(inputs,d_inputs,d_outputs,mode,discrete_inputs=None)Compute jac-vector product. The model is assumed to be in an unscaled state.

- If mode is:
‘fwd’: d_inputs |-> d_outputs

‘rev’: d_outputs |-> d_inputs

- Parameters

inputsVectorUnscaled, dimensional input variables read via inputs[key].

d_inputsVectorSee inputs; product must be computed only if var_name in d_inputs.

d_outputsVectorSee outputs; product must be computed only if var_name in d_outputs.

modestrEither ‘fwd’ or ‘rev’.

discrete_inputsdict or NoneIf not None, dict containing discrete input values.

`compute_partials`

(inputs,partials)[source]Use complex step method to update the given Jacobian.

- Parameters

inputsVecWrapperVecWrapper containing parameters (p).

partialsJacobianContains sub-jacobians.

`convert2units`

(name,val,units)Convert the given value to the specified units.

- Parameters

namestrName of the variable.

valfloat or ndarray of floatThe value of the variable.

unitsstrThe units to convert to.

- Returns

- float or ndarray of float
The value converted to the specified units.

`convert_from_units`

(name,val,units)Convert the given value from the specified units to those of the named variable.

- Parameters

namestrName of the variable.

valfloat or ndarray of floatThe value of the variable.

unitsstrThe units to convert to.

- Returns

- float or ndarray of float
The value converted to the specified units.

`convert_units`

(name,val,units_from,units_to)Wrap the utility convert_units and give a good error message.

- Parameters

namestrName of the variable.

valfloat or ndarray of floatThe value of the variable.

units_fromstrThe units to convert from.

units_tostrThe units to convert to.

- Returns

- float or ndarray of float
The value converted to the specified units.

`declare_coloring`

(wrt=('*'),method='fd',form=None,step=None,per_instance=True,num_full_jacs=3,tol=1e-25,orders=None,perturb_size=1e-09,min_improve_pct=5.0,show_summary=True,show_sparsity=False)Set options for deriv coloring of a set of wrt vars matching the given pattern(s).

- Parameters

wrtstr or list of strThe name or names of the variables that derivatives are taken with respect to. This can contain input names, output names, or glob patterns.

methodstrMethod used to compute derivative: “fd” for finite difference, “cs” for complex step.

formstrFinite difference form, can be “forward”, “central”, or “backward”. Leave undeclared to keep unchanged from previous or default value.

stepfloatStep size for finite difference. Leave undeclared to keep unchanged from previous or default value.

per_instanceboolIf True, a separate coloring will be generated for each instance of a given class. Otherwise, only one coloring for a given class will be generated and all instances of that class will use it.

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

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

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

perturb_sizefloatSize of input/output perturbation during generation of sparsity.

min_improve_pctfloatIf coloring does not improve (decrease) the number of solves more than the given percentage, coloring will not be used.

show_summaryboolIf True, display summary information after generating coloring.

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

`declare_partials`

(*args,**kwargs)[source]Declare information about this component’s subjacobians.

- Parameters

*argslistPositional args to be passed to base class version of declare_partials.

**kwargsdictKeyword args to be passed to base class version of declare_partials.

- Returns

- dict
Metadata dict for the specified partial(s).

`get_approx_coloring_fname`

()Return the full pathname to a coloring file.

- Returns

- str
Full pathname of the coloring file.

`get_constraints`

(recurse=True)Get the Constraint settings from this system.

Retrieve the constraint settings for the current system as a dict, keyed by variable name.

- Parameters

recursebool, optionalIf True, recurse through the subsystems and return the path of all constraints relative to the this system.

- Returns

- dict
The constraints defined in the current system.

`get_design_vars`

(recurse=True,get_sizes=True,use_prom_ivc=True)Get the DesignVariable settings from this system.

Retrieve all design variable settings from the system and, if recurse is True, all of its subsystems.

- Parameters

recurseboolIf True, recurse through the subsystems and return the path of all design vars relative to the this system.

get_sizesbool, optionalIf True, compute the size of each design variable.

use_prom_ivcboolTranslate auto_ivc_names to their promoted input names.

- Returns

- dict
The design variables defined in the current system and, if recurse=True, its subsystems.

`get_io_metadata`

(iotypes=('input', 'output'),metadata_keys=None,includes=None,excludes=None,tags=(),get_remote=False,rank=None,return_rel_names=True)Retrieve metdata for a filtered list of variables.

- Parameters

iotypesstr or iter of strWill contain either ‘input’, ‘output’, or both. Defaults to both.

metadata_keysiter of str or NoneNames of metadata entries to be retrieved or None, meaning retrieve all available ‘allprocs’ metadata. If ‘val’ or ‘src_indices’ are required, their keys must be provided explicitly since they are not found in the ‘allprocs’ metadata and must be retrieved from local metadata located in each process.

includesstr, iter of str or NoneCollection of glob patterns for pathnames of variables to include. Default is None, which includes all variables.

excludesstr, iter of str or NoneCollection of glob patterns for pathnames of variables to exclude. Default is None.

tagsstr or iter of strsUser defined tags that can be used to filter what gets listed. Only inputs with the given tags will be listed. Default is None, which means there will be no filtering based on tags.

get_remoteboolIf True, retrieve variables from other MPI processes as well.

rankint or NoneIf None, and get_remote is True, retrieve values from all MPI process to all other MPI processes. Otherwise, if get_remote is True, retrieve values from all MPI processes only to the specified rank.

return_rel_namesboolIf True, the names returned will be relative to the scope of this System. Otherwise they will be absolute names.

- Returns

- dict
A dict of metadata keyed on name, where name is either absolute or relative based on the value of the return_rel_names arg, and metadata is a dict containing entries based on the value of the metadata_keys arg. Every metadata dict will always contain two entries, ‘promoted_name’ and ‘discrete’, to indicate a given variable’s promoted name and whether or not it is discrete.

`get_linear_vectors`

()Return the linear inputs, outputs, and residuals vectors.

- Returns

- (inputs, outputs, residuals): tuple of <Vector> instances
Yields the linear inputs, outputs, and residuals vectors.

`get_nonlinear_vectors`

()Return the inputs, outputs, and residuals vectors.

- Returns

- (inputs, outputs, residuals)
Yields the inputs, outputs, and residuals nonlinear vectors.

`get_objectives`

(recurse=True)Get the Objective settings from this system.

Retrieve all objectives settings from the system as a dict, keyed by variable name.

- Parameters

recursebool, optionalIf True, recurse through the subsystems and return the path of all objective relative to the this system.

- Returns

- dict
The objectives defined in the current system.

`get_relevant_vars`

(desvars,responses,mode)Find all relevant vars between desvars and responses.

Both vars are assumed to be outputs (either design vars or responses).

- Parameters

desvarsdictDictionary of design variable metadata.

responsesdictDictionary of response variable metadata.

modestrDirection of derivatives, either ‘fwd’ or ‘rev’.

- Returns

- dict
Dict of ({‘outputs’: dep_outputs, ‘inputs’: dep_inputs}, dep_systems) keyed by design vars and responses.

`get_responses`

(recurse=True,get_sizes=True,use_prom_ivc=False)Get the response variable settings from this system.

Retrieve all response variable settings from the system as a dict, keyed by variable name.

- Parameters

recursebool, optionalIf True, recurse through the subsystems and return the path of all responses relative to the this system.

get_sizesbool, optionalIf True, compute the size of each response.

use_prom_ivcboolTranslate auto_ivc_names to their promoted input names.

- Returns

- dict
The responses defined in the current system and, if recurse=True, its subsystems.

`get_source`

(name)Return the source variable connected to the given named variable.

The name can be a promoted name or an absolute name. If the given variable is an input, the absolute name of the connected source will be returned. If the given variable itself is a source, its own absolute name will be returned.

- Parameters

namestrAbsolute or promoted name of the variable.

- Returns

- str
The absolute name of the source variable.

`get_val`

(name,units=None,indices=None,get_remote=False,rank=None,vec_name='nonlinear',kind=None,flat=False,from_src=True)Get an output/input/residual variable.

Function is used if you want to specify display units.

- Parameters

namestrPromoted or relative variable name in the root system’s namespace.

unitsstr, optionalUnits to convert to before return.

indicesint or list of ints or tuple of ints or int ndarray or Iterable or None, optionalIndices or slice to return.

get_remotebool or NoneIf True, retrieve the value even if it is on a remote process. Note that if the variable is remote on ANY process, this function must be called on EVERY process in the Problem’s MPI communicator. If False, only retrieve the value if it is on the current process, or only the part of the value that’s on the current process for a distributed variable. If None and the variable is remote or distributed, a RuntimeError will be raised.

rankint or NoneIf not None, only gather the value to this rank.

vec_namestrName of the vector to use. Defaults to ‘nonlinear’.

kindstr or NoneKind of variable (‘input’, ‘output’, or ‘residual’). If None, returned value will be either an input or output.

flatboolIf True, return the flattened version of the value.

from_srcboolIf True, retrieve value of an input variable from its connected source.

- Returns

- object
The value of the requested output/input variable.

`initialize`

()[source]Declare options.

`is_active`

()Determine if the system is active on this rank.

- Returns

- bool
If running under MPI, returns True if this System has a valid communicator. Always returns True if not running under MPI.

property`linear_solver`

Get the linear solver for this system.

`list_inputs`

(val=True,prom_name=False,units=False,shape=False,global_shape=False,desc=False,hierarchical=True,print_arrays=False,tags=None,includes=None,excludes=None,all_procs=False,out_stream=DEFAULT_OUT_STREAM,values=None,print_min=False,print_max=False)Write a list of input names and other optional information to a specified stream.

- Parameters

valbool, optionalWhen True, display/return input values. Default is True.

prom_namebool, optionalWhen True, display/return the promoted name of the variable. Default is False.

unitsbool, optionalWhen True, display/return units. Default is False.

shapebool, optionalWhen True, display/return the shape of the value. Default is False.

global_shapebool, optionalWhen True, display/return the global shape of the value. Default is False.

descbool, optionalWhen True, display/return description. Default is False.

hierarchicalbool, optionalWhen True, human readable output shows variables in hierarchical format.

print_arraysbool, optionalWhen False, in the columnar display, just display norm of any ndarrays with size > 1. The norm is surrounded by vertical bars to indicate that it is a norm. When True, also display full values of the ndarray below the row. Format is affected by the values set with numpy.set_printoptions Default is False.

tagsstr or list of strsUser defined tags that can be used to filter what gets listed. Only inputs with the given tags will be listed. Default is None, which means there will be no filtering based on tags.

includesNone, str, or iter of strCollection of glob patterns for pathnames of variables to include. Default is None, which includes all input variables.

excludesNone, str, or iter of strCollection of glob patterns for pathnames of variables to exclude. Default is None.

all_procsbool, optionalWhen True, display output on all ranks. Default is False, which will display output only from rank 0.

out_streamfile-like objectWhere to send human readable output. Default is sys.stdout. Set to None to suppress.

valuesbool, optionalThis argument has been deprecated and will be removed in 4.0.

print_minboolWhen true, if the input value is an array, print its smallest value.

print_maxboolWhen true, if the input value is an array, print its largest value.

- Returns

- list of (name, metadata)
List of input names and other optional information about those inputs.

`list_outputs`

(explicit=True,implicit=True,val=True,prom_name=False,residuals=False,residuals_tol=None,units=False,shape=False,global_shape=False,bounds=False,scaling=False,desc=False,hierarchical=True,print_arrays=False,tags=None,includes=None,excludes=None,all_procs=False,list_autoivcs=False,out_stream=DEFAULT_OUT_STREAM,values=None,print_min=False,print_max=False)Write a list of output names and other optional information to a specified stream.

- Parameters

explicitbool, optionalInclude outputs from explicit components. Default is True.

implicitbool, optionalInclude outputs from implicit components. Default is True.

valbool, optionalWhen True, display output values. Default is True.

prom_namebool, optionalWhen True, display the promoted name of the variable. Default is False.

residualsbool, optionalWhen True, display residual values. Default is False.

residuals_tolfloat, optionalIf set, limits the output of list_outputs to only variables where the norm of the resids array is greater than the given ‘residuals_tol’. Default is None.

unitsbool, optionalWhen True, display units. Default is False.

shapebool, optionalWhen True, display/return the shape of the value. Default is False.

global_shapebool, optionalWhen True, display/return the global shape of the value. Default is False.

boundsbool, optionalWhen True, display/return bounds (lower and upper). Default is False.

scalingbool, optionalWhen True, display/return scaling (ref, ref0, and res_ref). Default is False.

descbool, optionalWhen True, display/return description. Default is False.

hierarchicalbool, optionalWhen True, human readable output shows variables in hierarchical format.

print_arraysbool, optionalWhen False, in the columnar display, just display norm of any ndarrays with size > 1. The norm is surrounded by vertical bars to indicate that it is a norm. When True, also display full values of the ndarray below the row. Format is affected by the values set with numpy.set_printoptions Default is False.

tagsstr or list of strsUser defined tags that can be used to filter what gets listed. Only outputs with the given tags will be listed. Default is None, which means there will be no filtering based on tags.

includesNone, str, or iter of strCollection of glob patterns for pathnames of variables to include. Default is None, which includes all output variables.

excludesNone, str, or iter of strCollection of glob patterns for pathnames of variables to exclude. Default is None.

all_procsbool, optionalWhen True, display output on all processors. Default is False.

list_autoivcsboolIf True, include auto_ivc outputs in the listing. Defaults to False.

out_streamfile-likeWhere to send human readable output. Default is sys.stdout. Set to None to suppress.

valuesbool, optionalThis argument has been deprecated and will be removed in 4.0.

print_minboolWhen true, if the output value is an array, print its smallest value.

print_maxboolWhen true, if the output value is an array, print its largest value.

- Returns

- list of (name, metadata)
List of output names and other optional information about those outputs.

property`msginfo`

Our instance pathname, if available, or our class name. For use in error messages.

- Returns

- str
Either our instance pathname or class name.

property`nonlinear_solver`

Get the nonlinear solver for this system.

`record_iteration`

()Record an iteration of the current System.

classmethod`register`

(name,callable_obj,complex_safe)[source]Register a callable to be usable within ExecComp expressions.

- Parameters

namestrName of the callable.

callable_objcallableThe callable.

complex_safeboolIf True, the given callable works correctly with complex numbers.

`run_apply_linear`

(mode,scope_out=None,scope_in=None)Compute jac-vec product.

This calls _apply_linear, but with the model assumed to be in an unscaled state.

- Parameters

modestr‘fwd’ or ‘rev’.

scope_outset or NoneSet of absolute output names in the scope of this mat-vec product. If None, all are in the scope.

scope_inset or NoneSet of absolute input names in the scope of this mat-vec product. If None, all are in the scope.

`run_apply_nonlinear`

()Compute residuals.

This calls _apply_nonlinear, but with the model assumed to be in an unscaled state.

`run_linearize`

(sub_do_ln=True)Compute jacobian / factorization.

This calls _linearize, but with the model assumed to be in an unscaled state.

- Parameters

sub_do_lnboolFlag indicating if the children should call linearize on their linear solvers.

`run_solve_linear`

(mode)Apply inverse jac product.

This calls _solve_linear, but with the model assumed to be in an unscaled state.

- Parameters

modestr‘fwd’ or ‘rev’.

`run_solve_nonlinear`

()Compute outputs.

This calls _solve_nonlinear, but with the model assumed to be in an unscaled state.

`set_check_partial_options`

(wrt,method='fd',form=None,step=None,step_calc=None,minimum_step=None,directional=False)Set options that will be used for checking partial derivatives.

- Parameters

wrtstr or list of strThe name or names of the variables that derivatives are taken with respect to. This can contain the name of any input or output variable. May also contain a glob pattern.

methodstrMethod for check: “fd” for finite difference, “cs” for complex step.

formstrFinite difference form for check, can be “forward”, “central”, or “backward”. Leave undeclared to keep unchanged from previous or default value.

stepfloatStep size for finite difference check. Leave undeclared to keep unchanged from previous or default value.

step_calcstrStep type for computing the size of the finite difference step. It can be ‘abs’ for absolute, ‘rel_avg’ for a size relative to the absolute value of the vector input, or ‘rel_element’ for a size relative to each value in the vector input. In addition, it can be ‘rel_legacy’ for a size relative to the norm of the vector. For backwards compatibilty, it can be ‘rel’, which currently defaults to ‘rel_legacy’, but in the future will default to ‘rel_avg’. Defaults to None, in which case the approximation method provides its default value.

minimum_stepfloatMinimum step size allowed when using one of the relative step_calc options.

directionalboolSet to True to perform a single directional derivative for each vector variable in the pattern named in wrt.

`set_initial_values`

()Set all input and output variables to their declared initial values.

`set_solver_print`

(level=2,depth=1e+99,type_='all')Control printing for solvers and subsolvers in the model.

- Parameters

levelintIprint level. Set to 2 to print residuals each iteration; set to 1 to print just the iteration totals; set to 0 to disable all printing except for failures, and set to -1 to disable all printing including failures.

depthintHow deep to recurse. For example, you can set this to 0 if you only want to print the top level linear and nonlinear solver messages. Default prints everything.

type_strType of solver to set: ‘LN’ for linear, ‘NL’ for nonlinear, or ‘all’ for all.

`setup`

()[source]Set up variable name and metadata lists.

`setup_partials`

()Declare partials.

This is meant to be overridden by component classes. All partials should be declared here since this is called after all size/shape information is known for all variables.

`system_iter`

(include_self=False,recurse=True,typ=None)Yield a generator of local subsystems of this system.

- Parameters

include_selfboolIf True, include this system in the iteration.

recurseboolIf True, iterate over the whole tree under this system.

typtypeIf not None, only yield Systems that match that are instances of the given type.

- Yields

- type or None

`use_fixed_coloring`

(coloring=<object object>,recurse=True)Use a precomputed coloring for this System.

- Parameters

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

recurseboolIf True, set fixed coloring in all subsystems that declare a coloring. Ignored if a specific coloring is passed in.

`openmdao.components.exec_comp.`

`array_idx_iter`

(shape)[source]Return an iterator over the indices into a n-dimensional array.

- Parameters

shapetupleShape of the array.

- Yields

- int

`openmdao.components.exec_comp.`

`check_option`

(option,value)[source]Check option for validity.

- Parameters

optionstrThe name of the option.

valueanyThe value of the option.

- Raises

- ValueError

`openmdao.components.exec_comp.`

`factorial`

(*args)[source]Raise a warning stating that the factorial function is deprecated.