system.py

Base class for all systems in OpenMDAO.

exception openmdao.core.system.AnalysisError[source]

Bases: exceptions.Exception

This exception indicates that a possibly recoverable numerical error occurred in an analysis code or a subsolver.

class openmdao.core.system.DerivOptionsDict(read_only=True)[source]

Bases: openmdao.util.options.OptionsDictionary

Derived class that allows the default stepsize to change as you switch between fd and cs.

class openmdao.core.system.System[source]

Bases: object

Base class for systems in OpenMDAO. When building models, user should inherit from Group or Component

add_metadata(key, value)[source]

Add optional metadata to the system. This can be useful for saving data to reconstruct a run later. The CaseRecorder will save all metadata the user has associated with the system.

Args:

key : immutable

The key with which this metadata will be associated.

value

The value of metadata associated with the given key.

check_setup(out_stream=<open file '<stdout>', mode 'w'>)[source]

Write a report to the given stream indicating any potential problems found with the current configuration of this System.

Args:

out_stream : a file-like object, optional

Stream where report will be written.

cleanup()[source]

Clean up resources prior to exit.

fd_jacobian(params, unknowns, resids, total_derivs=False, fd_params=None, fd_unknowns=None, fd_states=None, pass_unknowns=(), poi_indices=None, qoi_indices=None, use_check=False, option_overrides=None)[source]

Finite difference across all unknowns in this system w.r.t. all incoming params.

Args:

params : VecWrapper

VecWrapper containing parameters. (p)

unknowns : VecWrapper

VecWrapper containing outputs and states. (u)

resids : VecWrapper

VecWrapper containing residuals. (r)

total_derivs : bool, optional

Set to true to calculate total derivatives. Otherwise, partial derivatives are returned.

fd_params : list of strings, optional

List of parameter name strings with respect to which derivatives are desired. This is used by problem to limit the derivatives that are taken.

fd_unknowns : list of strings, optional

List of output or state name strings for derivatives to be calculated. This is used by problem to limit the derivatives that are taken.

fd_states : list of strings, optional

List of state name strings for derivatives to be taken with respect to. This is used by problem to limit the derivatives that are taken.

pass_unknowns : list of strings, optional

List of outputs that are also finite difference inputs. OpenMDAO supports specifying a design variable (or slice of one) as an objective, so gradients of these are also required.

poi_indices: dict of list of integers, optional

This is a dict that contains the index values for each parameter of interest, so that we only finite difference those indices.

qoi_indices: dict of list of integers, optional

This is a dict that contains the index values for each quantity of interest, so that the finite difference is returned only for those indices.

use_check: bool

Set to True to use check_step_size, check_type, and check_form

option_overrides: dict

Dictionary of options that override the default values. The ‘check_form’, ‘check_step_size’, ‘check_step_calc’, and ‘check_type’ options are available. This is used by check_partial_derivatives.

Returns:

dict

Dictionary whose keys are tuples of the form (‘unknown’, ‘param’) and whose values are ndarrays containing the derivative for that tuple pair.

generate_docstring()[source]

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

Returns:

docstring : str

string that contains a basic numpy docstring.

get_combined_jac(J)[source]

Take a J dict that’s distributed, i.e., has different values across different MPI processes, and return a dict that contains all of the values from all of the processes. If values are duplicated, use the value from the lowest rank process. Note that J has a nested dict structure.

Args:

J : dict

Local Jacobian

Returns:

dict

Local gathered Jacobian

get_req_procs()[source]
Returns:

tuple

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

is_active()[source]
Returns:

bool

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

list_connections(group_by_comp=True, unconnected=True, var=None, stream=<open file '<stdout>', mode 'w'>)[source]

Writes out the list of all connections involving this System or any of its children. The list is of the form:

source_absolute_name (source_promoted_name) [units] -> target [units]

Where sources that broadcast to multiple targets will be replaced with a blank source for all but the first of their targets, in order to help broadcast sources visually stand out. The source name will be followed by its promoted name if it differs, and if a target is promoted it will be followed by a ‘*’, or by its promoted name if it doesn’t match the promoted name of the source, which indicates an explicit connection. Units are also included if they exist.

Sources are sorted alphabetically and targets are subsorted alphabetically when a source is broadcast to multiple targets.

Args:

group_by_comp : bool, optional

If True, show all sources and targets grouped by component. Note that this will cause repeated lines in the output since a given connection will always be from one component’s source to a different component’s target. Default is True.

unconnected : bool, optional

If True, include all unconnected params and unknowns as well. Default is True.

var : None or str, optional

If supplied, show only connections to this var. Wildcards are permitted.

stream : output stream, optional

Stream to write the connection info to. Default is sys.stdout.

list_params(stream=<open file '<stdout>', mode 'w'>)[source]

Returns a list of parameters that are unconnected, and a list of params that are only connected at a higher level of the hierarchy.

Args:

stream : output stream, optional

Stream to write the params info to. Default is sys.stdout.

Returns:

List of unconnected params, List of params connected in a higher scope.

list_states(stream=<open file '<stdout>', mode 'w'>)[source]

Recursively list all states and their initial values.

Args:

stream : output stream, optional

Stream to write the state info to. Default is sys.stdout.

list_unit_conv(stream=<open file '<stdout>', mode 'w'>)[source]

List all unit conversions that are being handled by OpenMDAO (including those with units defined only on one side of the connection.)

Args:

stream : output stream, optional

Stream to write the state info to. Default is sys.stdout.

Returns:

List of unit conversions.

post_setup(problem)[source]

User-configurable method to be run when problem.setup() just prior to the return of problem.setup().

Args:

problem : OpenMDAO.Problem

The Problem instance to which this group belongs.

pre_setup(problem)[source]

User-configurable method to be run when problem.setup() is called but prior to any actual problem setup.

Args:

problem : OpenMDAO.Problem

The Problem instance to which this group belongs.

subsystems(local=False, recurse=False, include_self=False)[source]

Returns an iterator over subsystems. For System, this is an empty list.

Args:

local : bool, optional

If True, only return those Components that are local. Default is False.

recurse : bool, optional

If True, return all Components in the system tree, subject to the value of the local arg. Default is False.

typ : type, optional

If a class is specified here, only those subsystems that are instances of that type will be returned. Default type is System.

include_self : bool, optional

If True, yield self before iterating over subsystems, assuming type of self is appropriate. Default is False.

Returns:

iterator

Iterator over subsystems.