paroto.models#
Model abstraction system for different fidelity levels.
Submodules#
- paroto.models.ablation
- paroto.models.arc_density
- paroto.models.arc_mobility
- paroto.models.base
- paroto.models.breakdown_voltage
- paroto.models.coverage
- paroto.models.energy_to_temperature
- paroto.models.gas_properties
- paroto.models.geometric_models
- paroto.models.geometry
- paroto.models.initial_temperature
- paroto.models.material_properties
- paroto.models.registry
- paroto.models.thermal_diameter
Classes#
Base class for all physics models - inherits from OpenMDAO. |
|
Base class for empirical models. |
|
Model fidelity levels. |
|
Model types. |
|
Base class for physical models. |
|
Registry for managing available physics models. |
Package Contents#
- class paroto.models.BaseModel(**kwargs)#
Bases:
openmdao.api.ExplicitComponentBase class for all physics models - inherits from OpenMDAO.
Adds model metadata (fidelity, type) to OpenMDAO components. Subclasses must implement setup(), compute(), and optionally compute_partials().
- model_fidelity#
Fidelity level of the model
- Type:
- initialize()#
Declare model options.
- to_dict()#
Serialize model to dictionary for YAML export.
- Returns:
model_dict – Model configuration as dictionary
- Return type:
- property nonlinear_solver#
Get the nonlinear solver for this system.
- property linear_solver#
Get the linear solver for this system.
- 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, compute_shape=None, units_by_conn=False, compute_units=None, copy_units=None, distributed=None, primal_name=None)#
Add an output variable to the component.
For ExplicitComponent, res_ref defaults to the value in res unless otherwise specified.
- Parameters:
name (
str) – Name of the variable in this component’s namespace.val (
floatorlistortupleorndarray) – The initial value of the variable being added in user-defined units. Default is 1.0.shape (
intortupleorlistorNone) – Shape of this variable, only required if val is not an array. Default is None.units (
strorNone) – Units in which the output variables will be provided to the component during execution. Default is None, which means it has no units.res_units (
strorNone) – Units in which the residuals of this output will be given to the user when requested. Default is None, which means it has no units.desc (
str) – Description of the variable.lower (
floatorlistortupleorndarrayorNone) – Lower 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.upper (
floatorlistortupleorndarrayorNone) – Upper 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.ref (
float) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 1. Default is 1.ref0 (
float) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 0. Default is 0.res_ref (
float) – Scaling 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.tags (
strorlistofstrs) – User 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_conn (
bool) – If True, shape this output to match its connected input(s).copy_shape (
strorNone) – If a str, that str is the name of a variable. Shape this output to match that of the named variable.compute_shape (
functionorNone) – If a function, that function is called to determine the shape of this output.units_by_conn (
bool) – If True, units are computed by the connected input(s).compute_units (
functionorNone) – If a function, that function is called to determine the units of this output.copy_units (
strorNone) – If a str, that str is the name of a variable. Units this output to match that of the named variable.distributed (
bool) – If True, this variable is a distributed variable, so it can have different sizes/values across MPI processes.primal_name (
strorNone) – Valid python name to represent the variable in compute_primal if ‘name’ is not a valid python name.
- Returns:
Metadata for added variable.
- Return type:
- compute(inputs, outputs, discrete_inputs=None, discrete_outputs=None)#
Compute outputs given inputs. The model is assumed to be in an unscaled state.
An inherited component may choose to either override this function or to define a compute_primal function.
- Parameters:
inputs (
Vector) – Unscaled, dimensional input variables read via inputs[key].outputs (
Vector) – Unscaled, dimensional output variables read via outputs[key].discrete_inputs (
dict-likeorNone) – If not None, dict-like object containing discrete input values.discrete_outputs (
dict-likeorNone) – If not None, dict-like object containing discrete output values.
- compute_partials(inputs, partials, discrete_inputs=None)#
Compute sub-jacobian parts. The model is assumed to be in an unscaled state.
- 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:
inputs (
Vector) – Unscaled, dimensional input variables read via inputs[key].d_inputs (
Vector) – See inputs; product must be computed only if var_name in d_inputs.d_outputs (
Vector) – See outputs; product must be computed only if var_name in d_outputs.mode (
str) – Either ‘fwd’ or ‘rev’.discrete_inputs (
dictorNone) – If not None, dict containing discrete input values.
- is_explicit(is_comp=True)#
Return True if this is an explicit component.
- compute_fd_sparsity(method='fd', num_full_jacs=2, perturb_size=1e-09)#
Use finite difference to compute a sparsity matrix.
- Parameters:
- Returns:
The sparsity matrix.
- Return type:
coo_matrix
- setup()#
Declare inputs and outputs.
- Available attributes:
name pathname comm options
- 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.
- property checking#
Return True if check_partials or check_totals is executing.
- Returns:
True if we’re running within check_partials or check_totals.
- Return type:
- add_input(name, val=1.0, shape=None, units=None, desc='', tags=None, shape_by_conn=False, copy_shape=None, compute_shape=None, units_by_conn=False, copy_units=None, compute_units=None, require_connection=False, distributed=None, primal_name=None)#
Add an input variable to the component.
- Parameters:
name (
str) – Name of the variable in this component’s namespace.val (
floatorlistortupleorndarrayorIterable) – The initial value of the variable being added in user-defined units. Default is 1.0.shape (
intortupleorlistorNone) – Shape of this variable, only required if val is not an array. Default is None.units (
strorNone) – Units in which this input variable will be provided to the component during execution. Default is None, which means it is unitless.desc (
str) – Description of the variable.tags (
strorlistofstrs) – User defined tags that can be used to filter what gets listed when calling list_inputs and list_outputs.shape_by_conn (
bool) – If True, shape this input to match its connected output.copy_shape (
strorNone) – If a str, that str is the name of a variable. Shape this input to match that of the named variable.compute_shape (
function) – A function taking a dict arg containing names and shapes of this component’s outputs and returning the shape of this input.units_by_conn (
bool) – If True, set units of this input to match its connected output.copy_units (
strorNone) – If a str, that str is the name of a variable. Set the units of this input to match those of the named variable.compute_units (
function) – A function taking a dict arg containing names and PhysicalUnits of this component’s outputs and returning the PhysicalUnits of this input.require_connection (
bool) – If True and this input is not a design variable, it must be connected to an output.distributed (
bool) – If True, this variable is a distributed variable, so it can have different sizes/values across MPI processes.primal_name (
strorNone) – Valid python name to represent the variable in compute_primal if ‘name’ is not a valid python name.
- Returns:
Metadata for added variable.
- Return type:
- add_discrete_input(name, val, desc='', tags=None, primal_name=None)#
Add a discrete input variable to the component.
- Parameters:
name (
str) – Name of the variable in this component’s namespace.val (
a picklable object) – The initial value of the variable being added.desc (
str) – Description of the variable.tags (
strorlistofstrs) – User defined tags that can be used to filter what gets listed when calling list_inputs and list_outputs.primal_name (
strorNone) – Valid python name to represent the variable in compute_primal if ‘name’ is not a valid python name.
- Returns:
Metadata for added variable.
- Return type:
- add_discrete_output(name, val, desc='', tags=None, primal_name=None)#
Add an output variable to the component.
- Parameters:
name (
str) – Name of the variable in this component’s namespace.val (
a picklable object) – The initial value of the variable being added.desc (
str) – Description of the variable.tags (
strorlistofstrsorsetofstrs) – User defined tags that can be used to filter what gets listed when calling list_inputs and list_outputs.primal_name (
strorNone) – Valid python name to represent the variable in compute_primal if ‘name’ is not a valid python name.
- Returns:
Metadata for added variable.
- Return type:
- declare_partials(of, wrt, dependent=True, rows=None, cols=None, val=None, method='exact', step=None, form=None, step_calc=None, minimum_step=None, diagonal=None)#
Declare information about this component’s subjacobians.
- Parameters:
of (
stroriterofstr) – The name of the residual(s) that derivatives are being computed for. May also contain a glob pattern.wrt (
stroriterofstr) – The name 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.dependent (
bool(True)) – If False, specifies no dependence between the output(s) and the input(s). This is only necessary in the case of a sparse global jacobian, because if ‘dependent=False’ is not specified and declare_partials is not called for a given pair, then a dense matrix of zeros will be allocated in the sparse global jacobian for that pair. In the case of a dense global jacobian it doesn’t matter because the space for a dense subjac will always be allocated for every pair.rows (
ndarrayofintorNone) – Row indices for each nonzero entry. For sparse subjacobians only.cols (
ndarrayofintorNone) – Column indices for each nonzero entry. For sparse subjacobians only.val (
floatorndarrayoffloatorscipy.sparse) – Value of subjacobian. If rows and cols are not None, this will contain the values found at each (row, col) location in the subjac.method (
str) – The type of approximation that should be used. Valid options include: ‘fd’: Finite Difference, ‘cs’: Complex Step, ‘exact’: use the component defined analytic derivatives. Default is ‘exact’.step (
float) – Step size for approximation. Defaults to None, in which case the approximation method provides its default value.form (
str) – Form for finite difference, can be ‘forward’, ‘backward’, or ‘central’. Defaults to None, in which case the approximation method provides its default value.step_calc (
str) – Step 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 is now equivalent to ‘rel_avg’. Defaults to None, in which case the approximation method provides its default value.minimum_step (
float) – Minimum step size allowed when using one of the relative step_calc options.diagonal (
bool) – If True, the subjacobian is a diagonal matrix.
- Returns:
Metadata dict for the specified partial(s).
- Return type:
- declare_coloring(wrt=_DEFAULT_COLORING_META['wrt_patterns'], method=_DEFAULT_COLORING_META['method'], form=None, step=None, per_instance=_DEFAULT_COLORING_META['per_instance'], num_full_jacs=_DEFAULT_COLORING_META['num_full_jacs'], tol=_DEFAULT_COLORING_META['tol'], orders=_DEFAULT_COLORING_META['orders'], perturb_size=_DEFAULT_COLORING_META['perturb_size'], min_improve_pct=_DEFAULT_COLORING_META['min_improve_pct'], show_summary=_DEFAULT_COLORING_META['show_summary'], show_sparsity=_DEFAULT_COLORING_META['show_sparsity'])#
Set options for deriv coloring of a set of wrt vars matching the given pattern(s).
- Parameters:
wrt (
strorlistofstr) – The name or names of the variables that derivatives are taken with respect to. This can contain input names, output names, or glob patterns.method (
str) – Method used to compute derivative: “fd” for finite difference, “cs” for complex step.form (
str) – Finite difference form, can be “forward”, “central”, or “backward”. Leave undeclared to keep unchanged from previous or default value.step (
float) – Step size for finite difference. Leave undeclared to keep unchanged from previous or default value.per_instance (
bool) – If 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_jacs (
int) – Number of times to repeat partial jacobian computation when computing sparsity.tol (
float) – Tolerance used to determine if an array entry is nonzero during sparsity determination.orders (
int) – Number of orders above and below the tolerance to check during the tolerance sweep.perturb_size (
float) – Size of input/output perturbation during generation of sparsity.min_improve_pct (
float) – If coloring does not improve (decrease) the number of solves more than the given percentage, coloring will not be used.show_summary (
bool) – If True, display summary information after generating coloring.show_sparsity (
bool) – If True, display sparsity with coloring info after generating coloring.
- 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:
wrt (
strorlistofstr) – The 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.method (
str) – Method for check: “fd” for finite difference, “cs” for complex step.form (
str) – Finite difference form for check, can be “forward”, “central”, or “backward”. Leave undeclared to keep unchanged from previous or default value.step (
float) – Step size for finite difference check. Leave undeclared to keep unchanged from previous or default value.step_calc (
str) – Step 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 is now equivalent to ‘rel_avg’. Defaults to None, in which case the approximation method provides its default value..minimum_step (
float) – Minimum step size allowed when using one of the relative step_calc options.directional (
bool) – Set to True to perform a single directional derivative for each vector variable in the pattern named in wrt.
- compute_fd_jac(jac, method='fd')#
Force the use of finite difference to compute a jacobian.
This can be used to compute sparsity for a component that computes derivatives analytically in order to check the accuracy of the declared sparsity.
- Parameters:
jac (
Jacobian) – The Jacobian object that will contain the computed jacobian.method (
str) – The type of finite difference to perform. Valid options are ‘fd’ for forward difference, or ‘cs’ for complex step.
- check_sparsity(method='fd', max_nz=90.0, out_stream=_DEFAULT_OUT_STREAM)#
Check the sparsity of the computed jacobian against the declared sparsity.
Check is skipped if one of the dimensions of the jacobian is 1 or if the percentage of nonzeros in the computed jacobian is greater than max_nz%.
- Parameters:
method (
str) – The type of finite difference to perform. Valid options are ‘fd’ for forward difference, or ‘cs’ for complex step.max_nz (
float) – If the percentage of nonzeros in a sub-jacobian exceeds this, no warning is issued if the computed sparsity does not match the declared sparsity.out_stream (
file-like object) – Where to send the output. If None, output will be suppressed.
- Returns:
A list of tuples, one for each subjacobian that has a mismatch between the computed sparsity and the declared sparsity. Each tuple has the form (of, wrt, computed_rows, computed_cols, declared_rows, declared_cols, shape, pct_nonzero).
- Return type:
- check_partials(out_stream=_DEFAULT_OUT_STREAM, compact_print=False, abs_err_tol=0.0, rel_err_tol=1e-06, method='fd', step=None, form='forward', step_calc='abs', minimum_step=1e-12, force_dense=True, show_only_incorrect=False, show_worst=True, rich_print=True)#
Check partial derivatives comprehensively for this component.
- Parameters:
out_stream (
file-like object) – Where to send human readable output. By default it goes to stdout. Set to None to suppress.compact_print (
bool) – Set to True to just print the essentials, one line per input-output pair.abs_err_tol (
float) – Threshold value for absolute error. Errors about this value will have a ‘*’ displayed next to them in output, making them easy to search for. Default is 1.0E-6.rel_err_tol (
float) – Threshold value for relative error. Errors about this value will have a ‘*’ displayed next to them in output, making them easy to search for. Note at times there may be a significant relative error due to a minor absolute error. Default is 1.0E-6.method (
str) – Method, ‘fd’ for finite difference or ‘cs’ for complex step. Default is ‘fd’.step (
None,float, orlist/tupleoffloat) – Step size(s) for approximation. Default is None, which means 1e-6 for ‘fd’ and 1e-40 for ‘cs’.form (
str) – Form for finite difference, can be ‘forward’, ‘backward’, or ‘central’. Default ‘forward’.step_calc (
str) – Step 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 is now equivalent to ‘rel_avg’. Defaults to None, in which case the approximation method provides its default value.minimum_step (
float) – Minimum step size allowed when using one of the relative step_calc options.force_dense (
bool) – If True, analytic derivatives will be coerced into arrays. Default is True.show_only_incorrect (
bool, optional) – Set to True if output should print only the subjacs found to be incorrect.show_worst (
bool, optional) – Set to False to suppress the display of the worst subjac.rich_print (
bool, optional) – If True, print using rich if available.
- Returns:
Where derivs_dict is a dict, where the top key is the component pathname. Under the top key, the subkeys are the (of, wrt) keys of the subjacs. Within the (of, wrt) entries are the following keys: ‘tol violation’, ‘magnitude’, ‘J_fd’, ‘J_fwd’, ‘J_rev’, ‘vals_at_max_error’, and ‘rank_inconsistent’. For ‘J_fd’, ‘J_fwd’, ‘J_rev’ the value is a numpy array representing the computed Jacobian for the three different methods of computation. For ‘tol violation’ and ‘vals_at_max_error’ the value is a tuple containing values for forward - fd, reverse - fd, forward - reverse. For ‘magnitude’ the value is a tuple indicating the maximum magnitude of values found in Jfwd, Jrev, and Jfd. The boolean ‘rank_inconsistent’ indicates if the derivative wrt a serial variable is inconsistent across MPI ranks.
worst is either None or a tuple of the form (error, table_row, header) where error is the max error found, table_row is the formatted table row containing the max error, and header is the formatted table header. ‘worst’ is not None only if compact_print is True.
- Return type:
tupleofthe form (derivs_dict,worst)
- get_declare_partials_calls(sparsity=None)#
Return a string containing declare_partials() calls based on the subjac sparsity.
- name = ''#
- pathname = None#
- options#
- recording_options#
- iter_count = 0#
- iter_count_apply = 0#
- iter_count_without_approx = 0#
- cite = ''#
- matrix_free#
- under_complex_step = False#
- under_finite_difference = False#
- property comm#
Return the wrapped MPI communicator object for the system.
- Returns:
Wrapped MPI communicator object.
- Return type:
DebugComm
- property under_approx#
Return True if under complex step or finite difference.
- Returns:
True if under CS or FD.
- Return type:
- property msginfo#
Our instance pathname, if available, or our class name. For use in error messages.
- Returns:
Either our instance pathname or class name.
- Return type:
- abs_meta_iter(iotype, local=True, cont=True, discrete=False)#
Iterate over absolute variable names and their metadata for this System.
By setting appropriate values for ‘cont’ and ‘discrete’, yielded variable names can be continuous only, discrete only, or both.
- Parameters:
- Yields:
- set_output_solver_options(name, lower=_UNDEFINED, upper=_UNDEFINED, ref=_UNDEFINED, ref0=_UNDEFINED, res_ref=_UNDEFINED)#
Set solver output options.
Allows the user to set output solver options after the output has been defined and metadata set using the add_ouput method.
- Parameters:
name (
str) – Name of the variable in this system’s namespace.lower (
floatorlistortupleorndarrayorNone) – Lower 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.upper (
floatorlistortupleorndarrayorNone) – Upper 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.ref (
float) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 1. Default is 1.ref0 (
float) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 0. Default is 0.res_ref (
float) – Scaling 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.
- set_design_var_options(name, lower=_UNDEFINED, upper=_UNDEFINED, scaler=_UNDEFINED, adder=_UNDEFINED, ref=_UNDEFINED, ref0=_UNDEFINED)#
Set options for design vars in the model.
Can be used to set the options outside of setting them when calling add_design_var
- Parameters:
name (
str) – Name of the variable in this system’s namespace.lower (
floatorndarray, optional) – Lower boundary for the input.upper (
upperorndarray, optional) – Upper boundary for the input.scaler (
floatorndarray, optional) – Value 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.adder (
floatorndarray, optional) – Value 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.ref (
floatorndarray, optional) – Value of design var that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of design var that scales to 0.0 in the driver.
- set_constraint_options(name, ref=_UNDEFINED, ref0=_UNDEFINED, equals=_UNDEFINED, lower=_UNDEFINED, upper=_UNDEFINED, adder=_UNDEFINED, scaler=_UNDEFINED, alias=_UNDEFINED)#
Set options for constraints in the model.
Can be used to set options that were set using add_constraint.
- Parameters:
name (
str) – Name of the response variable in the system, or alias if given.ref (
floatorndarray, optional) – Value of response variable that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of response variable that scales to 0.0 in the driver.equals (
floatorndarray, optional) – Equality constraint value for the variable.lower (
floatorndarray, optional) – Lower boundary for the variable.upper (
floatorndarray, optional) – Upper boundary for the variable.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value 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.alias (
str, optional) – Alias for this response. Necessary when adding multiple constraints on different indices or slices of a single variable.
- set_objective_options(name, ref=_UNDEFINED, ref0=_UNDEFINED, adder=_UNDEFINED, scaler=_UNDEFINED, alias=_UNDEFINED)#
Set options for objectives in the model.
Can be used to set options after they have been set by add_objective.
- Parameters:
name (
str) – Name of the response variable in the system, or alias if given.ref (
floatorndarray, optional) – Value of response variable that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of response variable that scales to 0.0 in the driver.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value 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.alias (
str) – Alias for this response. Used to disambiguate variable names when adding multiple objectives on different indices or slices of a single variable. Deprecated.
- 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.
- use_fixed_coloring(coloring=STD_COLORING_FNAME(), recurse=True)#
Use a precomputed coloring for this System.
- uses_approx()#
Return True if the system uses approximations to compute derivatives.
- Returns:
True if the system uses approximations to compute derivatives, False otherwise.
- Return type:
- compute_sparsity(direction=None, num_iters=2, perturb_size=1e-09)#
Compute the sparsity of the partial jacobian.
- Parameters:
direction (
str) – Compute derivatives in fwd or rev mode, or whichever is based based on input and output sizes if value is None. Note that only fwd is possible when using finite difference.num_iters (
int) – Number of times to compute the full jacobian.perturb_size (
float) – Size of relative perturbation. If base value is 0.0, perturbation is absolute.
- Returns:
coo_matrix– The sparsity matrix.dict– Metadata about the sparsity computation.
- subjac_sparsity_iter(sparsity, wrt_matches=None)#
Iterate over sparsity for each subjac in the jacobian.
- Parameters:
- Yields:
- sparsity_matches_fd(direction=None, outstream=sys.stdout)#
Compare the sparsity computed by this system vs. the sparsity computed using fd.
Note that some systems use fd to compute their sparsity, so no difference will ever be found even if the sparsity is somehow incorrect.
- Parameters:
direction (
strorNone) – Compute derivatives in fwd or rev mode, or whichever is based based on input and output sizes if value is None. Note that only fwd is possible when using finite difference.outstream (
file-like) – Stream where output will be written. If None, no output will be written. The output is a text visualization of the sparsity difference.
- Returns:
True if they match, False otherwise.
- Return type:
- get_coloring_fname(mode)#
Return the full pathname to a coloring file.
- Parameters:
mode (
str) – The type of coloring file desired. Must be either ‘input’ or ‘output’.- Returns:
Full pathname of the coloring file.
- Return type:
- get_nonlinear_vectors()#
Return the inputs, outputs, and residuals vectors.
- Returns:
Yields the inputs, outputs, and residuals nonlinear vectors.
- Return type:
(inputs,outputs,residuals)
- get_linear_vectors()#
Return the linear inputs, outputs, and residuals vectors.
- Returns:
(inputs, outputs, residuals) – Yields the linear inputs, outputs, and residuals vectors.
- Return type:
tupleof<Vector> instances
- set_solver_print(level=2, depth=1e+99, type_='all', debug_print=None)#
Control printing for solvers and subsolvers in the model.
- Parameters:
level (
intorNone) – Iprint 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. A value of None will leave solving printing unchanged, which is useful when using this method to enable or disable debug printing only.depth (
int) – How 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 (
str) – Type of solver to set: ‘LN’ for linear, ‘NL’ for nonlinear, or ‘all’ for all.debug_print (
boolorNone) – If None, leave solver debug printing unchanged, otherwise turn it on or off depending on whether debug_print is True or False. Note debug_print is only applied to nonlinear solvers.
- system_iter(include_self=False, recurse=True, typ=None, depth_first=False)#
Yield a generator of local subsystems of this system.
- Parameters:
include_self (
bool) – If True, include this system in the iteration.recurse (
bool) – If True, iterate over the whole tree under this system.typ (
type) – If not None, only yield Systems that match that are instances of the given type.depth_first (
bool) – If recurse is True, this specifies whether subsystems are returned in depth-first order (if True) or bredth-first order (if False).
- Yields:
- 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:
name (
str) – Promoted name of the design variable in the system.lower (
floatorndarray, optional) – Lower boundary for the input.upper (
upperorndarray, optional) – Upper boundary for the input.ref (
floatorndarray, optional) – Value of design var that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of design var that scales to 0.0 in the driver.indices (
iterofint, optional) – If an input is an array, these indicate which entries are of interest for this particular design variable. These may be positive or negative integers.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value 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.units (
str, optional) – Units to convert to before applying scaling.parallel_deriv_color (
str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.cache_linear_solution (
bool) – If 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_indices (
bool) – If True, interpret specified indices as being indices into a flat source array.
Notes
The response can be scaled using ref and ref0. The argument
ref0represents the physical value when the scaled value is 0. The argumentrefrepresents the physical value when the scaled value is 1.
- 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, alias=None)#
Add a response variable to this system.
The response can be scaled using ref and ref0. The argument
ref0represents the physical value when the scaled value is 0. The argumentrefrepresents the physical value when the scaled value is 1.- Parameters:
name (
str) – Promoted name of the response variable in the system.type (
str) – The type of response. Supported values are ‘con’ and ‘obj’.lower (
floatorndarray, optional) – Lower boundary for the variable.upper (
upperorndarray, optional) – Upper boundary for the variable.equals (
equalsorndarray, optional) – Equality constraint value for the variable.ref (
floatorndarray, optional) – Value of response variable that scales to 1.0 in the driver.ref0 (
upperorndarray, optional) – Value of response variable that scales to 0.0 in the driver.indices (
sequenceofint, optional) – If variable is an array, these indicate which entries are of interest for this particular response.index (
int, optional) – If variable is an array, this indicates which entry is of interest for this particular response.units (
str, optional) – Units to convert to before applying scaling.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value 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.linear (
bool) – Set to True if constraint is linear. Default is False.parallel_deriv_color (
str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.cache_linear_solution (
bool) – If 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_indices (
bool) – If True, interpret specified indices as being indices into a flat source array.alias (
strorNone) – Alias for this response. Necessary when adding multiple responses on different indices of the same variable.
- 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, alias=None)#
Add a constraint variable to this system.
- Parameters:
name (
str) – Name of the response variable in the system.lower (
floatorndarray, optional) – Lower boundary for the variable.upper (
floatorndarray, optional) – Upper boundary for the variable.equals (
floatorndarray, optional) – Equality constraint value for the variable.ref (
floatorndarray, optional) – Value of response variable that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of response variable that scales to 0.0 in the driver.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alternative to using ref and ref0.units (
str, optional) – Units to convert to before applying scaling.indices (
sequenceofint, optional) – If variable is an array, these indicate which entries are of interest for this particular response. These may be positive or negative integers.linear (
bool) – Set to True if constraint is linear. Default is False.parallel_deriv_color (
str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.cache_linear_solution (
bool) – If 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_indices (
bool) – If True, interpret specified indices as being indices into a flat source array.alias (
str) – Alias for this response. Necessary when adding multiple constraints on different indices or slices of a single variable.
Notes
The response can be scaled using ref and ref0. The argument
ref0represents the physical value when the scaled value is 0. The argumentrefrepresents the physical value when the scaled value is 1. The arguments (lower,upper,equals) can not be strings or variable names.
- 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, alias=None)#
Add a response variable to this system.
- Parameters:
name (
str) – Name of the response variable in the system.ref (
floatorndarray, optional) – Value of response variable that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of response variable that scales to 0.0 in the driver.index (
int, optional) – If variable is an array, this indicates which entry is of interest for this particular response. This may be a positive or negative integer.units (
str, optional) – Units to convert to before applying scaling.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value 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_color (
str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.cache_linear_solution (
bool) – If 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_indices (
bool) – If True, interpret specified indices as being indices into a flat source array.alias (
str) – Alias for this response. Necessary when adding multiple objectives on different indices or slices of a single variable.
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} \]
- 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:
recurse (
bool) – If True, recurse through the subsystems of a group and return the path of all design vars relative to the this system.get_sizes (
bool, optional) – If True, compute the size of each design variable.use_prom_ivc (
bool) – Use promoted names for inputs, else convert to absolute source names.
- Returns:
The design variables defined in the current system and, if recurse=True, its subsystems.
- Return type:
- 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 either absolute variable name, promoted name, or alias name, depending on the value of use_prom_ivc and whether the original key was a promoted output, promoted input, or an alias.
- Parameters:
- Returns:
The responses defined in the current system and, if recurse=True, its subsystems.
- Return type:
- get_constraints(recurse=True, get_sizes=True, use_prom_ivc=True)#
Get the Constraint settings from this system.
Retrieve the constraint settings for the current system as a dict, keyed by variable name.
- Parameters:
- Returns:
The constraints defined in the current system.
- Return type:
- get_objectives(recurse=True, get_sizes=True, use_prom_ivc=True)#
Get the Objective settings from this system.
Retrieve all objectives settings from the system as a dict, keyed by variable name.
- Parameters:
- Returns:
The objectives defined in the current system.
- Return type:
- run_apply_nonlinear()#
Compute residuals.
This calls _apply_nonlinear, but with the model assumed to be in an unscaled state.
- get_io_metadata(iotypes=('input', 'output'), metadata_keys=None, includes=None, excludes=None, is_indep_var=None, is_design_var=None, tags=None, get_remote=False, rank=None, return_rel_names=True)#
Retrieve metadata for a filtered list of variables.
- Parameters:
iotypes (
stroriterofstr) – Will contain either ‘input’, ‘output’, or both. Defaults to both.metadata_keys (
iterofstrorNone) – Names 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.includes (
str,iterofstrorNone) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all variables.excludes (
str,iterofstrorNone) – Collection of glob patterns for pathnames of variables to exclude. Default is None.is_indep_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to an output tagged openmdao:indep_var. If False, list only inputs _not_ connected to outputs tagged openmdao:indep_var.is_design_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.tags (
stroriterofstrs) – User 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_remote (
bool) – If True, retrieve variables from other MPI processes as well.rank (
intorNone) – If 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_names (
bool) – If True, the names returned will be relative to the scope of this System. Otherwise they will be absolute names.
- Returns:
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, ‘prom_name’ and ‘discrete’, to indicate a given variable’s promoted name and whether or not it is discrete.
- Return type:
- list_vars(val=True, prom_name=True, residuals=False, residuals_tol=None, units=False, shape=False, global_shape=False, bounds=False, scaling=False, desc=False, print_arrays=False, tags=None, print_tags=False, includes=None, excludes=None, is_indep_var=None, is_design_var=None, all_procs=False, list_autoivcs=False, out_stream=_DEFAULT_OUT_STREAM, print_min=False, print_max=False, print_mean=False, return_format='list')#
Write a list of inputs and outputs sorted by component in execution order.
- Parameters:
val (
bool, optional) – When True, display output values. Default is True.prom_name (
bool, optional) – When True, display the promoted name of the variable. Default is True.residuals (
bool, optional) – When True, display residual values. Default is False.residuals_tol (
float, optional) – If 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.units (
bool, optional) – When True, display units. Default is False.shape (
bool, optional) – When True, display/return the shape of the value. Default is False.global_shape (
bool, optional) – When True, display/return the global shape of the value. Default is False.bounds (
bool, optional) – When True, display/return bounds (lower and upper). Default is False.scaling (
bool, optional) – When True, display/return scaling (ref, ref0, and res_ref). Default is False.desc (
bool, optional) – When True, display/return description. Default is False.print_arrays (
bool, optional) – When 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.tags (
strorlistofstrs) – User 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.print_tags (
bool) – When true, display tags in the columnar display.includes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all output variables.excludes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to exclude. Default is None.is_indep_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only outputs tagged openmdao:indep_var. If False, list only outputs that are _not_ tagged openmdao:indep_var.is_design_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.all_procs (
bool, optional) – When True, display output on all processors. Default is False.list_autoivcs (
bool) – If True, include auto_ivc outputs in the listing. Defaults to False.out_stream (
file-like) – Where to send human readable output. Default is sys.stdout. Set to None to suppress.print_min (
bool) – When true, if the output value is an array, print its smallest value.print_max (
bool) – When true, if the output value is an array, print its largest value.print_mean (
bool) – When true, if the output value is an array, print its mean value.return_format (
str) – Indicates the desired format of the return value. Can have value of ‘list’ or ‘dict’. If ‘list’, the return value is a list of (name, metadata) tuples. if ‘dict’, the return value is a dictionary mapping {name: metadata}.
- Returns:
list of (name, metadata) or dict of {name – List or dict of output names and other optional information about those outputs.
- Return type:
metadata``}``
- list_inputs(val=True, prom_name=True, units=False, shape=False, global_shape=False, desc=False, hierarchical=True, print_arrays=False, tags=None, print_tags=False, includes=None, excludes=None, is_indep_var=None, is_design_var=None, all_procs=False, out_stream=_DEFAULT_OUT_STREAM, print_min=False, print_max=False, print_mean=False, return_format='list')#
Write a list of input names and other optional information to a specified stream.
- Parameters:
val (
bool, optional) – When True, display/return input values. Default is True.prom_name (
bool, optional) – When True, display/return the promoted name of the variable. Default is True.units (
bool, optional) – When True, display/return units. Default is False.shape (
bool, optional) – When True, display/return the shape of the value. Default is False.global_shape (
bool, optional) – When True, display/return the global shape of the value. Default is False.desc (
bool, optional) – When True, display/return description. Default is False.hierarchical (
bool, optional) – When True, human readable output shows variables in hierarchical format.print_arrays (
bool, optional) – When 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.tags (
strorlistofstrs) – User 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.print_tags (
bool) – When true, display tags in the columnar display.includes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all input variables.excludes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to exclude. Default is None.is_indep_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to an output tagged openmdao:indep_var. If False, list only inputs _not_ connected to outputs tagged openmdao:indep_var.is_design_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.all_procs (
bool, optional) – When True, display output on all ranks. Default is False, which will display output only from rank 0.out_stream (
file-like object) – Where to send human readable output. Default is sys.stdout. Set to None to suppress.print_min (
bool) – When true, if the input value is an array, print its smallest value.print_max (
bool) – When true, if the input value is an array, print its largest value.print_mean (
bool) – When true, if the input value is an array, print its mean value.return_format (
str) – Indicates the desired format of the return value. Can have value of ‘list’ or ‘dict’. If ‘list’, the return value is a list of (name, metadata) tuples. if ‘dict’, the return value is a dictionary mapping {name: metadata}.
- Returns:
list of (name, metadata) or dict of {name – List or dict of input names and other optional information about those inputs.
- Return type:
metadata``}``
- list_outputs(explicit=True, implicit=True, val=True, prom_name=True, 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, print_tags=False, includes=None, excludes=None, is_indep_var=None, is_design_var=None, all_procs=False, list_autoivcs=False, out_stream=_DEFAULT_OUT_STREAM, print_min=False, print_max=False, print_mean=False, return_format='list')#
Write a list of output names and other optional information to a specified stream.
- Parameters:
explicit (
bool, optional) – Include outputs from explicit components. Default is True.implicit (
bool, optional) – Include outputs from implicit components. Default is True.val (
bool, optional) – When True, display output values. Default is True.prom_name (
bool, optional) – When True, display the promoted name of the variable. Default is True.residuals (
bool, optional) – When True, display residual values. Default is False.residuals_tol (
float, optional) – If 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.units (
bool, optional) – When True, display units. Default is False.shape (
bool, optional) – When True, display/return the shape of the value. Default is False.global_shape (
bool, optional) – When True, display/return the global shape of the value. Default is False.bounds (
bool, optional) – When True, display/return bounds (lower and upper). Default is False.scaling (
bool, optional) – When True, display/return scaling (ref, ref0, and res_ref). Default is False.desc (
bool, optional) – When True, display/return description. Default is False.hierarchical (
bool, optional) – When True, human readable output shows variables in hierarchical format.print_arrays (
bool, optional) – When 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.tags (
strorlistofstrs) – User 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.print_tags (
bool) – When true, display tags in the columnar display.includes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all output variables.excludes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to exclude. Default is None.is_indep_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only outputs tagged openmdao:indep_var. If False, list only outputs that are _not_ tagged openmdao:indep_var.is_design_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.all_procs (
bool, optional) – When True, display output on all processors. Default is False.list_autoivcs (
bool) – If True, include auto_ivc outputs in the listing. Defaults to False.out_stream (
file-like) – Where to send human readable output. Default is sys.stdout. Set to None to suppress.print_min (
bool) – When true, if the output value is an array, print its smallest value.print_max (
bool) – When true, if the output value is an array, print its largest value.print_mean (
bool) – When true, if the output value is an array, print its mean value.return_format (
str) – Indicates the desired format of the return value. Can have value of ‘list’ or ‘dict’. If ‘list’, the return value is a list of (name, metadata) tuples. if ‘dict’, the return value is a dictionary mapping {name: metadata}.
- Returns:
list of (name, metadata) or dict of {name – List or dict of output names and other optional information about those outputs.
- Return type:
metadata``}``
- list_options(include_default=True, include_solvers=True, out_stream=_DEFAULT_OUT_STREAM, return_format='list')#
Write a list of output names and other optional information to a specified stream.
- Parameters:
include_default (
bool) – When True, include the built-in openmdao system options. Default is True.include_solvers (
bool) – When True, include options from nonlinear_solver and linear_solver.out_stream (
file-like) – Where to send human readable output. Default is sys.stdout. Set to None to suppress.return_format (
str) – Indicates the desired format of the return value. Can have value of ‘list’ or ‘dict’. If ‘list’, the return value is a list of tuples of the form: (pathname, system options , nonlinear solver options, linear solver options) if ‘dict’, the return value is a dictionary with the pathname as key, and a dictionary as the value. The dictionary contains ‘options’, ‘nonlinear_solver’, and ‘linear_solver’ keys, each of which isa dictionary of options.
- Returns:
List of tuples, one for each subsystem sorted by execution order. Each tuple contains the pathname string, a dictionary of system options, a dictionary of nonlinear solver options (only if include_solvers is True) or None, and a dictionary of nonlinear solver options (only if include_solvers is True) or None.
- Return type:
- run_solve_nonlinear()#
Compute outputs.
This calls _solve_nonlinear, but with the model assumed to be in an unscaled state.
- 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.
- run_solve_linear(mode)#
Apply inverse jac product.
This calls _solve_linear, but with the model assumed to be in an unscaled state.
- Parameters:
mode (
str) – ‘fwd’ or ‘rev’.
- 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_ln (
bool) – Flag indicating if the children should call linearize on their linear solvers.
- check_config(logger)#
Perform optional error checks.
- Parameters:
logger (
object) – The object that manages logging output.
- load_model_options()#
Load the relevant model options from Problem._metadata[‘model_options’].
This method examines each path filter and corresponding options in self._problem_meta[‘model_options’]. If this System’s pathname matches the given path filter, it will assume the value for each given option which it possesses.
- add_recorder(recorder, recurse=False)#
Add a recorder to the system.
- Parameters:
recorder (
<CaseRecorder>) – A recorder instance.recurse (
bool) – Flag indicating if the recorder should be added to all the subsystems.
- record_iteration()#
Record an iteration of the current System.
- get_reports_dir()#
Get the path to the directory where the report files should go.
If it doesn’t exist, it will be created.
- Returns:
The path to the directory where reports should be written.
- Return type:
- get_outputs_dir(*subdirs, mkdir=False)#
Get the path under which all output files of this system are to be placed.
- Parameters:
- Returns:
The path of the outputs directory for the problem.
- Return type:
- cleanup()#
Clean up resources prior to exit.
- get_val(name, units=None, indices=None, get_remote=False, rank=None, vec_name='nonlinear', kind=None, flat=False, from_src=True, copy=False)#
Get an output/input/residual variable.
Function is used if you want to specify display units.
- Parameters:
name (
str) – Promoted or relative variable name in the root system’s namespace.units (
str, optional) – Units to convert to before return.indices (
intorlistofintsortupleofintsorint ndarrayorIterableorNone, optional) – Indices or slice to return.get_remote (
boolorNone) – If 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.rank (
intorNone) – If not None, only gather the value to this rank.vec_name (
str) – Name of the vector to use. Defaults to ‘nonlinear’.kind (
strorNone) – Kind of variable (‘input’, ‘output’, or ‘residual’). If None, returned value will be either an input or output.flat (
bool) – If True, return the flattened version of the value.from_src (
bool) – If True, retrieve value of an input variable from its connected source.copy (
bool, optional) – If True, return a copy of the value. If False, return a reference to the value.
- Returns:
The value of the requested output/input variable.
- Return type:
- set_val(name, val, units=None, indices=None)#
Set an input or output variable.
- convert2units(name, val, units)#
Convert the given value to the specified units.
- convert_from_units(name, val, units)#
Convert the given value from the specified units to those of the named variable.
- convert_units(name, val, units_from, units_to)#
Wrap the utility convert_units and give a good error message.
- total_local_size(io)#
Return the total local size of the given variable.
- best_partial_deriv_direction()#
Return the best direction for partial deriv calculations based on input and output sizes.
- Returns:
The best direction for derivative calculations, ‘fwd’ or ‘rev’.
- Return type:
- get_promotions(inprom=None, outprom=None)#
Return all promotions for the given promoted variable(s).
In other words, how and where did promotions occur to convert absolute variable names into the given promoted name(s) at the current System level.
- Parameters:
- Returns:
Dictionary keyed on system pathname containing input and/or output promotion lists for each System where promotions occurred to produce the given promoted variable(s).
- Return type:
- load_case(case)#
Pull all input and output variables from a Case into this System.
Override this method if the System requires special handling when loading a case.
- Parameters:
case (
Caseordict) – A Case from a CaseReader, or a dictionary with key ‘inputs’ mapped to the output of problem.model.list_inputs and key ‘outputs’ mapped to the output of prob.model.list_outputs. Both list_inputs and list_outputs should be called with prom_name=True and return_format=’dict’.
- comm_info_iter()#
Yield comm size for this system and all subsystems.
- Yields:
tuple– A tuple of the form (abs_name, comm_size).
- dist_size_iter(io, top_comm)#
Yield names and distributed ranges of all local and remote variables in this system.
- get_var_dup_info(name, io)#
Return information about how the given variable is duplicated across MPI processes.
- get_var_sizes(name, io)#
Return the sizes of the given variable on all procs.
- get_self_statics()#
Override this in derived classes if compute_primal references static values.
Do NOT include self._discrete_inputs in the returned tuple. Include things like self.options[‘opt_name’], etc., that are used in compute_primal but are assumed to be constant during derivative computation.
Return value MUST be a tuple. Don’t forget the trailing comma if tuple has only one item. Return value MUST be hashable.
The order of these values doesn’t matter. They are only checked (by computing their hash) to see if they have changed since the last time compute_primal was jitted, and if so, compute_primal will be re-jitted.
- Returns:
Tuple containing all static values required by compute_primal.
- Return type:
- run_validation()#
Run validate method on all systems below this system.
The validate method on each system can be used to check any final input / output values after a run.
- validate(inputs, outputs, discrete_inputs=None, discrete_outputs=None)#
Check any final input / output values after a run.
The model is assumed to be in an unscaled state. An inherited component may choose to either override this function or ignore it. Any errors or warnings raised in this method will be collected and all printed / raised together.
- Parameters:
inputs (
Vector) – Unscaled, dimensional input variables read via inputs[key].outputs (
Vector) – Unscaled, dimensional output variables read via outputs[key].discrete_inputs (
dict-likeorNone) – If not None, dict-like object containing discrete input values.discrete_outputs (
dict-likeorNone) – If not None, dict-like object containing discrete output values.
- class paroto.models.EmpiricalModel(**kwargs)#
Bases:
BaseModelBase class for empirical models.
Empirical models are based on experimental data and correlations. They are typically fast but may have limited validity ranges.
- initialize()#
Initialize with empirical model type.
- to_dict()#
Serialize model to dictionary for YAML export.
- Returns:
model_dict – Model configuration as dictionary
- Return type:
- property nonlinear_solver#
Get the nonlinear solver for this system.
- property linear_solver#
Get the linear solver for this system.
- 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, compute_shape=None, units_by_conn=False, compute_units=None, copy_units=None, distributed=None, primal_name=None)#
Add an output variable to the component.
For ExplicitComponent, res_ref defaults to the value in res unless otherwise specified.
- Parameters:
name (
str) – Name of the variable in this component’s namespace.val (
floatorlistortupleorndarray) – The initial value of the variable being added in user-defined units. Default is 1.0.shape (
intortupleorlistorNone) – Shape of this variable, only required if val is not an array. Default is None.units (
strorNone) – Units in which the output variables will be provided to the component during execution. Default is None, which means it has no units.res_units (
strorNone) – Units in which the residuals of this output will be given to the user when requested. Default is None, which means it has no units.desc (
str) – Description of the variable.lower (
floatorlistortupleorndarrayorNone) – Lower 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.upper (
floatorlistortupleorndarrayorNone) – Upper 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.ref (
float) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 1. Default is 1.ref0 (
float) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 0. Default is 0.res_ref (
float) – Scaling 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.tags (
strorlistofstrs) – User 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_conn (
bool) – If True, shape this output to match its connected input(s).copy_shape (
strorNone) – If a str, that str is the name of a variable. Shape this output to match that of the named variable.compute_shape (
functionorNone) – If a function, that function is called to determine the shape of this output.units_by_conn (
bool) – If True, units are computed by the connected input(s).compute_units (
functionorNone) – If a function, that function is called to determine the units of this output.copy_units (
strorNone) – If a str, that str is the name of a variable. Units this output to match that of the named variable.distributed (
bool) – If True, this variable is a distributed variable, so it can have different sizes/values across MPI processes.primal_name (
strorNone) – Valid python name to represent the variable in compute_primal if ‘name’ is not a valid python name.
- Returns:
Metadata for added variable.
- Return type:
- compute(inputs, outputs, discrete_inputs=None, discrete_outputs=None)#
Compute outputs given inputs. The model is assumed to be in an unscaled state.
An inherited component may choose to either override this function or to define a compute_primal function.
- Parameters:
inputs (
Vector) – Unscaled, dimensional input variables read via inputs[key].outputs (
Vector) – Unscaled, dimensional output variables read via outputs[key].discrete_inputs (
dict-likeorNone) – If not None, dict-like object containing discrete input values.discrete_outputs (
dict-likeorNone) – If not None, dict-like object containing discrete output values.
- compute_partials(inputs, partials, discrete_inputs=None)#
Compute sub-jacobian parts. The model is assumed to be in an unscaled state.
- 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:
inputs (
Vector) – Unscaled, dimensional input variables read via inputs[key].d_inputs (
Vector) – See inputs; product must be computed only if var_name in d_inputs.d_outputs (
Vector) – See outputs; product must be computed only if var_name in d_outputs.mode (
str) – Either ‘fwd’ or ‘rev’.discrete_inputs (
dictorNone) – If not None, dict containing discrete input values.
- is_explicit(is_comp=True)#
Return True if this is an explicit component.
- compute_fd_sparsity(method='fd', num_full_jacs=2, perturb_size=1e-09)#
Use finite difference to compute a sparsity matrix.
- Parameters:
- Returns:
The sparsity matrix.
- Return type:
coo_matrix
- setup()#
Declare inputs and outputs.
- Available attributes:
name pathname comm options
- 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.
- property checking#
Return True if check_partials or check_totals is executing.
- Returns:
True if we’re running within check_partials or check_totals.
- Return type:
- add_input(name, val=1.0, shape=None, units=None, desc='', tags=None, shape_by_conn=False, copy_shape=None, compute_shape=None, units_by_conn=False, copy_units=None, compute_units=None, require_connection=False, distributed=None, primal_name=None)#
Add an input variable to the component.
- Parameters:
name (
str) – Name of the variable in this component’s namespace.val (
floatorlistortupleorndarrayorIterable) – The initial value of the variable being added in user-defined units. Default is 1.0.shape (
intortupleorlistorNone) – Shape of this variable, only required if val is not an array. Default is None.units (
strorNone) – Units in which this input variable will be provided to the component during execution. Default is None, which means it is unitless.desc (
str) – Description of the variable.tags (
strorlistofstrs) – User defined tags that can be used to filter what gets listed when calling list_inputs and list_outputs.shape_by_conn (
bool) – If True, shape this input to match its connected output.copy_shape (
strorNone) – If a str, that str is the name of a variable. Shape this input to match that of the named variable.compute_shape (
function) – A function taking a dict arg containing names and shapes of this component’s outputs and returning the shape of this input.units_by_conn (
bool) – If True, set units of this input to match its connected output.copy_units (
strorNone) – If a str, that str is the name of a variable. Set the units of this input to match those of the named variable.compute_units (
function) – A function taking a dict arg containing names and PhysicalUnits of this component’s outputs and returning the PhysicalUnits of this input.require_connection (
bool) – If True and this input is not a design variable, it must be connected to an output.distributed (
bool) – If True, this variable is a distributed variable, so it can have different sizes/values across MPI processes.primal_name (
strorNone) – Valid python name to represent the variable in compute_primal if ‘name’ is not a valid python name.
- Returns:
Metadata for added variable.
- Return type:
- add_discrete_input(name, val, desc='', tags=None, primal_name=None)#
Add a discrete input variable to the component.
- Parameters:
name (
str) – Name of the variable in this component’s namespace.val (
a picklable object) – The initial value of the variable being added.desc (
str) – Description of the variable.tags (
strorlistofstrs) – User defined tags that can be used to filter what gets listed when calling list_inputs and list_outputs.primal_name (
strorNone) – Valid python name to represent the variable in compute_primal if ‘name’ is not a valid python name.
- Returns:
Metadata for added variable.
- Return type:
- add_discrete_output(name, val, desc='', tags=None, primal_name=None)#
Add an output variable to the component.
- Parameters:
name (
str) – Name of the variable in this component’s namespace.val (
a picklable object) – The initial value of the variable being added.desc (
str) – Description of the variable.tags (
strorlistofstrsorsetofstrs) – User defined tags that can be used to filter what gets listed when calling list_inputs and list_outputs.primal_name (
strorNone) – Valid python name to represent the variable in compute_primal if ‘name’ is not a valid python name.
- Returns:
Metadata for added variable.
- Return type:
- declare_partials(of, wrt, dependent=True, rows=None, cols=None, val=None, method='exact', step=None, form=None, step_calc=None, minimum_step=None, diagonal=None)#
Declare information about this component’s subjacobians.
- Parameters:
of (
stroriterofstr) – The name of the residual(s) that derivatives are being computed for. May also contain a glob pattern.wrt (
stroriterofstr) – The name 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.dependent (
bool(True)) – If False, specifies no dependence between the output(s) and the input(s). This is only necessary in the case of a sparse global jacobian, because if ‘dependent=False’ is not specified and declare_partials is not called for a given pair, then a dense matrix of zeros will be allocated in the sparse global jacobian for that pair. In the case of a dense global jacobian it doesn’t matter because the space for a dense subjac will always be allocated for every pair.rows (
ndarrayofintorNone) – Row indices for each nonzero entry. For sparse subjacobians only.cols (
ndarrayofintorNone) – Column indices for each nonzero entry. For sparse subjacobians only.val (
floatorndarrayoffloatorscipy.sparse) – Value of subjacobian. If rows and cols are not None, this will contain the values found at each (row, col) location in the subjac.method (
str) – The type of approximation that should be used. Valid options include: ‘fd’: Finite Difference, ‘cs’: Complex Step, ‘exact’: use the component defined analytic derivatives. Default is ‘exact’.step (
float) – Step size for approximation. Defaults to None, in which case the approximation method provides its default value.form (
str) – Form for finite difference, can be ‘forward’, ‘backward’, or ‘central’. Defaults to None, in which case the approximation method provides its default value.step_calc (
str) – Step 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 is now equivalent to ‘rel_avg’. Defaults to None, in which case the approximation method provides its default value.minimum_step (
float) – Minimum step size allowed when using one of the relative step_calc options.diagonal (
bool) – If True, the subjacobian is a diagonal matrix.
- Returns:
Metadata dict for the specified partial(s).
- Return type:
- declare_coloring(wrt=_DEFAULT_COLORING_META['wrt_patterns'], method=_DEFAULT_COLORING_META['method'], form=None, step=None, per_instance=_DEFAULT_COLORING_META['per_instance'], num_full_jacs=_DEFAULT_COLORING_META['num_full_jacs'], tol=_DEFAULT_COLORING_META['tol'], orders=_DEFAULT_COLORING_META['orders'], perturb_size=_DEFAULT_COLORING_META['perturb_size'], min_improve_pct=_DEFAULT_COLORING_META['min_improve_pct'], show_summary=_DEFAULT_COLORING_META['show_summary'], show_sparsity=_DEFAULT_COLORING_META['show_sparsity'])#
Set options for deriv coloring of a set of wrt vars matching the given pattern(s).
- Parameters:
wrt (
strorlistofstr) – The name or names of the variables that derivatives are taken with respect to. This can contain input names, output names, or glob patterns.method (
str) – Method used to compute derivative: “fd” for finite difference, “cs” for complex step.form (
str) – Finite difference form, can be “forward”, “central”, or “backward”. Leave undeclared to keep unchanged from previous or default value.step (
float) – Step size for finite difference. Leave undeclared to keep unchanged from previous or default value.per_instance (
bool) – If 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_jacs (
int) – Number of times to repeat partial jacobian computation when computing sparsity.tol (
float) – Tolerance used to determine if an array entry is nonzero during sparsity determination.orders (
int) – Number of orders above and below the tolerance to check during the tolerance sweep.perturb_size (
float) – Size of input/output perturbation during generation of sparsity.min_improve_pct (
float) – If coloring does not improve (decrease) the number of solves more than the given percentage, coloring will not be used.show_summary (
bool) – If True, display summary information after generating coloring.show_sparsity (
bool) – If True, display sparsity with coloring info after generating coloring.
- 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:
wrt (
strorlistofstr) – The 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.method (
str) – Method for check: “fd” for finite difference, “cs” for complex step.form (
str) – Finite difference form for check, can be “forward”, “central”, or “backward”. Leave undeclared to keep unchanged from previous or default value.step (
float) – Step size for finite difference check. Leave undeclared to keep unchanged from previous or default value.step_calc (
str) – Step 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 is now equivalent to ‘rel_avg’. Defaults to None, in which case the approximation method provides its default value..minimum_step (
float) – Minimum step size allowed when using one of the relative step_calc options.directional (
bool) – Set to True to perform a single directional derivative for each vector variable in the pattern named in wrt.
- compute_fd_jac(jac, method='fd')#
Force the use of finite difference to compute a jacobian.
This can be used to compute sparsity for a component that computes derivatives analytically in order to check the accuracy of the declared sparsity.
- Parameters:
jac (
Jacobian) – The Jacobian object that will contain the computed jacobian.method (
str) – The type of finite difference to perform. Valid options are ‘fd’ for forward difference, or ‘cs’ for complex step.
- check_sparsity(method='fd', max_nz=90.0, out_stream=_DEFAULT_OUT_STREAM)#
Check the sparsity of the computed jacobian against the declared sparsity.
Check is skipped if one of the dimensions of the jacobian is 1 or if the percentage of nonzeros in the computed jacobian is greater than max_nz%.
- Parameters:
method (
str) – The type of finite difference to perform. Valid options are ‘fd’ for forward difference, or ‘cs’ for complex step.max_nz (
float) – If the percentage of nonzeros in a sub-jacobian exceeds this, no warning is issued if the computed sparsity does not match the declared sparsity.out_stream (
file-like object) – Where to send the output. If None, output will be suppressed.
- Returns:
A list of tuples, one for each subjacobian that has a mismatch between the computed sparsity and the declared sparsity. Each tuple has the form (of, wrt, computed_rows, computed_cols, declared_rows, declared_cols, shape, pct_nonzero).
- Return type:
- check_partials(out_stream=_DEFAULT_OUT_STREAM, compact_print=False, abs_err_tol=0.0, rel_err_tol=1e-06, method='fd', step=None, form='forward', step_calc='abs', minimum_step=1e-12, force_dense=True, show_only_incorrect=False, show_worst=True, rich_print=True)#
Check partial derivatives comprehensively for this component.
- Parameters:
out_stream (
file-like object) – Where to send human readable output. By default it goes to stdout. Set to None to suppress.compact_print (
bool) – Set to True to just print the essentials, one line per input-output pair.abs_err_tol (
float) – Threshold value for absolute error. Errors about this value will have a ‘*’ displayed next to them in output, making them easy to search for. Default is 1.0E-6.rel_err_tol (
float) – Threshold value for relative error. Errors about this value will have a ‘*’ displayed next to them in output, making them easy to search for. Note at times there may be a significant relative error due to a minor absolute error. Default is 1.0E-6.method (
str) – Method, ‘fd’ for finite difference or ‘cs’ for complex step. Default is ‘fd’.step (
None,float, orlist/tupleoffloat) – Step size(s) for approximation. Default is None, which means 1e-6 for ‘fd’ and 1e-40 for ‘cs’.form (
str) – Form for finite difference, can be ‘forward’, ‘backward’, or ‘central’. Default ‘forward’.step_calc (
str) – Step 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 is now equivalent to ‘rel_avg’. Defaults to None, in which case the approximation method provides its default value.minimum_step (
float) – Minimum step size allowed when using one of the relative step_calc options.force_dense (
bool) – If True, analytic derivatives will be coerced into arrays. Default is True.show_only_incorrect (
bool, optional) – Set to True if output should print only the subjacs found to be incorrect.show_worst (
bool, optional) – Set to False to suppress the display of the worst subjac.rich_print (
bool, optional) – If True, print using rich if available.
- Returns:
Where derivs_dict is a dict, where the top key is the component pathname. Under the top key, the subkeys are the (of, wrt) keys of the subjacs. Within the (of, wrt) entries are the following keys: ‘tol violation’, ‘magnitude’, ‘J_fd’, ‘J_fwd’, ‘J_rev’, ‘vals_at_max_error’, and ‘rank_inconsistent’. For ‘J_fd’, ‘J_fwd’, ‘J_rev’ the value is a numpy array representing the computed Jacobian for the three different methods of computation. For ‘tol violation’ and ‘vals_at_max_error’ the value is a tuple containing values for forward - fd, reverse - fd, forward - reverse. For ‘magnitude’ the value is a tuple indicating the maximum magnitude of values found in Jfwd, Jrev, and Jfd. The boolean ‘rank_inconsistent’ indicates if the derivative wrt a serial variable is inconsistent across MPI ranks.
worst is either None or a tuple of the form (error, table_row, header) where error is the max error found, table_row is the formatted table row containing the max error, and header is the formatted table header. ‘worst’ is not None only if compact_print is True.
- Return type:
tupleofthe form (derivs_dict,worst)
- get_declare_partials_calls(sparsity=None)#
Return a string containing declare_partials() calls based on the subjac sparsity.
- name = ''#
- pathname = None#
- options#
- recording_options#
- iter_count = 0#
- iter_count_apply = 0#
- iter_count_without_approx = 0#
- cite = ''#
- matrix_free#
- under_complex_step = False#
- under_finite_difference = False#
- property comm#
Return the wrapped MPI communicator object for the system.
- Returns:
Wrapped MPI communicator object.
- Return type:
DebugComm
- property under_approx#
Return True if under complex step or finite difference.
- Returns:
True if under CS or FD.
- Return type:
- property msginfo#
Our instance pathname, if available, or our class name. For use in error messages.
- Returns:
Either our instance pathname or class name.
- Return type:
- abs_meta_iter(iotype, local=True, cont=True, discrete=False)#
Iterate over absolute variable names and their metadata for this System.
By setting appropriate values for ‘cont’ and ‘discrete’, yielded variable names can be continuous only, discrete only, or both.
- Parameters:
- Yields:
- set_output_solver_options(name, lower=_UNDEFINED, upper=_UNDEFINED, ref=_UNDEFINED, ref0=_UNDEFINED, res_ref=_UNDEFINED)#
Set solver output options.
Allows the user to set output solver options after the output has been defined and metadata set using the add_ouput method.
- Parameters:
name (
str) – Name of the variable in this system’s namespace.lower (
floatorlistortupleorndarrayorNone) – Lower 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.upper (
floatorlistortupleorndarrayorNone) – Upper 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.ref (
float) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 1. Default is 1.ref0 (
float) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 0. Default is 0.res_ref (
float) – Scaling 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.
- set_design_var_options(name, lower=_UNDEFINED, upper=_UNDEFINED, scaler=_UNDEFINED, adder=_UNDEFINED, ref=_UNDEFINED, ref0=_UNDEFINED)#
Set options for design vars in the model.
Can be used to set the options outside of setting them when calling add_design_var
- Parameters:
name (
str) – Name of the variable in this system’s namespace.lower (
floatorndarray, optional) – Lower boundary for the input.upper (
upperorndarray, optional) – Upper boundary for the input.scaler (
floatorndarray, optional) – Value 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.adder (
floatorndarray, optional) – Value 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.ref (
floatorndarray, optional) – Value of design var that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of design var that scales to 0.0 in the driver.
- set_constraint_options(name, ref=_UNDEFINED, ref0=_UNDEFINED, equals=_UNDEFINED, lower=_UNDEFINED, upper=_UNDEFINED, adder=_UNDEFINED, scaler=_UNDEFINED, alias=_UNDEFINED)#
Set options for constraints in the model.
Can be used to set options that were set using add_constraint.
- Parameters:
name (
str) – Name of the response variable in the system, or alias if given.ref (
floatorndarray, optional) – Value of response variable that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of response variable that scales to 0.0 in the driver.equals (
floatorndarray, optional) – Equality constraint value for the variable.lower (
floatorndarray, optional) – Lower boundary for the variable.upper (
floatorndarray, optional) – Upper boundary for the variable.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value 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.alias (
str, optional) – Alias for this response. Necessary when adding multiple constraints on different indices or slices of a single variable.
- set_objective_options(name, ref=_UNDEFINED, ref0=_UNDEFINED, adder=_UNDEFINED, scaler=_UNDEFINED, alias=_UNDEFINED)#
Set options for objectives in the model.
Can be used to set options after they have been set by add_objective.
- Parameters:
name (
str) – Name of the response variable in the system, or alias if given.ref (
floatorndarray, optional) – Value of response variable that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of response variable that scales to 0.0 in the driver.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value 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.alias (
str) – Alias for this response. Used to disambiguate variable names when adding multiple objectives on different indices or slices of a single variable. Deprecated.
- 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.
- use_fixed_coloring(coloring=STD_COLORING_FNAME(), recurse=True)#
Use a precomputed coloring for this System.
- uses_approx()#
Return True if the system uses approximations to compute derivatives.
- Returns:
True if the system uses approximations to compute derivatives, False otherwise.
- Return type:
- compute_sparsity(direction=None, num_iters=2, perturb_size=1e-09)#
Compute the sparsity of the partial jacobian.
- Parameters:
direction (
str) – Compute derivatives in fwd or rev mode, or whichever is based based on input and output sizes if value is None. Note that only fwd is possible when using finite difference.num_iters (
int) – Number of times to compute the full jacobian.perturb_size (
float) – Size of relative perturbation. If base value is 0.0, perturbation is absolute.
- Returns:
coo_matrix– The sparsity matrix.dict– Metadata about the sparsity computation.
- subjac_sparsity_iter(sparsity, wrt_matches=None)#
Iterate over sparsity for each subjac in the jacobian.
- Parameters:
- Yields:
- sparsity_matches_fd(direction=None, outstream=sys.stdout)#
Compare the sparsity computed by this system vs. the sparsity computed using fd.
Note that some systems use fd to compute their sparsity, so no difference will ever be found even if the sparsity is somehow incorrect.
- Parameters:
direction (
strorNone) – Compute derivatives in fwd or rev mode, or whichever is based based on input and output sizes if value is None. Note that only fwd is possible when using finite difference.outstream (
file-like) – Stream where output will be written. If None, no output will be written. The output is a text visualization of the sparsity difference.
- Returns:
True if they match, False otherwise.
- Return type:
- get_coloring_fname(mode)#
Return the full pathname to a coloring file.
- Parameters:
mode (
str) – The type of coloring file desired. Must be either ‘input’ or ‘output’.- Returns:
Full pathname of the coloring file.
- Return type:
- get_nonlinear_vectors()#
Return the inputs, outputs, and residuals vectors.
- Returns:
Yields the inputs, outputs, and residuals nonlinear vectors.
- Return type:
(inputs,outputs,residuals)
- get_linear_vectors()#
Return the linear inputs, outputs, and residuals vectors.
- Returns:
(inputs, outputs, residuals) – Yields the linear inputs, outputs, and residuals vectors.
- Return type:
tupleof<Vector> instances
- set_solver_print(level=2, depth=1e+99, type_='all', debug_print=None)#
Control printing for solvers and subsolvers in the model.
- Parameters:
level (
intorNone) – Iprint 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. A value of None will leave solving printing unchanged, which is useful when using this method to enable or disable debug printing only.depth (
int) – How 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 (
str) – Type of solver to set: ‘LN’ for linear, ‘NL’ for nonlinear, or ‘all’ for all.debug_print (
boolorNone) – If None, leave solver debug printing unchanged, otherwise turn it on or off depending on whether debug_print is True or False. Note debug_print is only applied to nonlinear solvers.
- system_iter(include_self=False, recurse=True, typ=None, depth_first=False)#
Yield a generator of local subsystems of this system.
- Parameters:
include_self (
bool) – If True, include this system in the iteration.recurse (
bool) – If True, iterate over the whole tree under this system.typ (
type) – If not None, only yield Systems that match that are instances of the given type.depth_first (
bool) – If recurse is True, this specifies whether subsystems are returned in depth-first order (if True) or bredth-first order (if False).
- Yields:
- 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:
name (
str) – Promoted name of the design variable in the system.lower (
floatorndarray, optional) – Lower boundary for the input.upper (
upperorndarray, optional) – Upper boundary for the input.ref (
floatorndarray, optional) – Value of design var that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of design var that scales to 0.0 in the driver.indices (
iterofint, optional) – If an input is an array, these indicate which entries are of interest for this particular design variable. These may be positive or negative integers.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value 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.units (
str, optional) – Units to convert to before applying scaling.parallel_deriv_color (
str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.cache_linear_solution (
bool) – If 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_indices (
bool) – If True, interpret specified indices as being indices into a flat source array.
Notes
The response can be scaled using ref and ref0. The argument
ref0represents the physical value when the scaled value is 0. The argumentrefrepresents the physical value when the scaled value is 1.
- 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, alias=None)#
Add a response variable to this system.
The response can be scaled using ref and ref0. The argument
ref0represents the physical value when the scaled value is 0. The argumentrefrepresents the physical value when the scaled value is 1.- Parameters:
name (
str) – Promoted name of the response variable in the system.type (
str) – The type of response. Supported values are ‘con’ and ‘obj’.lower (
floatorndarray, optional) – Lower boundary for the variable.upper (
upperorndarray, optional) – Upper boundary for the variable.equals (
equalsorndarray, optional) – Equality constraint value for the variable.ref (
floatorndarray, optional) – Value of response variable that scales to 1.0 in the driver.ref0 (
upperorndarray, optional) – Value of response variable that scales to 0.0 in the driver.indices (
sequenceofint, optional) – If variable is an array, these indicate which entries are of interest for this particular response.index (
int, optional) – If variable is an array, this indicates which entry is of interest for this particular response.units (
str, optional) – Units to convert to before applying scaling.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value 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.linear (
bool) – Set to True if constraint is linear. Default is False.parallel_deriv_color (
str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.cache_linear_solution (
bool) – If 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_indices (
bool) – If True, interpret specified indices as being indices into a flat source array.alias (
strorNone) – Alias for this response. Necessary when adding multiple responses on different indices of the same variable.
- 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, alias=None)#
Add a constraint variable to this system.
- Parameters:
name (
str) – Name of the response variable in the system.lower (
floatorndarray, optional) – Lower boundary for the variable.upper (
floatorndarray, optional) – Upper boundary for the variable.equals (
floatorndarray, optional) – Equality constraint value for the variable.ref (
floatorndarray, optional) – Value of response variable that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of response variable that scales to 0.0 in the driver.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alternative to using ref and ref0.units (
str, optional) – Units to convert to before applying scaling.indices (
sequenceofint, optional) – If variable is an array, these indicate which entries are of interest for this particular response. These may be positive or negative integers.linear (
bool) – Set to True if constraint is linear. Default is False.parallel_deriv_color (
str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.cache_linear_solution (
bool) – If 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_indices (
bool) – If True, interpret specified indices as being indices into a flat source array.alias (
str) – Alias for this response. Necessary when adding multiple constraints on different indices or slices of a single variable.
Notes
The response can be scaled using ref and ref0. The argument
ref0represents the physical value when the scaled value is 0. The argumentrefrepresents the physical value when the scaled value is 1. The arguments (lower,upper,equals) can not be strings or variable names.
- 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, alias=None)#
Add a response variable to this system.
- Parameters:
name (
str) – Name of the response variable in the system.ref (
floatorndarray, optional) – Value of response variable that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of response variable that scales to 0.0 in the driver.index (
int, optional) – If variable is an array, this indicates which entry is of interest for this particular response. This may be a positive or negative integer.units (
str, optional) – Units to convert to before applying scaling.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value 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_color (
str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.cache_linear_solution (
bool) – If 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_indices (
bool) – If True, interpret specified indices as being indices into a flat source array.alias (
str) – Alias for this response. Necessary when adding multiple objectives on different indices or slices of a single variable.
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} \]
- 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:
recurse (
bool) – If True, recurse through the subsystems of a group and return the path of all design vars relative to the this system.get_sizes (
bool, optional) – If True, compute the size of each design variable.use_prom_ivc (
bool) – Use promoted names for inputs, else convert to absolute source names.
- Returns:
The design variables defined in the current system and, if recurse=True, its subsystems.
- Return type:
- 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 either absolute variable name, promoted name, or alias name, depending on the value of use_prom_ivc and whether the original key was a promoted output, promoted input, or an alias.
- Parameters:
- Returns:
The responses defined in the current system and, if recurse=True, its subsystems.
- Return type:
- get_constraints(recurse=True, get_sizes=True, use_prom_ivc=True)#
Get the Constraint settings from this system.
Retrieve the constraint settings for the current system as a dict, keyed by variable name.
- Parameters:
- Returns:
The constraints defined in the current system.
- Return type:
- get_objectives(recurse=True, get_sizes=True, use_prom_ivc=True)#
Get the Objective settings from this system.
Retrieve all objectives settings from the system as a dict, keyed by variable name.
- Parameters:
- Returns:
The objectives defined in the current system.
- Return type:
- run_apply_nonlinear()#
Compute residuals.
This calls _apply_nonlinear, but with the model assumed to be in an unscaled state.
- get_io_metadata(iotypes=('input', 'output'), metadata_keys=None, includes=None, excludes=None, is_indep_var=None, is_design_var=None, tags=None, get_remote=False, rank=None, return_rel_names=True)#
Retrieve metadata for a filtered list of variables.
- Parameters:
iotypes (
stroriterofstr) – Will contain either ‘input’, ‘output’, or both. Defaults to both.metadata_keys (
iterofstrorNone) – Names 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.includes (
str,iterofstrorNone) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all variables.excludes (
str,iterofstrorNone) – Collection of glob patterns for pathnames of variables to exclude. Default is None.is_indep_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to an output tagged openmdao:indep_var. If False, list only inputs _not_ connected to outputs tagged openmdao:indep_var.is_design_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.tags (
stroriterofstrs) – User 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_remote (
bool) – If True, retrieve variables from other MPI processes as well.rank (
intorNone) – If 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_names (
bool) – If True, the names returned will be relative to the scope of this System. Otherwise they will be absolute names.
- Returns:
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, ‘prom_name’ and ‘discrete’, to indicate a given variable’s promoted name and whether or not it is discrete.
- Return type:
- list_vars(val=True, prom_name=True, residuals=False, residuals_tol=None, units=False, shape=False, global_shape=False, bounds=False, scaling=False, desc=False, print_arrays=False, tags=None, print_tags=False, includes=None, excludes=None, is_indep_var=None, is_design_var=None, all_procs=False, list_autoivcs=False, out_stream=_DEFAULT_OUT_STREAM, print_min=False, print_max=False, print_mean=False, return_format='list')#
Write a list of inputs and outputs sorted by component in execution order.
- Parameters:
val (
bool, optional) – When True, display output values. Default is True.prom_name (
bool, optional) – When True, display the promoted name of the variable. Default is True.residuals (
bool, optional) – When True, display residual values. Default is False.residuals_tol (
float, optional) – If 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.units (
bool, optional) – When True, display units. Default is False.shape (
bool, optional) – When True, display/return the shape of the value. Default is False.global_shape (
bool, optional) – When True, display/return the global shape of the value. Default is False.bounds (
bool, optional) – When True, display/return bounds (lower and upper). Default is False.scaling (
bool, optional) – When True, display/return scaling (ref, ref0, and res_ref). Default is False.desc (
bool, optional) – When True, display/return description. Default is False.print_arrays (
bool, optional) – When 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.tags (
strorlistofstrs) – User 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.print_tags (
bool) – When true, display tags in the columnar display.includes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all output variables.excludes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to exclude. Default is None.is_indep_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only outputs tagged openmdao:indep_var. If False, list only outputs that are _not_ tagged openmdao:indep_var.is_design_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.all_procs (
bool, optional) – When True, display output on all processors. Default is False.list_autoivcs (
bool) – If True, include auto_ivc outputs in the listing. Defaults to False.out_stream (
file-like) – Where to send human readable output. Default is sys.stdout. Set to None to suppress.print_min (
bool) – When true, if the output value is an array, print its smallest value.print_max (
bool) – When true, if the output value is an array, print its largest value.print_mean (
bool) – When true, if the output value is an array, print its mean value.return_format (
str) – Indicates the desired format of the return value. Can have value of ‘list’ or ‘dict’. If ‘list’, the return value is a list of (name, metadata) tuples. if ‘dict’, the return value is a dictionary mapping {name: metadata}.
- Returns:
list of (name, metadata) or dict of {name – List or dict of output names and other optional information about those outputs.
- Return type:
metadata``}``
- list_inputs(val=True, prom_name=True, units=False, shape=False, global_shape=False, desc=False, hierarchical=True, print_arrays=False, tags=None, print_tags=False, includes=None, excludes=None, is_indep_var=None, is_design_var=None, all_procs=False, out_stream=_DEFAULT_OUT_STREAM, print_min=False, print_max=False, print_mean=False, return_format='list')#
Write a list of input names and other optional information to a specified stream.
- Parameters:
val (
bool, optional) – When True, display/return input values. Default is True.prom_name (
bool, optional) – When True, display/return the promoted name of the variable. Default is True.units (
bool, optional) – When True, display/return units. Default is False.shape (
bool, optional) – When True, display/return the shape of the value. Default is False.global_shape (
bool, optional) – When True, display/return the global shape of the value. Default is False.desc (
bool, optional) – When True, display/return description. Default is False.hierarchical (
bool, optional) – When True, human readable output shows variables in hierarchical format.print_arrays (
bool, optional) – When 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.tags (
strorlistofstrs) – User 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.print_tags (
bool) – When true, display tags in the columnar display.includes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all input variables.excludes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to exclude. Default is None.is_indep_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to an output tagged openmdao:indep_var. If False, list only inputs _not_ connected to outputs tagged openmdao:indep_var.is_design_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.all_procs (
bool, optional) – When True, display output on all ranks. Default is False, which will display output only from rank 0.out_stream (
file-like object) – Where to send human readable output. Default is sys.stdout. Set to None to suppress.print_min (
bool) – When true, if the input value is an array, print its smallest value.print_max (
bool) – When true, if the input value is an array, print its largest value.print_mean (
bool) – When true, if the input value is an array, print its mean value.return_format (
str) – Indicates the desired format of the return value. Can have value of ‘list’ or ‘dict’. If ‘list’, the return value is a list of (name, metadata) tuples. if ‘dict’, the return value is a dictionary mapping {name: metadata}.
- Returns:
list of (name, metadata) or dict of {name – List or dict of input names and other optional information about those inputs.
- Return type:
metadata``}``
- list_outputs(explicit=True, implicit=True, val=True, prom_name=True, 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, print_tags=False, includes=None, excludes=None, is_indep_var=None, is_design_var=None, all_procs=False, list_autoivcs=False, out_stream=_DEFAULT_OUT_STREAM, print_min=False, print_max=False, print_mean=False, return_format='list')#
Write a list of output names and other optional information to a specified stream.
- Parameters:
explicit (
bool, optional) – Include outputs from explicit components. Default is True.implicit (
bool, optional) – Include outputs from implicit components. Default is True.val (
bool, optional) – When True, display output values. Default is True.prom_name (
bool, optional) – When True, display the promoted name of the variable. Default is True.residuals (
bool, optional) – When True, display residual values. Default is False.residuals_tol (
float, optional) – If 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.units (
bool, optional) – When True, display units. Default is False.shape (
bool, optional) – When True, display/return the shape of the value. Default is False.global_shape (
bool, optional) – When True, display/return the global shape of the value. Default is False.bounds (
bool, optional) – When True, display/return bounds (lower and upper). Default is False.scaling (
bool, optional) – When True, display/return scaling (ref, ref0, and res_ref). Default is False.desc (
bool, optional) – When True, display/return description. Default is False.hierarchical (
bool, optional) – When True, human readable output shows variables in hierarchical format.print_arrays (
bool, optional) – When 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.tags (
strorlistofstrs) – User 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.print_tags (
bool) – When true, display tags in the columnar display.includes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all output variables.excludes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to exclude. Default is None.is_indep_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only outputs tagged openmdao:indep_var. If False, list only outputs that are _not_ tagged openmdao:indep_var.is_design_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.all_procs (
bool, optional) – When True, display output on all processors. Default is False.list_autoivcs (
bool) – If True, include auto_ivc outputs in the listing. Defaults to False.out_stream (
file-like) – Where to send human readable output. Default is sys.stdout. Set to None to suppress.print_min (
bool) – When true, if the output value is an array, print its smallest value.print_max (
bool) – When true, if the output value is an array, print its largest value.print_mean (
bool) – When true, if the output value is an array, print its mean value.return_format (
str) – Indicates the desired format of the return value. Can have value of ‘list’ or ‘dict’. If ‘list’, the return value is a list of (name, metadata) tuples. if ‘dict’, the return value is a dictionary mapping {name: metadata}.
- Returns:
list of (name, metadata) or dict of {name – List or dict of output names and other optional information about those outputs.
- Return type:
metadata``}``
- list_options(include_default=True, include_solvers=True, out_stream=_DEFAULT_OUT_STREAM, return_format='list')#
Write a list of output names and other optional information to a specified stream.
- Parameters:
include_default (
bool) – When True, include the built-in openmdao system options. Default is True.include_solvers (
bool) – When True, include options from nonlinear_solver and linear_solver.out_stream (
file-like) – Where to send human readable output. Default is sys.stdout. Set to None to suppress.return_format (
str) – Indicates the desired format of the return value. Can have value of ‘list’ or ‘dict’. If ‘list’, the return value is a list of tuples of the form: (pathname, system options , nonlinear solver options, linear solver options) if ‘dict’, the return value is a dictionary with the pathname as key, and a dictionary as the value. The dictionary contains ‘options’, ‘nonlinear_solver’, and ‘linear_solver’ keys, each of which isa dictionary of options.
- Returns:
List of tuples, one for each subsystem sorted by execution order. Each tuple contains the pathname string, a dictionary of system options, a dictionary of nonlinear solver options (only if include_solvers is True) or None, and a dictionary of nonlinear solver options (only if include_solvers is True) or None.
- Return type:
- run_solve_nonlinear()#
Compute outputs.
This calls _solve_nonlinear, but with the model assumed to be in an unscaled state.
- 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.
- run_solve_linear(mode)#
Apply inverse jac product.
This calls _solve_linear, but with the model assumed to be in an unscaled state.
- Parameters:
mode (
str) – ‘fwd’ or ‘rev’.
- 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_ln (
bool) – Flag indicating if the children should call linearize on their linear solvers.
- check_config(logger)#
Perform optional error checks.
- Parameters:
logger (
object) – The object that manages logging output.
- load_model_options()#
Load the relevant model options from Problem._metadata[‘model_options’].
This method examines each path filter and corresponding options in self._problem_meta[‘model_options’]. If this System’s pathname matches the given path filter, it will assume the value for each given option which it possesses.
- add_recorder(recorder, recurse=False)#
Add a recorder to the system.
- Parameters:
recorder (
<CaseRecorder>) – A recorder instance.recurse (
bool) – Flag indicating if the recorder should be added to all the subsystems.
- record_iteration()#
Record an iteration of the current System.
- get_reports_dir()#
Get the path to the directory where the report files should go.
If it doesn’t exist, it will be created.
- Returns:
The path to the directory where reports should be written.
- Return type:
- get_outputs_dir(*subdirs, mkdir=False)#
Get the path under which all output files of this system are to be placed.
- Parameters:
- Returns:
The path of the outputs directory for the problem.
- Return type:
- cleanup()#
Clean up resources prior to exit.
- get_val(name, units=None, indices=None, get_remote=False, rank=None, vec_name='nonlinear', kind=None, flat=False, from_src=True, copy=False)#
Get an output/input/residual variable.
Function is used if you want to specify display units.
- Parameters:
name (
str) – Promoted or relative variable name in the root system’s namespace.units (
str, optional) – Units to convert to before return.indices (
intorlistofintsortupleofintsorint ndarrayorIterableorNone, optional) – Indices or slice to return.get_remote (
boolorNone) – If 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.rank (
intorNone) – If not None, only gather the value to this rank.vec_name (
str) – Name of the vector to use. Defaults to ‘nonlinear’.kind (
strorNone) – Kind of variable (‘input’, ‘output’, or ‘residual’). If None, returned value will be either an input or output.flat (
bool) – If True, return the flattened version of the value.from_src (
bool) – If True, retrieve value of an input variable from its connected source.copy (
bool, optional) – If True, return a copy of the value. If False, return a reference to the value.
- Returns:
The value of the requested output/input variable.
- Return type:
- set_val(name, val, units=None, indices=None)#
Set an input or output variable.
- convert2units(name, val, units)#
Convert the given value to the specified units.
- convert_from_units(name, val, units)#
Convert the given value from the specified units to those of the named variable.
- convert_units(name, val, units_from, units_to)#
Wrap the utility convert_units and give a good error message.
- total_local_size(io)#
Return the total local size of the given variable.
- best_partial_deriv_direction()#
Return the best direction for partial deriv calculations based on input and output sizes.
- Returns:
The best direction for derivative calculations, ‘fwd’ or ‘rev’.
- Return type:
- get_promotions(inprom=None, outprom=None)#
Return all promotions for the given promoted variable(s).
In other words, how and where did promotions occur to convert absolute variable names into the given promoted name(s) at the current System level.
- Parameters:
- Returns:
Dictionary keyed on system pathname containing input and/or output promotion lists for each System where promotions occurred to produce the given promoted variable(s).
- Return type:
- load_case(case)#
Pull all input and output variables from a Case into this System.
Override this method if the System requires special handling when loading a case.
- Parameters:
case (
Caseordict) – A Case from a CaseReader, or a dictionary with key ‘inputs’ mapped to the output of problem.model.list_inputs and key ‘outputs’ mapped to the output of prob.model.list_outputs. Both list_inputs and list_outputs should be called with prom_name=True and return_format=’dict’.
- comm_info_iter()#
Yield comm size for this system and all subsystems.
- Yields:
tuple– A tuple of the form (abs_name, comm_size).
- dist_size_iter(io, top_comm)#
Yield names and distributed ranges of all local and remote variables in this system.
- get_var_dup_info(name, io)#
Return information about how the given variable is duplicated across MPI processes.
- get_var_sizes(name, io)#
Return the sizes of the given variable on all procs.
- get_self_statics()#
Override this in derived classes if compute_primal references static values.
Do NOT include self._discrete_inputs in the returned tuple. Include things like self.options[‘opt_name’], etc., that are used in compute_primal but are assumed to be constant during derivative computation.
Return value MUST be a tuple. Don’t forget the trailing comma if tuple has only one item. Return value MUST be hashable.
The order of these values doesn’t matter. They are only checked (by computing their hash) to see if they have changed since the last time compute_primal was jitted, and if so, compute_primal will be re-jitted.
- Returns:
Tuple containing all static values required by compute_primal.
- Return type:
- run_validation()#
Run validate method on all systems below this system.
The validate method on each system can be used to check any final input / output values after a run.
- validate(inputs, outputs, discrete_inputs=None, discrete_outputs=None)#
Check any final input / output values after a run.
The model is assumed to be in an unscaled state. An inherited component may choose to either override this function or ignore it. Any errors or warnings raised in this method will be collected and all printed / raised together.
- Parameters:
inputs (
Vector) – Unscaled, dimensional input variables read via inputs[key].outputs (
Vector) – Unscaled, dimensional output variables read via outputs[key].discrete_inputs (
dict-likeorNone) – If not None, dict-like object containing discrete input values.discrete_outputs (
dict-likeorNone) – If not None, dict-like object containing discrete output values.
- class paroto.models.ModelFidelity(*args, **kwds)#
Bases:
enum.EnumModel fidelity levels.
- LOW = 'low'#
- MEDIUM = 'medium'#
- HIGH = 'high'#
- class paroto.models.ModelType(*args, **kwds)#
Bases:
enum.EnumModel types.
- EMPIRICAL = 'empirical'#
- PHYSICAL = 'physical'#
- HYBRID = 'hybrid'#
- class paroto.models.PhysicalModel(**kwargs)#
Bases:
BaseModelBase class for physical models.
Physical models are based on first principles and physical laws. They are typically more accurate but computationally expensive.
- initialize()#
Initialize with physical model type.
- to_dict()#
Serialize model to dictionary for YAML export.
- Returns:
model_dict – Model configuration as dictionary
- Return type:
- property nonlinear_solver#
Get the nonlinear solver for this system.
- property linear_solver#
Get the linear solver for this system.
- 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, compute_shape=None, units_by_conn=False, compute_units=None, copy_units=None, distributed=None, primal_name=None)#
Add an output variable to the component.
For ExplicitComponent, res_ref defaults to the value in res unless otherwise specified.
- Parameters:
name (
str) – Name of the variable in this component’s namespace.val (
floatorlistortupleorndarray) – The initial value of the variable being added in user-defined units. Default is 1.0.shape (
intortupleorlistorNone) – Shape of this variable, only required if val is not an array. Default is None.units (
strorNone) – Units in which the output variables will be provided to the component during execution. Default is None, which means it has no units.res_units (
strorNone) – Units in which the residuals of this output will be given to the user when requested. Default is None, which means it has no units.desc (
str) – Description of the variable.lower (
floatorlistortupleorndarrayorNone) – Lower 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.upper (
floatorlistortupleorndarrayorNone) – Upper 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.ref (
float) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 1. Default is 1.ref0 (
float) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 0. Default is 0.res_ref (
float) – Scaling 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.tags (
strorlistofstrs) – User 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_conn (
bool) – If True, shape this output to match its connected input(s).copy_shape (
strorNone) – If a str, that str is the name of a variable. Shape this output to match that of the named variable.compute_shape (
functionorNone) – If a function, that function is called to determine the shape of this output.units_by_conn (
bool) – If True, units are computed by the connected input(s).compute_units (
functionorNone) – If a function, that function is called to determine the units of this output.copy_units (
strorNone) – If a str, that str is the name of a variable. Units this output to match that of the named variable.distributed (
bool) – If True, this variable is a distributed variable, so it can have different sizes/values across MPI processes.primal_name (
strorNone) – Valid python name to represent the variable in compute_primal if ‘name’ is not a valid python name.
- Returns:
Metadata for added variable.
- Return type:
- compute(inputs, outputs, discrete_inputs=None, discrete_outputs=None)#
Compute outputs given inputs. The model is assumed to be in an unscaled state.
An inherited component may choose to either override this function or to define a compute_primal function.
- Parameters:
inputs (
Vector) – Unscaled, dimensional input variables read via inputs[key].outputs (
Vector) – Unscaled, dimensional output variables read via outputs[key].discrete_inputs (
dict-likeorNone) – If not None, dict-like object containing discrete input values.discrete_outputs (
dict-likeorNone) – If not None, dict-like object containing discrete output values.
- compute_partials(inputs, partials, discrete_inputs=None)#
Compute sub-jacobian parts. The model is assumed to be in an unscaled state.
- 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:
inputs (
Vector) – Unscaled, dimensional input variables read via inputs[key].d_inputs (
Vector) – See inputs; product must be computed only if var_name in d_inputs.d_outputs (
Vector) – See outputs; product must be computed only if var_name in d_outputs.mode (
str) – Either ‘fwd’ or ‘rev’.discrete_inputs (
dictorNone) – If not None, dict containing discrete input values.
- is_explicit(is_comp=True)#
Return True if this is an explicit component.
- compute_fd_sparsity(method='fd', num_full_jacs=2, perturb_size=1e-09)#
Use finite difference to compute a sparsity matrix.
- Parameters:
- Returns:
The sparsity matrix.
- Return type:
coo_matrix
- setup()#
Declare inputs and outputs.
- Available attributes:
name pathname comm options
- 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.
- property checking#
Return True if check_partials or check_totals is executing.
- Returns:
True if we’re running within check_partials or check_totals.
- Return type:
- add_input(name, val=1.0, shape=None, units=None, desc='', tags=None, shape_by_conn=False, copy_shape=None, compute_shape=None, units_by_conn=False, copy_units=None, compute_units=None, require_connection=False, distributed=None, primal_name=None)#
Add an input variable to the component.
- Parameters:
name (
str) – Name of the variable in this component’s namespace.val (
floatorlistortupleorndarrayorIterable) – The initial value of the variable being added in user-defined units. Default is 1.0.shape (
intortupleorlistorNone) – Shape of this variable, only required if val is not an array. Default is None.units (
strorNone) – Units in which this input variable will be provided to the component during execution. Default is None, which means it is unitless.desc (
str) – Description of the variable.tags (
strorlistofstrs) – User defined tags that can be used to filter what gets listed when calling list_inputs and list_outputs.shape_by_conn (
bool) – If True, shape this input to match its connected output.copy_shape (
strorNone) – If a str, that str is the name of a variable. Shape this input to match that of the named variable.compute_shape (
function) – A function taking a dict arg containing names and shapes of this component’s outputs and returning the shape of this input.units_by_conn (
bool) – If True, set units of this input to match its connected output.copy_units (
strorNone) – If a str, that str is the name of a variable. Set the units of this input to match those of the named variable.compute_units (
function) – A function taking a dict arg containing names and PhysicalUnits of this component’s outputs and returning the PhysicalUnits of this input.require_connection (
bool) – If True and this input is not a design variable, it must be connected to an output.distributed (
bool) – If True, this variable is a distributed variable, so it can have different sizes/values across MPI processes.primal_name (
strorNone) – Valid python name to represent the variable in compute_primal if ‘name’ is not a valid python name.
- Returns:
Metadata for added variable.
- Return type:
- add_discrete_input(name, val, desc='', tags=None, primal_name=None)#
Add a discrete input variable to the component.
- Parameters:
name (
str) – Name of the variable in this component’s namespace.val (
a picklable object) – The initial value of the variable being added.desc (
str) – Description of the variable.tags (
strorlistofstrs) – User defined tags that can be used to filter what gets listed when calling list_inputs and list_outputs.primal_name (
strorNone) – Valid python name to represent the variable in compute_primal if ‘name’ is not a valid python name.
- Returns:
Metadata for added variable.
- Return type:
- add_discrete_output(name, val, desc='', tags=None, primal_name=None)#
Add an output variable to the component.
- Parameters:
name (
str) – Name of the variable in this component’s namespace.val (
a picklable object) – The initial value of the variable being added.desc (
str) – Description of the variable.tags (
strorlistofstrsorsetofstrs) – User defined tags that can be used to filter what gets listed when calling list_inputs and list_outputs.primal_name (
strorNone) – Valid python name to represent the variable in compute_primal if ‘name’ is not a valid python name.
- Returns:
Metadata for added variable.
- Return type:
- declare_partials(of, wrt, dependent=True, rows=None, cols=None, val=None, method='exact', step=None, form=None, step_calc=None, minimum_step=None, diagonal=None)#
Declare information about this component’s subjacobians.
- Parameters:
of (
stroriterofstr) – The name of the residual(s) that derivatives are being computed for. May also contain a glob pattern.wrt (
stroriterofstr) – The name 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.dependent (
bool(True)) – If False, specifies no dependence between the output(s) and the input(s). This is only necessary in the case of a sparse global jacobian, because if ‘dependent=False’ is not specified and declare_partials is not called for a given pair, then a dense matrix of zeros will be allocated in the sparse global jacobian for that pair. In the case of a dense global jacobian it doesn’t matter because the space for a dense subjac will always be allocated for every pair.rows (
ndarrayofintorNone) – Row indices for each nonzero entry. For sparse subjacobians only.cols (
ndarrayofintorNone) – Column indices for each nonzero entry. For sparse subjacobians only.val (
floatorndarrayoffloatorscipy.sparse) – Value of subjacobian. If rows and cols are not None, this will contain the values found at each (row, col) location in the subjac.method (
str) – The type of approximation that should be used. Valid options include: ‘fd’: Finite Difference, ‘cs’: Complex Step, ‘exact’: use the component defined analytic derivatives. Default is ‘exact’.step (
float) – Step size for approximation. Defaults to None, in which case the approximation method provides its default value.form (
str) – Form for finite difference, can be ‘forward’, ‘backward’, or ‘central’. Defaults to None, in which case the approximation method provides its default value.step_calc (
str) – Step 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 is now equivalent to ‘rel_avg’. Defaults to None, in which case the approximation method provides its default value.minimum_step (
float) – Minimum step size allowed when using one of the relative step_calc options.diagonal (
bool) – If True, the subjacobian is a diagonal matrix.
- Returns:
Metadata dict for the specified partial(s).
- Return type:
- declare_coloring(wrt=_DEFAULT_COLORING_META['wrt_patterns'], method=_DEFAULT_COLORING_META['method'], form=None, step=None, per_instance=_DEFAULT_COLORING_META['per_instance'], num_full_jacs=_DEFAULT_COLORING_META['num_full_jacs'], tol=_DEFAULT_COLORING_META['tol'], orders=_DEFAULT_COLORING_META['orders'], perturb_size=_DEFAULT_COLORING_META['perturb_size'], min_improve_pct=_DEFAULT_COLORING_META['min_improve_pct'], show_summary=_DEFAULT_COLORING_META['show_summary'], show_sparsity=_DEFAULT_COLORING_META['show_sparsity'])#
Set options for deriv coloring of a set of wrt vars matching the given pattern(s).
- Parameters:
wrt (
strorlistofstr) – The name or names of the variables that derivatives are taken with respect to. This can contain input names, output names, or glob patterns.method (
str) – Method used to compute derivative: “fd” for finite difference, “cs” for complex step.form (
str) – Finite difference form, can be “forward”, “central”, or “backward”. Leave undeclared to keep unchanged from previous or default value.step (
float) – Step size for finite difference. Leave undeclared to keep unchanged from previous or default value.per_instance (
bool) – If 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_jacs (
int) – Number of times to repeat partial jacobian computation when computing sparsity.tol (
float) – Tolerance used to determine if an array entry is nonzero during sparsity determination.orders (
int) – Number of orders above and below the tolerance to check during the tolerance sweep.perturb_size (
float) – Size of input/output perturbation during generation of sparsity.min_improve_pct (
float) – If coloring does not improve (decrease) the number of solves more than the given percentage, coloring will not be used.show_summary (
bool) – If True, display summary information after generating coloring.show_sparsity (
bool) – If True, display sparsity with coloring info after generating coloring.
- 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:
wrt (
strorlistofstr) – The 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.method (
str) – Method for check: “fd” for finite difference, “cs” for complex step.form (
str) – Finite difference form for check, can be “forward”, “central”, or “backward”. Leave undeclared to keep unchanged from previous or default value.step (
float) – Step size for finite difference check. Leave undeclared to keep unchanged from previous or default value.step_calc (
str) – Step 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 is now equivalent to ‘rel_avg’. Defaults to None, in which case the approximation method provides its default value..minimum_step (
float) – Minimum step size allowed when using one of the relative step_calc options.directional (
bool) – Set to True to perform a single directional derivative for each vector variable in the pattern named in wrt.
- compute_fd_jac(jac, method='fd')#
Force the use of finite difference to compute a jacobian.
This can be used to compute sparsity for a component that computes derivatives analytically in order to check the accuracy of the declared sparsity.
- Parameters:
jac (
Jacobian) – The Jacobian object that will contain the computed jacobian.method (
str) – The type of finite difference to perform. Valid options are ‘fd’ for forward difference, or ‘cs’ for complex step.
- check_sparsity(method='fd', max_nz=90.0, out_stream=_DEFAULT_OUT_STREAM)#
Check the sparsity of the computed jacobian against the declared sparsity.
Check is skipped if one of the dimensions of the jacobian is 1 or if the percentage of nonzeros in the computed jacobian is greater than max_nz%.
- Parameters:
method (
str) – The type of finite difference to perform. Valid options are ‘fd’ for forward difference, or ‘cs’ for complex step.max_nz (
float) – If the percentage of nonzeros in a sub-jacobian exceeds this, no warning is issued if the computed sparsity does not match the declared sparsity.out_stream (
file-like object) – Where to send the output. If None, output will be suppressed.
- Returns:
A list of tuples, one for each subjacobian that has a mismatch between the computed sparsity and the declared sparsity. Each tuple has the form (of, wrt, computed_rows, computed_cols, declared_rows, declared_cols, shape, pct_nonzero).
- Return type:
- check_partials(out_stream=_DEFAULT_OUT_STREAM, compact_print=False, abs_err_tol=0.0, rel_err_tol=1e-06, method='fd', step=None, form='forward', step_calc='abs', minimum_step=1e-12, force_dense=True, show_only_incorrect=False, show_worst=True, rich_print=True)#
Check partial derivatives comprehensively for this component.
- Parameters:
out_stream (
file-like object) – Where to send human readable output. By default it goes to stdout. Set to None to suppress.compact_print (
bool) – Set to True to just print the essentials, one line per input-output pair.abs_err_tol (
float) – Threshold value for absolute error. Errors about this value will have a ‘*’ displayed next to them in output, making them easy to search for. Default is 1.0E-6.rel_err_tol (
float) – Threshold value for relative error. Errors about this value will have a ‘*’ displayed next to them in output, making them easy to search for. Note at times there may be a significant relative error due to a minor absolute error. Default is 1.0E-6.method (
str) – Method, ‘fd’ for finite difference or ‘cs’ for complex step. Default is ‘fd’.step (
None,float, orlist/tupleoffloat) – Step size(s) for approximation. Default is None, which means 1e-6 for ‘fd’ and 1e-40 for ‘cs’.form (
str) – Form for finite difference, can be ‘forward’, ‘backward’, or ‘central’. Default ‘forward’.step_calc (
str) – Step 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 is now equivalent to ‘rel_avg’. Defaults to None, in which case the approximation method provides its default value.minimum_step (
float) – Minimum step size allowed when using one of the relative step_calc options.force_dense (
bool) – If True, analytic derivatives will be coerced into arrays. Default is True.show_only_incorrect (
bool, optional) – Set to True if output should print only the subjacs found to be incorrect.show_worst (
bool, optional) – Set to False to suppress the display of the worst subjac.rich_print (
bool, optional) – If True, print using rich if available.
- Returns:
Where derivs_dict is a dict, where the top key is the component pathname. Under the top key, the subkeys are the (of, wrt) keys of the subjacs. Within the (of, wrt) entries are the following keys: ‘tol violation’, ‘magnitude’, ‘J_fd’, ‘J_fwd’, ‘J_rev’, ‘vals_at_max_error’, and ‘rank_inconsistent’. For ‘J_fd’, ‘J_fwd’, ‘J_rev’ the value is a numpy array representing the computed Jacobian for the three different methods of computation. For ‘tol violation’ and ‘vals_at_max_error’ the value is a tuple containing values for forward - fd, reverse - fd, forward - reverse. For ‘magnitude’ the value is a tuple indicating the maximum magnitude of values found in Jfwd, Jrev, and Jfd. The boolean ‘rank_inconsistent’ indicates if the derivative wrt a serial variable is inconsistent across MPI ranks.
worst is either None or a tuple of the form (error, table_row, header) where error is the max error found, table_row is the formatted table row containing the max error, and header is the formatted table header. ‘worst’ is not None only if compact_print is True.
- Return type:
tupleofthe form (derivs_dict,worst)
- get_declare_partials_calls(sparsity=None)#
Return a string containing declare_partials() calls based on the subjac sparsity.
- name = ''#
- pathname = None#
- options#
- recording_options#
- iter_count = 0#
- iter_count_apply = 0#
- iter_count_without_approx = 0#
- cite = ''#
- matrix_free#
- under_complex_step = False#
- under_finite_difference = False#
- property comm#
Return the wrapped MPI communicator object for the system.
- Returns:
Wrapped MPI communicator object.
- Return type:
DebugComm
- property under_approx#
Return True if under complex step or finite difference.
- Returns:
True if under CS or FD.
- Return type:
- property msginfo#
Our instance pathname, if available, or our class name. For use in error messages.
- Returns:
Either our instance pathname or class name.
- Return type:
- abs_meta_iter(iotype, local=True, cont=True, discrete=False)#
Iterate over absolute variable names and their metadata for this System.
By setting appropriate values for ‘cont’ and ‘discrete’, yielded variable names can be continuous only, discrete only, or both.
- Parameters:
- Yields:
- set_output_solver_options(name, lower=_UNDEFINED, upper=_UNDEFINED, ref=_UNDEFINED, ref0=_UNDEFINED, res_ref=_UNDEFINED)#
Set solver output options.
Allows the user to set output solver options after the output has been defined and metadata set using the add_ouput method.
- Parameters:
name (
str) – Name of the variable in this system’s namespace.lower (
floatorlistortupleorndarrayorNone) – Lower 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.upper (
floatorlistortupleorndarrayorNone) – Upper 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.ref (
float) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 1. Default is 1.ref0 (
float) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 0. Default is 0.res_ref (
float) – Scaling 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.
- set_design_var_options(name, lower=_UNDEFINED, upper=_UNDEFINED, scaler=_UNDEFINED, adder=_UNDEFINED, ref=_UNDEFINED, ref0=_UNDEFINED)#
Set options for design vars in the model.
Can be used to set the options outside of setting them when calling add_design_var
- Parameters:
name (
str) – Name of the variable in this system’s namespace.lower (
floatorndarray, optional) – Lower boundary for the input.upper (
upperorndarray, optional) – Upper boundary for the input.scaler (
floatorndarray, optional) – Value 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.adder (
floatorndarray, optional) – Value 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.ref (
floatorndarray, optional) – Value of design var that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of design var that scales to 0.0 in the driver.
- set_constraint_options(name, ref=_UNDEFINED, ref0=_UNDEFINED, equals=_UNDEFINED, lower=_UNDEFINED, upper=_UNDEFINED, adder=_UNDEFINED, scaler=_UNDEFINED, alias=_UNDEFINED)#
Set options for constraints in the model.
Can be used to set options that were set using add_constraint.
- Parameters:
name (
str) – Name of the response variable in the system, or alias if given.ref (
floatorndarray, optional) – Value of response variable that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of response variable that scales to 0.0 in the driver.equals (
floatorndarray, optional) – Equality constraint value for the variable.lower (
floatorndarray, optional) – Lower boundary for the variable.upper (
floatorndarray, optional) – Upper boundary for the variable.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value 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.alias (
str, optional) – Alias for this response. Necessary when adding multiple constraints on different indices or slices of a single variable.
- set_objective_options(name, ref=_UNDEFINED, ref0=_UNDEFINED, adder=_UNDEFINED, scaler=_UNDEFINED, alias=_UNDEFINED)#
Set options for objectives in the model.
Can be used to set options after they have been set by add_objective.
- Parameters:
name (
str) – Name of the response variable in the system, or alias if given.ref (
floatorndarray, optional) – Value of response variable that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of response variable that scales to 0.0 in the driver.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value 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.alias (
str) – Alias for this response. Used to disambiguate variable names when adding multiple objectives on different indices or slices of a single variable. Deprecated.
- 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.
- use_fixed_coloring(coloring=STD_COLORING_FNAME(), recurse=True)#
Use a precomputed coloring for this System.
- uses_approx()#
Return True if the system uses approximations to compute derivatives.
- Returns:
True if the system uses approximations to compute derivatives, False otherwise.
- Return type:
- compute_sparsity(direction=None, num_iters=2, perturb_size=1e-09)#
Compute the sparsity of the partial jacobian.
- Parameters:
direction (
str) – Compute derivatives in fwd or rev mode, or whichever is based based on input and output sizes if value is None. Note that only fwd is possible when using finite difference.num_iters (
int) – Number of times to compute the full jacobian.perturb_size (
float) – Size of relative perturbation. If base value is 0.0, perturbation is absolute.
- Returns:
coo_matrix– The sparsity matrix.dict– Metadata about the sparsity computation.
- subjac_sparsity_iter(sparsity, wrt_matches=None)#
Iterate over sparsity for each subjac in the jacobian.
- Parameters:
- Yields:
- sparsity_matches_fd(direction=None, outstream=sys.stdout)#
Compare the sparsity computed by this system vs. the sparsity computed using fd.
Note that some systems use fd to compute their sparsity, so no difference will ever be found even if the sparsity is somehow incorrect.
- Parameters:
direction (
strorNone) – Compute derivatives in fwd or rev mode, or whichever is based based on input and output sizes if value is None. Note that only fwd is possible when using finite difference.outstream (
file-like) – Stream where output will be written. If None, no output will be written. The output is a text visualization of the sparsity difference.
- Returns:
True if they match, False otherwise.
- Return type:
- get_coloring_fname(mode)#
Return the full pathname to a coloring file.
- Parameters:
mode (
str) – The type of coloring file desired. Must be either ‘input’ or ‘output’.- Returns:
Full pathname of the coloring file.
- Return type:
- get_nonlinear_vectors()#
Return the inputs, outputs, and residuals vectors.
- Returns:
Yields the inputs, outputs, and residuals nonlinear vectors.
- Return type:
(inputs,outputs,residuals)
- get_linear_vectors()#
Return the linear inputs, outputs, and residuals vectors.
- Returns:
(inputs, outputs, residuals) – Yields the linear inputs, outputs, and residuals vectors.
- Return type:
tupleof<Vector> instances
- set_solver_print(level=2, depth=1e+99, type_='all', debug_print=None)#
Control printing for solvers and subsolvers in the model.
- Parameters:
level (
intorNone) – Iprint 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. A value of None will leave solving printing unchanged, which is useful when using this method to enable or disable debug printing only.depth (
int) – How 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 (
str) – Type of solver to set: ‘LN’ for linear, ‘NL’ for nonlinear, or ‘all’ for all.debug_print (
boolorNone) – If None, leave solver debug printing unchanged, otherwise turn it on or off depending on whether debug_print is True or False. Note debug_print is only applied to nonlinear solvers.
- system_iter(include_self=False, recurse=True, typ=None, depth_first=False)#
Yield a generator of local subsystems of this system.
- Parameters:
include_self (
bool) – If True, include this system in the iteration.recurse (
bool) – If True, iterate over the whole tree under this system.typ (
type) – If not None, only yield Systems that match that are instances of the given type.depth_first (
bool) – If recurse is True, this specifies whether subsystems are returned in depth-first order (if True) or bredth-first order (if False).
- Yields:
- 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:
name (
str) – Promoted name of the design variable in the system.lower (
floatorndarray, optional) – Lower boundary for the input.upper (
upperorndarray, optional) – Upper boundary for the input.ref (
floatorndarray, optional) – Value of design var that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of design var that scales to 0.0 in the driver.indices (
iterofint, optional) – If an input is an array, these indicate which entries are of interest for this particular design variable. These may be positive or negative integers.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value 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.units (
str, optional) – Units to convert to before applying scaling.parallel_deriv_color (
str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.cache_linear_solution (
bool) – If 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_indices (
bool) – If True, interpret specified indices as being indices into a flat source array.
Notes
The response can be scaled using ref and ref0. The argument
ref0represents the physical value when the scaled value is 0. The argumentrefrepresents the physical value when the scaled value is 1.
- 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, alias=None)#
Add a response variable to this system.
The response can be scaled using ref and ref0. The argument
ref0represents the physical value when the scaled value is 0. The argumentrefrepresents the physical value when the scaled value is 1.- Parameters:
name (
str) – Promoted name of the response variable in the system.type (
str) – The type of response. Supported values are ‘con’ and ‘obj’.lower (
floatorndarray, optional) – Lower boundary for the variable.upper (
upperorndarray, optional) – Upper boundary for the variable.equals (
equalsorndarray, optional) – Equality constraint value for the variable.ref (
floatorndarray, optional) – Value of response variable that scales to 1.0 in the driver.ref0 (
upperorndarray, optional) – Value of response variable that scales to 0.0 in the driver.indices (
sequenceofint, optional) – If variable is an array, these indicate which entries are of interest for this particular response.index (
int, optional) – If variable is an array, this indicates which entry is of interest for this particular response.units (
str, optional) – Units to convert to before applying scaling.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value 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.linear (
bool) – Set to True if constraint is linear. Default is False.parallel_deriv_color (
str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.cache_linear_solution (
bool) – If 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_indices (
bool) – If True, interpret specified indices as being indices into a flat source array.alias (
strorNone) – Alias for this response. Necessary when adding multiple responses on different indices of the same variable.
- 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, alias=None)#
Add a constraint variable to this system.
- Parameters:
name (
str) – Name of the response variable in the system.lower (
floatorndarray, optional) – Lower boundary for the variable.upper (
floatorndarray, optional) – Upper boundary for the variable.equals (
floatorndarray, optional) – Equality constraint value for the variable.ref (
floatorndarray, optional) – Value of response variable that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of response variable that scales to 0.0 in the driver.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value to multiply the model value to get the scaled value for the driver. scaler is second in precedence. adder and scaler are an alternative to using ref and ref0.units (
str, optional) – Units to convert to before applying scaling.indices (
sequenceofint, optional) – If variable is an array, these indicate which entries are of interest for this particular response. These may be positive or negative integers.linear (
bool) – Set to True if constraint is linear. Default is False.parallel_deriv_color (
str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.cache_linear_solution (
bool) – If 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_indices (
bool) – If True, interpret specified indices as being indices into a flat source array.alias (
str) – Alias for this response. Necessary when adding multiple constraints on different indices or slices of a single variable.
Notes
The response can be scaled using ref and ref0. The argument
ref0represents the physical value when the scaled value is 0. The argumentrefrepresents the physical value when the scaled value is 1. The arguments (lower,upper,equals) can not be strings or variable names.
- 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, alias=None)#
Add a response variable to this system.
- Parameters:
name (
str) – Name of the response variable in the system.ref (
floatorndarray, optional) – Value of response variable that scales to 1.0 in the driver.ref0 (
floatorndarray, optional) – Value of response variable that scales to 0.0 in the driver.index (
int, optional) – If variable is an array, this indicates which entry is of interest for this particular response. This may be a positive or negative integer.units (
str, optional) – Units to convert to before applying scaling.adder (
floatorndarray, optional) – Value 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.scaler (
floatorndarray, optional) – Value 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_color (
str) – If specified, this design var will be grouped for parallel derivative calculations with other variables sharing the same parallel_deriv_color.cache_linear_solution (
bool) – If 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_indices (
bool) – If True, interpret specified indices as being indices into a flat source array.alias (
str) – Alias for this response. Necessary when adding multiple objectives on different indices or slices of a single variable.
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} \]
- 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:
recurse (
bool) – If True, recurse through the subsystems of a group and return the path of all design vars relative to the this system.get_sizes (
bool, optional) – If True, compute the size of each design variable.use_prom_ivc (
bool) – Use promoted names for inputs, else convert to absolute source names.
- Returns:
The design variables defined in the current system and, if recurse=True, its subsystems.
- Return type:
- 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 either absolute variable name, promoted name, or alias name, depending on the value of use_prom_ivc and whether the original key was a promoted output, promoted input, or an alias.
- Parameters:
- Returns:
The responses defined in the current system and, if recurse=True, its subsystems.
- Return type:
- get_constraints(recurse=True, get_sizes=True, use_prom_ivc=True)#
Get the Constraint settings from this system.
Retrieve the constraint settings for the current system as a dict, keyed by variable name.
- Parameters:
- Returns:
The constraints defined in the current system.
- Return type:
- get_objectives(recurse=True, get_sizes=True, use_prom_ivc=True)#
Get the Objective settings from this system.
Retrieve all objectives settings from the system as a dict, keyed by variable name.
- Parameters:
- Returns:
The objectives defined in the current system.
- Return type:
- run_apply_nonlinear()#
Compute residuals.
This calls _apply_nonlinear, but with the model assumed to be in an unscaled state.
- get_io_metadata(iotypes=('input', 'output'), metadata_keys=None, includes=None, excludes=None, is_indep_var=None, is_design_var=None, tags=None, get_remote=False, rank=None, return_rel_names=True)#
Retrieve metadata for a filtered list of variables.
- Parameters:
iotypes (
stroriterofstr) – Will contain either ‘input’, ‘output’, or both. Defaults to both.metadata_keys (
iterofstrorNone) – Names 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.includes (
str,iterofstrorNone) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all variables.excludes (
str,iterofstrorNone) – Collection of glob patterns for pathnames of variables to exclude. Default is None.is_indep_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to an output tagged openmdao:indep_var. If False, list only inputs _not_ connected to outputs tagged openmdao:indep_var.is_design_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.tags (
stroriterofstrs) – User 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_remote (
bool) – If True, retrieve variables from other MPI processes as well.rank (
intorNone) – If 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_names (
bool) – If True, the names returned will be relative to the scope of this System. Otherwise they will be absolute names.
- Returns:
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, ‘prom_name’ and ‘discrete’, to indicate a given variable’s promoted name and whether or not it is discrete.
- Return type:
- list_vars(val=True, prom_name=True, residuals=False, residuals_tol=None, units=False, shape=False, global_shape=False, bounds=False, scaling=False, desc=False, print_arrays=False, tags=None, print_tags=False, includes=None, excludes=None, is_indep_var=None, is_design_var=None, all_procs=False, list_autoivcs=False, out_stream=_DEFAULT_OUT_STREAM, print_min=False, print_max=False, print_mean=False, return_format='list')#
Write a list of inputs and outputs sorted by component in execution order.
- Parameters:
val (
bool, optional) – When True, display output values. Default is True.prom_name (
bool, optional) – When True, display the promoted name of the variable. Default is True.residuals (
bool, optional) – When True, display residual values. Default is False.residuals_tol (
float, optional) – If 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.units (
bool, optional) – When True, display units. Default is False.shape (
bool, optional) – When True, display/return the shape of the value. Default is False.global_shape (
bool, optional) – When True, display/return the global shape of the value. Default is False.bounds (
bool, optional) – When True, display/return bounds (lower and upper). Default is False.scaling (
bool, optional) – When True, display/return scaling (ref, ref0, and res_ref). Default is False.desc (
bool, optional) – When True, display/return description. Default is False.print_arrays (
bool, optional) – When 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.tags (
strorlistofstrs) – User 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.print_tags (
bool) – When true, display tags in the columnar display.includes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all output variables.excludes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to exclude. Default is None.is_indep_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only outputs tagged openmdao:indep_var. If False, list only outputs that are _not_ tagged openmdao:indep_var.is_design_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.all_procs (
bool, optional) – When True, display output on all processors. Default is False.list_autoivcs (
bool) – If True, include auto_ivc outputs in the listing. Defaults to False.out_stream (
file-like) – Where to send human readable output. Default is sys.stdout. Set to None to suppress.print_min (
bool) – When true, if the output value is an array, print its smallest value.print_max (
bool) – When true, if the output value is an array, print its largest value.print_mean (
bool) – When true, if the output value is an array, print its mean value.return_format (
str) – Indicates the desired format of the return value. Can have value of ‘list’ or ‘dict’. If ‘list’, the return value is a list of (name, metadata) tuples. if ‘dict’, the return value is a dictionary mapping {name: metadata}.
- Returns:
list of (name, metadata) or dict of {name – List or dict of output names and other optional information about those outputs.
- Return type:
metadata``}``
- list_inputs(val=True, prom_name=True, units=False, shape=False, global_shape=False, desc=False, hierarchical=True, print_arrays=False, tags=None, print_tags=False, includes=None, excludes=None, is_indep_var=None, is_design_var=None, all_procs=False, out_stream=_DEFAULT_OUT_STREAM, print_min=False, print_max=False, print_mean=False, return_format='list')#
Write a list of input names and other optional information to a specified stream.
- Parameters:
val (
bool, optional) – When True, display/return input values. Default is True.prom_name (
bool, optional) – When True, display/return the promoted name of the variable. Default is True.units (
bool, optional) – When True, display/return units. Default is False.shape (
bool, optional) – When True, display/return the shape of the value. Default is False.global_shape (
bool, optional) – When True, display/return the global shape of the value. Default is False.desc (
bool, optional) – When True, display/return description. Default is False.hierarchical (
bool, optional) – When True, human readable output shows variables in hierarchical format.print_arrays (
bool, optional) – When 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.tags (
strorlistofstrs) – User 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.print_tags (
bool) – When true, display tags in the columnar display.includes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all input variables.excludes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to exclude. Default is None.is_indep_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to an output tagged openmdao:indep_var. If False, list only inputs _not_ connected to outputs tagged openmdao:indep_var.is_design_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.all_procs (
bool, optional) – When True, display output on all ranks. Default is False, which will display output only from rank 0.out_stream (
file-like object) – Where to send human readable output. Default is sys.stdout. Set to None to suppress.print_min (
bool) – When true, if the input value is an array, print its smallest value.print_max (
bool) – When true, if the input value is an array, print its largest value.print_mean (
bool) – When true, if the input value is an array, print its mean value.return_format (
str) – Indicates the desired format of the return value. Can have value of ‘list’ or ‘dict’. If ‘list’, the return value is a list of (name, metadata) tuples. if ‘dict’, the return value is a dictionary mapping {name: metadata}.
- Returns:
list of (name, metadata) or dict of {name – List or dict of input names and other optional information about those inputs.
- Return type:
metadata``}``
- list_outputs(explicit=True, implicit=True, val=True, prom_name=True, 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, print_tags=False, includes=None, excludes=None, is_indep_var=None, is_design_var=None, all_procs=False, list_autoivcs=False, out_stream=_DEFAULT_OUT_STREAM, print_min=False, print_max=False, print_mean=False, return_format='list')#
Write a list of output names and other optional information to a specified stream.
- Parameters:
explicit (
bool, optional) – Include outputs from explicit components. Default is True.implicit (
bool, optional) – Include outputs from implicit components. Default is True.val (
bool, optional) – When True, display output values. Default is True.prom_name (
bool, optional) – When True, display the promoted name of the variable. Default is True.residuals (
bool, optional) – When True, display residual values. Default is False.residuals_tol (
float, optional) – If 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.units (
bool, optional) – When True, display units. Default is False.shape (
bool, optional) – When True, display/return the shape of the value. Default is False.global_shape (
bool, optional) – When True, display/return the global shape of the value. Default is False.bounds (
bool, optional) – When True, display/return bounds (lower and upper). Default is False.scaling (
bool, optional) – When True, display/return scaling (ref, ref0, and res_ref). Default is False.desc (
bool, optional) – When True, display/return description. Default is False.hierarchical (
bool, optional) – When True, human readable output shows variables in hierarchical format.print_arrays (
bool, optional) – When 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.tags (
strorlistofstrs) – User 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.print_tags (
bool) – When true, display tags in the columnar display.includes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to include. Default is None, which includes all output variables.excludes (
None,str, oriterofstr) – Collection of glob patterns for pathnames of variables to exclude. Default is None.is_indep_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only outputs tagged openmdao:indep_var. If False, list only outputs that are _not_ tagged openmdao:indep_var.is_design_var (
boolorNone) – If None (the default), do no additional filtering of the inputs. If True, list only inputs connected to outputs that are driver design variables. If False, list only inputs _not_ connected to outputs that are driver design variables.all_procs (
bool, optional) – When True, display output on all processors. Default is False.list_autoivcs (
bool) – If True, include auto_ivc outputs in the listing. Defaults to False.out_stream (
file-like) – Where to send human readable output. Default is sys.stdout. Set to None to suppress.print_min (
bool) – When true, if the output value is an array, print its smallest value.print_max (
bool) – When true, if the output value is an array, print its largest value.print_mean (
bool) – When true, if the output value is an array, print its mean value.return_format (
str) – Indicates the desired format of the return value. Can have value of ‘list’ or ‘dict’. If ‘list’, the return value is a list of (name, metadata) tuples. if ‘dict’, the return value is a dictionary mapping {name: metadata}.
- Returns:
list of (name, metadata) or dict of {name – List or dict of output names and other optional information about those outputs.
- Return type:
metadata``}``
- list_options(include_default=True, include_solvers=True, out_stream=_DEFAULT_OUT_STREAM, return_format='list')#
Write a list of output names and other optional information to a specified stream.
- Parameters:
include_default (
bool) – When True, include the built-in openmdao system options. Default is True.include_solvers (
bool) – When True, include options from nonlinear_solver and linear_solver.out_stream (
file-like) – Where to send human readable output. Default is sys.stdout. Set to None to suppress.return_format (
str) – Indicates the desired format of the return value. Can have value of ‘list’ or ‘dict’. If ‘list’, the return value is a list of tuples of the form: (pathname, system options , nonlinear solver options, linear solver options) if ‘dict’, the return value is a dictionary with the pathname as key, and a dictionary as the value. The dictionary contains ‘options’, ‘nonlinear_solver’, and ‘linear_solver’ keys, each of which isa dictionary of options.
- Returns:
List of tuples, one for each subsystem sorted by execution order. Each tuple contains the pathname string, a dictionary of system options, a dictionary of nonlinear solver options (only if include_solvers is True) or None, and a dictionary of nonlinear solver options (only if include_solvers is True) or None.
- Return type:
- run_solve_nonlinear()#
Compute outputs.
This calls _solve_nonlinear, but with the model assumed to be in an unscaled state.
- 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.
- run_solve_linear(mode)#
Apply inverse jac product.
This calls _solve_linear, but with the model assumed to be in an unscaled state.
- Parameters:
mode (
str) – ‘fwd’ or ‘rev’.
- 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_ln (
bool) – Flag indicating if the children should call linearize on their linear solvers.
- check_config(logger)#
Perform optional error checks.
- Parameters:
logger (
object) – The object that manages logging output.
- load_model_options()#
Load the relevant model options from Problem._metadata[‘model_options’].
This method examines each path filter and corresponding options in self._problem_meta[‘model_options’]. If this System’s pathname matches the given path filter, it will assume the value for each given option which it possesses.
- add_recorder(recorder, recurse=False)#
Add a recorder to the system.
- Parameters:
recorder (
<CaseRecorder>) – A recorder instance.recurse (
bool) – Flag indicating if the recorder should be added to all the subsystems.
- record_iteration()#
Record an iteration of the current System.
- get_reports_dir()#
Get the path to the directory where the report files should go.
If it doesn’t exist, it will be created.
- Returns:
The path to the directory where reports should be written.
- Return type:
- get_outputs_dir(*subdirs, mkdir=False)#
Get the path under which all output files of this system are to be placed.
- Parameters:
- Returns:
The path of the outputs directory for the problem.
- Return type:
- cleanup()#
Clean up resources prior to exit.
- get_val(name, units=None, indices=None, get_remote=False, rank=None, vec_name='nonlinear', kind=None, flat=False, from_src=True, copy=False)#
Get an output/input/residual variable.
Function is used if you want to specify display units.
- Parameters:
name (
str) – Promoted or relative variable name in the root system’s namespace.units (
str, optional) – Units to convert to before return.indices (
intorlistofintsortupleofintsorint ndarrayorIterableorNone, optional) – Indices or slice to return.get_remote (
boolorNone) – If 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.rank (
intorNone) – If not None, only gather the value to this rank.vec_name (
str) – Name of the vector to use. Defaults to ‘nonlinear’.kind (
strorNone) – Kind of variable (‘input’, ‘output’, or ‘residual’). If None, returned value will be either an input or output.flat (
bool) – If True, return the flattened version of the value.from_src (
bool) – If True, retrieve value of an input variable from its connected source.copy (
bool, optional) – If True, return a copy of the value. If False, return a reference to the value.
- Returns:
The value of the requested output/input variable.
- Return type:
- set_val(name, val, units=None, indices=None)#
Set an input or output variable.
- convert2units(name, val, units)#
Convert the given value to the specified units.
- convert_from_units(name, val, units)#
Convert the given value from the specified units to those of the named variable.
- convert_units(name, val, units_from, units_to)#
Wrap the utility convert_units and give a good error message.
- total_local_size(io)#
Return the total local size of the given variable.
- best_partial_deriv_direction()#
Return the best direction for partial deriv calculations based on input and output sizes.
- Returns:
The best direction for derivative calculations, ‘fwd’ or ‘rev’.
- Return type:
- get_promotions(inprom=None, outprom=None)#
Return all promotions for the given promoted variable(s).
In other words, how and where did promotions occur to convert absolute variable names into the given promoted name(s) at the current System level.
- Parameters:
- Returns:
Dictionary keyed on system pathname containing input and/or output promotion lists for each System where promotions occurred to produce the given promoted variable(s).
- Return type:
- load_case(case)#
Pull all input and output variables from a Case into this System.
Override this method if the System requires special handling when loading a case.
- Parameters:
case (
Caseordict) – A Case from a CaseReader, or a dictionary with key ‘inputs’ mapped to the output of problem.model.list_inputs and key ‘outputs’ mapped to the output of prob.model.list_outputs. Both list_inputs and list_outputs should be called with prom_name=True and return_format=’dict’.
- comm_info_iter()#
Yield comm size for this system and all subsystems.
- Yields:
tuple– A tuple of the form (abs_name, comm_size).
- dist_size_iter(io, top_comm)#
Yield names and distributed ranges of all local and remote variables in this system.
- get_var_dup_info(name, io)#
Return information about how the given variable is duplicated across MPI processes.
- get_var_sizes(name, io)#
Return the sizes of the given variable on all procs.
- get_self_statics()#
Override this in derived classes if compute_primal references static values.
Do NOT include self._discrete_inputs in the returned tuple. Include things like self.options[‘opt_name’], etc., that are used in compute_primal but are assumed to be constant during derivative computation.
Return value MUST be a tuple. Don’t forget the trailing comma if tuple has only one item. Return value MUST be hashable.
The order of these values doesn’t matter. They are only checked (by computing their hash) to see if they have changed since the last time compute_primal was jitted, and if so, compute_primal will be re-jitted.
- Returns:
Tuple containing all static values required by compute_primal.
- Return type:
- run_validation()#
Run validate method on all systems below this system.
The validate method on each system can be used to check any final input / output values after a run.
- validate(inputs, outputs, discrete_inputs=None, discrete_outputs=None)#
Check any final input / output values after a run.
The model is assumed to be in an unscaled state. An inherited component may choose to either override this function or ignore it. Any errors or warnings raised in this method will be collected and all printed / raised together.
- Parameters:
inputs (
Vector) – Unscaled, dimensional input variables read via inputs[key].outputs (
Vector) – Unscaled, dimensional output variables read via outputs[key].discrete_inputs (
dict-likeorNone) – If not None, dict-like object containing discrete input values.discrete_outputs (
dict-likeorNone) – If not None, dict-like object containing discrete output values.
- class paroto.models.ModelRegistry#
Registry for managing available physics models.
This class maintains a registry of all available models for different physical phenomena, allowing users to select models by name.
- classmethod register(category, model_class)#
Register a model class.
- Parameters:
category (
str) – Model category (e.g., ‘breakdown_voltage’, ‘ablation’)model_class (
Type[BaseModel]) – Model class to register
- classmethod get_model(category, model_name)#
Get a model class by category and name.
- classmethod list_models(category)#
List all models in a category.
- classmethod list_categories()#
List all available model categories.
- Returns:
categories – List of category names
- Return type:
- classmethod create_model(category, model_name, parameters=None)#
Create a model instance.
- Parameters:
- Returns:
model – Model instance
- Return type:
- Raises:
ValueError – If model not found