conn_graph.py

conn_graph.py#

class openmdao.core.conn_graph.AllConnGraph(*args, backend=None, **kwargs)[source]

Bases: DiGraph

A graph for all connection info. Covers manual, implicit, and all promotions.

Every connection in the graph forms a tree structure with an absolute output name at its root and all connected absolute input names as the leaf nodes.

Node keys are tuples of the form (io, name), where io is either ‘i’ or ‘o’, and name is the name (either promoted or absolute) of a variable in the model.

src_indices are stored in the edges between nodes.

Attributes:
_mult_inconn_nodesset

A set of nodes that have multiple incoming connections.

_input_input_connsset

A set of nodes that have input to input connections.

_first_passbool

True if we’re in the first pass of node data updates.

_required_connsset

A set of input nodes that have required connections, direct or indirect, to an output node.

_resolvedset

A set of nodes that have been resolved and so can be skipped in the second pass.

_has_dynamic_shapesbool

Whether the graph has dynamic shape behavior.

_has_dynamic_unitsbool

Whether the graph has dynamic units behavior.

_dist_shapeslist or None

A list of shapes from all processes if MPI size > 1.

_dist_sizeslist or None

A list of sizes from all processes if MPI size > 1.

_dist_nodesset

A set of nodes that are distributed.

_problem_metadict or None

The metadata of the problem.

_bad_connsset or None

A set of nodes that have bad connections.

msginfostr or None

The message information for the top level System.

commMPI communicator or None

The MPI communicator for the model.

_var_existencedict or None

A dictionary of variable existence from the model.

_var_allprocs_abs2metadict or None

A dictionary of variable all processes absolute metadata from the model.

_var_allprocs_discretedict or None

A dictionary of variable all processes discrete from the model.

_var_allprocs_abs2idxdict or None

A dictionary of variable all processes absolute index from the model.

_var_abs2metadict or None

A dictionary of variable absolute metadata from the model.

_sync_auto_ivcsdict

A dictionary of auto_ivcs that require sync when setting intial values.

_dangling_prom_inputsset

A set of dangling promoted inputs.

Methods

absnames(node)

Get the absolute names associated with a node.

add_auto_ivc_nodes(model)

Add auto IVC nodes.

add_continuous_var(model, name, meta, ...)

Add a continuous variable to the graph.

add_discrete_var(model, name, meta, locmeta, io)

Add a discrete variable to the graph.

add_edge(u_of_edge, v_of_edge, **attr)

Add an edge between u and v.

add_edges_from(ebunch_to_add, **attr)

Add all the edges in ebunch_to_add.

add_group_input_defaults(group)

Add group input defaults to the graph for the given group.

add_implicit_connections(model, ...)

Add implicit connections.

add_manual_connections(group)

Add manual connections to the graph for the given group.

add_model_vars(model)

Add variable metadata to the graph.

add_node(node_for_adding, **attr)

Add a single node node_for_adding and update node attributes.

add_nodes_from(nodes_for_adding, **attr)

Add multiple nodes.

add_promotion(io, group, prom_name, subsys, ...)

Add a promotion to the graph.

add_weighted_edges_from(ebunch_to_add[, weight])

Add weighted edges in ebunch_to_add with specified weight attr

adjacency()

Returns an iterator over (node, adjacency dict) tuples for all nodes.

adjlist_inner_dict_factory

alias of dict

adjlist_outer_dict_factory

alias of dict

ambig_shapes_msg(node, children_meta)

Generate a message for an ambiguous shapes error.

ambig_units_msg(node[, incompatible])

Generate a message for an ambiguous or incompatible units error.

ambig_values_msg(node)

Generate a message for an ambiguous values error.

base_error(msg, src, tgt[, src_indices])

Return the error message for a connection error.

bfs_down_iter(node[, include_self])

Iterate down the tree from the given node.

bfs_up_iter(node[, include_self])

Iterate up the tree from the given node.

check_add_edge(group, src, tgt, **kwargs)

Check if an edge can be added to the graph and add it if it can.

check_dist_connection(model, src_node)

Check a connection starting at src where src and/or a target is distributed.

check_src_to_tgt_indirect(model, src, tgt, ...)

Check compatibility between nodes that are not directly connected.

clear()

Remove all nodes and edges from the graph.

clear_edges()

Remove all edges from the graph without altering nodes.

compute_global_shape(node)

Compute the global shape of a variable.

convert_get(node, val, src_units, tgt_units)

Convert the value for a given node based on units and indices.

convert_set(val, src_units, tgt_units[, ...])

Convert the value for a given node based on units and indices.

copy([as_view])

Returns a copy of the graph.

copy_var_shape(from_node, to_node)

Copy shape info from from_node's metadata to to_node's metadata in the graph.

create_all_conns_dict(model)

Create a dict of global connections 'owned' by a group, keyed by the group's pathname.

create_node_label(node)

Create the label for a displayed node.

display([varname, pathname, ...])

Display the connection graph.

dist2dist_fwd_shape(from_node, to_node, ...)

Compute the shape for a distributed to distributed forward connection.

dist2dist_rev_shape(from_node, to_node, ...)

Compute the shape for a distributed to distributed reverse connection.

dist2serial_fwd_shape(from_node, to_node, ...)

Compute the shape for a distributed to serial forward connection.

dist2serial_rev_shape(from_node, to_node, ...)

Compute the shape for a distributed to serial reverse connection.

drawable_edge_iter([pathname, ...])

Yield edges usable in a pydot graph.

drawable_node_iter([pathname])

Yield nodes usable in a pydot graph.

edge_attr_dict_factory

alias of dict

edge_subgraph(edges)

Returns the subgraph induced by the specified edges.

final_check(model)

Check for any errors after all updates are complete.

find_ambiguous_causes(node, causes, data_name)

Find all of the nodes that are causing the ambiguity, starting from an ambiguous node.

find_node(pathname, varname[, io])

Find a node in the graph.

gather_data(model)

Gather graph node and edge data from all processes for the given model.

get_anchored_input_node(node)

Get anchored input node.

get_conn_tree_graph(node[, inputs, outputs])

Get the connection tree graph for a given node.

get_discrete_from_children(group, node, ...)

Get the discrete flag from the children of the given node.

get_dist_offset(node, rank, flat)

Get the distributed offset and size of axis 0 of the given node.

get_dist_shapes([node])

Get the distributed shapes of a variable.

get_dist_sizes([node])

Get the distributed sizes of a variable.

get_distributed_from_children(model, node, ...)

Get the distributed flag from the children of the given node.

get_dot([pathname, varname, show_cross_boundary])

Get DOT representation of the connection graph.

get_drawable_graph([pathname, varname, ...])

Display the connection graph.

get_edge_data(u, v[, default])

Returns the attribute dictionary associated with edge (u, v).

get_node_attrs(pathname, name, io)

Get attrs from a node, adding the node if necessary.

get_parent_val_shape_units(parent, child)

Get the value, shape, and units from the parent of the given child node.

get_path_prom(node)

Get the system path and promoted name of a node.

get_root(node)

Get root.

get_shape_from_children(node, children_meta, ...)

Get the shape from the children of the given node.

get_src_index_array(abs_in)

Get the source index array for a given absolute input name.

get_subarray(arr, indices_list)

Apply a sequence of indexing operations to the input array.

get_tree_iter(node)

For any node in the graph, yield a generator of all nodes in the tree the node belongs to.

get_units_from_children(model, node, ...)

Get the units from the children of the given node.

get_val(system, name[, units, indices, ...])

Return the value of a variable.

get_val_from_children(model, node, ...)

Get the value from the children of the given node.

get_val_from_src(system, name[, units, ...])

Get val from source.

graph_attr_dict_factory

alias of dict

handle_error(going_up, src, tgt, exc)

Given an exception either raise it or save it for later.

has_edge(u, v)

Returns True if the edge (u, v) is in the graph.

has_node(n)

Returns True if the graph contains the node n.

has_predecessor(u, v)

Returns True if node u has predecessor v.

has_successor(u, v)

Returns True if node u has successor v.

inds_into_local_distrib(model, src_node, ...)

Convert indices into distributed indices and verify that they only reference local entries.

input_root(node)

Return the top input predecessor to the given node.

is_directed()

Returns True if graph is directed, False otherwise.

is_multigraph()

Returns True if graph is a multigraph, False otherwise.

leaf_input_iter(node)

Leaf input iter.

msgname(node)

Get full name of node, including absolute names if they differ from the promoted name.

nbunch_iter([nbunch])

Returns an iterator over nodes contained in nbunch that are also in the graph.

neighbors(n)

Returns an iterator over successor nodes of n.

node_attr_dict_factory

alias of dict

node_dict_factory

alias of dict

node_name(pathname, name, io)

Return the name of a node.

number_of_edges([u, v])

Returns the number of edges between two nodes.

number_of_nodes()

Returns the number of nodes in the graph.

order()

Returns the number of nodes in the graph.

predecessors(n)

Returns an iterator over predecessor nodes of n.

print_tree(name)

Print the tree of a given variable.

remove_edge(u, v)

Remove the edge between u and v.

remove_edges_from(ebunch)

Remove all edges specified in ebunch.

remove_node(n)

Remove node n.

remove_nodes_from(nodes)

Remove multiple nodes.

resolve_conn_tree(model, src_node)

Resolve the connection tree rooted at src_node.

resolve_down(model, parent, child, auto)

Update the child node's metadata based on the parent node's metadata.

resolve_from_children(model, src_node, node)

Resolve metadata from children for the given node.

resolve_input_to_input_down(model, parent, ...)

Resolve a connection between two input nodes.

resolve_output_input_connection(model, src, tgt)

Check the compatibility of a connection between an output and input node.

resolve_output_to_output_down(parent, child)

Resolve metadata for a target output node based on the metadata of a parent output node.

reverse([copy])

Returns the reverse of the graph.

serial2dist_fwd_shape(from_node, to_node, ...)

Compute the shape for a serial to distributed forward connection.

serial2dist_rev_shape(from_node, to_node, ...)

Compute the shape for a serial to distributed reverse connection.

serial2serial_fwd_shape(from_node, to_node, ...)

Compute the shape for a serial to serial connection.

serial2serial_rev_shape(from_node, to_node, ...)

Compute the shape for a serial to serial reverse connection.

serve([port, open_browser])

Serve the connection graph web UI.

set_model_meta(model, node, meta, locmeta)

Update node meta and locmete from the model.

set_subarray(arr, indices_list, val, node)

Set the val into the positions of the original array based on indices_list.

set_tree_val(model, src_node, srcval)

Set the value of a source in the tree and propagate it down the tree.

set_val(system, name, val[, units, indices])

Set the value of a variable.

setup_global_connections(model)

Compute dict of all connections between inputs and outputs.

shape_error(src, tgt, src_shape, tgt_shape)

Return an error message for a shape incompatibility.

size([weight])

Returns the number of edges or total of all edge weights.

startswith(prefix, node)

Check if the node name starts with the prefix.

subgraph(nodes)

Returns a SubGraph view of the subgraph induced on nodes.

successors(n)

Returns an iterator over successor nodes of n.

sync_auto_ivcs(model)

Synchronize auto_ivc values that require it.

to_directed([as_view])

Returns a directed representation of the graph.

to_directed_class()

Returns the class to use for empty directed copies.

to_undirected([reciprocal, as_view])

Returns an undirected representation of the digraph.

to_undirected_class()

Returns the class to use for empty undirected copies.

top_name(node)

Return the variable name relative to the top level group.

transform_input_input_connections(model)

Transform input-to-input connections into input-to-output connections.

units_error(going_up, src, tgt, src_units, ...)

Return an error message for a units incompatibility.

update([edges, nodes])

Update the graph using nodes/edges/graphs as input.

update_all_node_meta(model)

Update all node metadata for the given model.

update_dangling_prom_inputs(model)

Update dangling promoted inputs.

update_src_inds_lists(model)

Update source indices lists.

value_error(going_up, src, tgt, src_val, tgt_val)

Return an error message for a value incompatibility.

__init__(*args, **kwargs)[source]

Initialize a graph with edges, name, or graph attributes.

Parameters:
incoming_graph_datainput graph (optional, default: None)

Data to initialize graph. If None (default) an empty graph is created. The data can be an edge list, or any NetworkX graph object. If the corresponding optional Python packages are installed the data can also be a 2D NumPy array, a SciPy sparse array, or a PyGraphviz graph.

attrkeyword arguments, optional (default= no attributes)

Attributes to add to graph as key=value pairs.

See also

convert

Examples

>>> G = nx.Graph()  # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G = nx.Graph(name="my graph")
>>> e = [(1, 2), (2, 3), (3, 4)]  # list of edges
>>> G = nx.Graph(e)

Arbitrary graph attribute pairs (key=value) may be assigned

>>> G = nx.Graph(e, day="Friday")
>>> G.graph
{'day': 'Friday'}
absnames(node)[source]

Get the absolute names associated with a node.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node to get the absolute names for.

Returns:
list of str

The absolute names associated with the node.

add_auto_ivc_nodes(model)[source]

Add auto IVC nodes.

Parameters:
modelGroup

model.

Returns:
list of tuples of the form (‘o’, name)

The auto IVC nodes added.

add_continuous_var(model, name, meta, locmeta, io)[source]

Add a continuous variable to the graph.

Parameters:
modelGroup

The model.

namestr

The name of the variable.

metadict or None

The metadata of the variable.

locmetadict or None

The local metadata of the variable.

iostr

The I/O type of the variable, either ‘input’ or ‘output’.

add_discrete_var(model, name, meta, locmeta, io)[source]

Add a discrete variable to the graph.

Parameters:
modelGroup

The model.

namestr

The name of the variable.

metadict or None

The metadata of the variable.

locmetadict or None

The local metadata of the variable.

iostr

The I/O type of the variable, either ‘input’ or ‘output’.

add_group_input_defaults(group)[source]

Add group input defaults to the graph for the given group.

Parameters:
groupGroup

The group.

add_implicit_connections(model, implicit_conn_vars)[source]

Add implicit connections.

Parameters:
modelGroup

The top level group.

implicit_conn_varslist of tuples of the form (pathname, relname)

implicit conn vars.

add_manual_connections(group)[source]

Add manual connections to the graph for the given group.

Parameters:
groupGroup

The group.

add_model_vars(model)[source]

Add variable metadata to the graph.

Parameters:
modelGroup

The model.

add_promotion(io, group, prom_name, subsys, sub_prom, pinfo=None)[source]

Add a promotion to the graph.

Parameters:
iostr

The I/O type of the promotion.

groupGroup

The group.

prom_namestr

The promoted name.

subsysGroup

The subsystem.

sub_promstr

The sub promoted name.

pinfodict or None

The promotion information.

ambig_shapes_msg(node, children_meta)[source]

Generate a message for an ambiguous shapes error.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node.

children_metalist of tuples of the form (NodeAttrs, list of Indexers or None)

The children metadata and source indices.

Returns:
str

The message.

ambig_units_msg(node, incompatible=False)[source]

Generate a message for an ambiguous or incompatible units error.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node.

incompatiblebool

Whether the units are incompatible.

Returns:
any

Returned value.

ambig_values_msg(node)[source]

Generate a message for an ambiguous values error.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node.

Returns:
str

The message.

base_error(msg, src, tgt, src_indices=None)[source]

Return the error message for a connection error.

Parameters:
msgstr

msg.

srctuple of the form (‘i’ or ‘o’, name)

source.

tgttuple of the form (‘i’ or ‘o’, name)

target.

src_indicesIndexer or None

source indices.

Returns:
str

Returned value.

bfs_down_iter(node, include_self=True)[source]

Iterate down the tree from the given node.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node to start from.

include_selfbool, optional

Whether to include the given node in the iteration.

bfs_up_iter(node, include_self=True)[source]

Iterate up the tree from the given node.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node to start from.

include_selfbool, optional

Whether to include the given node in the iteration.

check_add_edge(group, src, tgt, **kwargs)[source]

Check if an edge can be added to the graph and add it if it can.

Parameters:
groupGroup

The group.

srctuple of the form (‘i’ or ‘o’, name)

The source node.

tgttuple of the form (‘i’ or ‘o’, name)

The target node.

**kwargsdict

The keyword arguments to add the edge.

check_dist_connection(model, src_node)[source]

Check a connection starting at src where src and/or a target is distributed.

Parameters:
modelGroup

The model.

src_nodetuple of the form (‘i’ or ‘o’, name)

The source node.

check_src_to_tgt_indirect(model, src, tgt, src_shape, tgt_shape)[source]

Check compatibility between nodes that are not directly connected.

Parameters:
modelGroup

model.

srctuple of the form (‘i’ or ‘o’, name)

The source node.

tgttuple of the form (‘i’ or ‘o’, name)

The target node.

src_shapetuple

The source shape.

tgt_shapetuple

The target shape.

compute_global_shape(node)[source]

Compute the global shape of a variable.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

node.

Returns:
tuple of ints

The global shape of the variable.

convert_get(node, val, src_units, tgt_units, src_inds_list=(), units=None, indices=None, get_remote=False)[source]

Convert the value for a given node based on units and indices.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node to convert the value for.

valnumpy.ndarray

The value to convert.

src_unitsstr

The source units.

tgt_unitsstr

The target units.

src_inds_listlist of Indexer

The source indices list.

unitsstr or None

The units to convert to.

indicesIndexer or None

The indices to convert.

get_remotebool

Whether to get the remote value.

Returns:
numpy.ndarray

The converted value.

convert_set(val, src_units, tgt_units, src_inds_list=(), units=None, indices=None)[source]

Convert the value for a given node based on units and indices.

Parameters:
valnumpy.ndarray

val.

src_unitsstr

The source units.

tgt_unitsstr

The target units.

src_inds_listlist of Indexer

The source indices list.

unitsstr or None

The units to convert to.

indicesIndexer or None

The indices to convert.

Returns:
any

Returned value.

copy_var_shape(from_node, to_node)[source]

Copy shape info from from_node’s metadata to to_node’s metadata in the graph.

Parameters:
from_nodetuple

Tuple containing the IO and name of the variable to copy shape info from.

to_nodetuple

Tuple containing the IO and name of the variable to copy shape info to.

Returns:
tuple or None

If the shape of the variable is known, return the shape. Otherwise, return None.

create_all_conns_dict(model)[source]

Create a dict of global connections ‘owned’ by a group, keyed by the group’s pathname.

This should only be called on the top level group.

Parameters:
modelGroup

The top level group.

Returns:
dict

A dict of connections ‘owned’ by a group, of the form {group_pathname: {abs_in: abs_out}}.

create_node_label(node)[source]

Create the label for a displayed node.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node.

Returns:
str

Returned html for the node label.

display(varname=None, pathname='', show_cross_boundary=True, outfile='graph.html')[source]

Display the connection graph.

Parameters:
varnamestr or None

Display the connection tree associated with this variable. If None, display the entire collection graph.

pathnamestr

The pathname of the system to display.

show_cross_boundarybool

Whether to show cross boundary connections.

outfilestr

The name of the file to write the graph to.

dist2dist_fwd_shape(from_node, to_node, src_inds_list, is_full_slice)[source]

Compute the shape for a distributed to distributed forward connection.

Parameters:
from_nodetuple of the form (‘i’ or ‘o’, name)

The from node.

to_nodetuple of the form (‘i’ or ‘o’, name)

The to node.

src_inds_listlist of Indexers

The source indices list.

is_full_slicebool

If True, the source is a full slice.

Returns:
tuple

The shape.

dist2dist_rev_shape(from_node, to_node, src_inds_list, is_full_slice)[source]

Compute the shape for a distributed to distributed reverse connection.

Parameters:
from_nodetuple of the form (‘i’ or ‘o’, name)

The from node.

to_nodetuple of the form (‘i’ or ‘o’, name)

The to node.

src_inds_listlist of Indexers

The source indices list.

is_full_slicebool

If True, the source is a full slice.

Returns:
tuple

The shape.

dist2serial_fwd_shape(from_node, to_node, src_inds_list, is_full_slice)[source]

Compute the shape for a distributed to serial forward connection.

Parameters:
from_nodetuple of the form (‘i’ or ‘o’, name)

The from node.

to_nodetuple of the form (‘i’ or ‘o’, name)

The to node.

src_inds_listlist of Indexers

The source indices list.

is_full_slicebool

If True, the source is a full slice.

Returns:
tuple

The shape.

dist2serial_rev_shape(from_node, to_node, src_inds_list, is_full_slice)[source]

Compute the shape for a distributed to serial reverse connection.

Parameters:
from_nodetuple of the form (‘i’ or ‘o’, name)

The from node.

to_nodetuple of the form (‘i’ or ‘o’, name)

The to node.

src_inds_listlist of Indexers

The source indices list.

is_full_slicebool

If True, the source is a full slice.

Returns:
tuple

The shape.

drawable_edge_iter(pathname='', show_cross_boundary=True, max_width=50)[source]

Yield edges usable in a pydot graph.

Parameters:
pathnamestr, optional

The pathname of the group to draw.

show_cross_boundarybool, optional

Whether to show cross boundary connections.

max_widthint or None

The maximum allowable width of an edge label.

Yields:
tuple of the form (u, v, data)

The edge and its metadata.

drawable_node_iter(pathname='')[source]

Yield nodes usable in a pydot graph.

Parameters:
pathnamestr

The pathname of the group to draw.

Yields:
tuple of the form (node, data)

The node and its metadata.

final_check(model)[source]

Check for any errors after all updates are complete.

Parameters:
modelGroup

The top level group.

find_ambiguous_causes(node, causes, data_name)[source]

Find all of the nodes that are causing the ambiguity, starting from an ambiguous node.

Parameters:
nodetuple

The node to start from.

causeslist

A list of tuples of the form (node_name, data_value).

data_namestr

The name of the data to find the causes of.

find_node(pathname, varname, io=None)[source]

Find a node in the graph.

Parameters:
pathnamestr

The current scoping system pathname.

varnamestr

The variable name to find.

iostr

The io type of the variable

Returns:
tuple of the form (io, name), where io is either ‘i’ or ‘o’.

The node found.

gather_data(model)[source]

Gather graph node and edge data from all processes for the given model.

Parameters:
modelGroup

The model.

get_anchored_input_node(node)[source]

Get anchored input node.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node to get the anchored input node for.

Returns:
tuple

The source attachment point and its predecessor.

get_conn_tree_graph(node, inputs=True, outputs=True)[source]

Get the connection tree graph for a given node.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node to get the connection tree for.

inputsbool, optional

Whether to include input nodes in the graph.

outputsbool, optional

Whether to include output nodes in the graph.

Returns:
nx.DiGraph

The connection tree graph containing all nodes connected to the given node.

get_discrete_from_children(group, node, children_meta)[source]

Get the discrete flag from the children of the given node.

Parameters:
groupGroup

The group.

nodetuple of the form (‘i’ or ‘o’, name)

The node.

children_metalist of tuples of the form (NodeAttrs, list of Indexers or None)

The children metadata and source indices.

Returns:
bool

The discrete flag from the children of the given node.

get_dist_offset(node, rank, flat)[source]

Get the distributed offset and size of axis 0 of the given node.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node.

rankint

rank.

flatbool

Whether the source is flat.

Returns:
tuple

The distributed offset and size of axis 0 of the given node.

get_dist_shapes(node=None)[source]

Get the distributed shapes of a variable.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node.

Returns:
dict or list of tuples

The full distributed shapes dict or a single entry for the given node.

get_dist_sizes(node=None)[source]

Get the distributed sizes of a variable.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node.

Returns:
dict or list of ints

The full distributed sized dict or a single entry for the given node.

get_distributed_from_children(model, node, children_meta, auto, src_distributed)[source]

Get the distributed flag from the children of the given node.

Parameters:
modelGroup

The model.

nodetuple of the form (‘i’ or ‘o’, name)

The node.

children_metalist of tuples of the form (NodeAttrs, list of Indexers or None)

The children metadata and source indices.

autobool

Whether the source node is an auto_ivc node.

src_distributedbool

Whether the source node is distributed.

Returns:
bool or None

The distributed flag from the children of the given node.

get_dot(pathname='', varname=None, show_cross_boundary=True)[source]

Get DOT representation of the connection graph.

Parameters:
pathnamestr

The pathname of the system to display.

varnamestr or None

Display the connection tree associated with this variable. If None, display the entire collection graph.

show_cross_boundarybool

Whether to show cross boundary connections.

Returns:
str

The DOT representation of the connection graph.

get_drawable_graph(pathname='', varname=None, show_cross_boundary=True)[source]

Display the connection graph.

The collection graph is a collection of connection trees. A connection tree has an absolute output at the root and absolute inputs at the leaves, with any intermediate nodes being promoted inputs and outputs.

Parameters:
pathnamestr

The pathname of the system to display.

varnamestr or None

Display the connection tree associated with this variable. If None, display the entire collection graph.

show_cross_boundarybool

Whether to show cross boundary connections.

get_node_attrs(pathname, name, io)[source]

Get attrs from a node, adding the node if necessary.

get_parent_val_shape_units(parent, child)[source]

Get the value, shape, and units from the parent of the given child node.

Parameters:
parenttuple of the form (‘i’ or ‘o’, name)

The parent node.

childtuple of the form (‘i’ or ‘o’, name)

child.

Returns:
any

The value, shape, and units from the parent of the given child node.

get_path_prom(node)[source]

Get the system path and promoted name of a node.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node.

Returns:
tuple of the form (str, str)

The system pathname and promoted name of the node relative to the system.

get_root(node)[source]

Get root.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The starting node..

Returns:
tuple of the form (‘i’ or ‘o’, name) or None

The root node.

get_shape_from_children(node, children_meta, defaults)[source]

Get the shape from the children of the given node.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node.

children_metalist of tuples of the form (NodeAttrs, list of Indexers or None)

The children metadata and source indices.

defaultsDefaults

The default metadata for the node.

Returns:
tuple or None

The shape from the children of the given node.

get_src_index_array(abs_in)[source]

Get the source index array for a given absolute input name.

Parameters:
abs_instr

The absolute input name.

Returns:
numpy.ndarray or None

The source index array or None if the input is not found.

get_subarray(arr, indices_list)[source]

Apply a sequence of indexing operations to the input array.

Parameters:
arrnumpy.ndarray

The initial array.

indices_listlist

A list of indexing objects (e.g., slices, integers, arrays for advanced indexing).

Returns:
subarraynumpy.ndarray

The result after applying all indexing operations (may be a view or copy).

get_tree_iter(node)[source]

For any node in the graph, yield a generator of all nodes in the tree the node belongs to.

The nodes are yielded in depth-first preorder.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node to get the tree for.

Yields:
tuple of the form (node, depth)

The node and its depth.

get_units_from_children(model, node, children_meta, defaults)[source]

Get the units from the children of the given node.

Parameters:
modelGroup

The model.

nodetuple of the form (‘i’ or ‘o’, name)

The node.

children_metalist of tuples of the form (NodeAttrs, list of Indexers or None)

The children metadata and source indices.

defaultsDefaults

The default metadata for the node.

Returns:
str or None

The units from the children of the given node.

get_val(system, name, units=None, indices=None, get_remote=False, rank=None, vec_name='nonlinear', kind=None, flat=False, from_src=True)[source]

Return the value of a variable.

Parameters:
systemSystem

The System requesting the value.

namestr

The name of the variable to get the value of.

unitsstr or None

The units to convert to before returning the value.

indicesint or iter of ints or None

The indices or slice to return.

get_remotebool

If True, retrieve the value even if it is on a remote process.

rankint or None

If not None, only gather the value to this rank.

vec_namestr

The name of the vector to use.

kindstr or None

The kind of variable to get the value of.

flatbool

If True, return the flattened version of the value.

from_srcbool

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

Returns:
numpy.ndarray

Returned value.

get_val_from_children(model, node, children_meta, defaults, auto)[source]

Get the value from the children of the given node.

Parameters:
modelGroup

The model.

nodetuple of the form (‘i’ or ‘o’, name)

The node.

children_metalist of tuples of the form (NodeAttrs, list of Indexers or None)

The children metadata and source indices.

defaultsDefaults

The default metadata for the node.

autobool

Whether the source node is an auto_ivc node.

Returns:
any or None

The value from the children of the given node.

get_val_from_src(system, name, units=None, indices=None, get_remote=False, rank=None, vec_name='nonlinear', kind=None, flat=False, use_vec=False, src_node=None)[source]

Get val from source.

Parameters:
systemSystem

The System requesting the value.

namestr

The name of the variable to get the value of.

unitsstr or None

The units to convert to before returning the value.

indicesint or iter of ints or None

The indices or slice to return. indices.

get_remotebool

If True, retrieve the value even if it is on a remote process.

rankint or None

If not None, only gather the value to this rank.

vec_namestr

The name of the vector to use.

kindstr or None

The kind of variable to get the value of.

flatbool

If True, return the flattened version of the value.

use_vecbool

If True, use the vector to get the value.

src_nodetuple of the form (‘i’ or ‘o’, name) or None

The source node.

Returns:
numpy.ndarray

Returned value.

handle_error(going_up, src, tgt, exc)[source]

Given an exception either raise it or save it for later.

Parameters:
going_upbool

going up.

srctuple of the form (‘i’ or ‘o’, name)

source.

tgttuple of the form (‘i’ or ‘o’, name)

target.

excException

The exception to handle.

inds_into_local_distrib(model, src_node, tgt_node, inds)[source]

Convert indices into distributed indices and verify that they only reference local entries.

Parameters:
modelModel

The model.

src_nodetuple of the form (‘i’ or ‘o’, name)

The source node.

tgt_nodetuple of the form (‘i’ or ‘o’, name)

The target node.

indslist of Indexers

The indices to convert.

Returns:
list of Indexers

The converted indices.

input_root(node)[source]

Return the top input predecessor to the given node.

Parameters:
node(str, str)

Tuple of the form (‘i’ or ‘o’, variable name)

Returns:
(str, str) or None

Node name (‘i’ or ‘o’, var name), or None.

leaf_input_iter(node)[source]

Leaf input iter.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The starting node.

Yields:
tuple of the form (‘i’ or ‘o’, name)

A leaf input node.

msgname(node)[source]

Get full name of node, including absolute names if they differ from the promoted name.

Parameters:
nodetuple or str

The node to get the full name of. Tuple of the form (io, name), where io is either ‘i’ or ‘o’, or a variable name.

Returns:
str

The full name of the node.

node_name(pathname, name, io)[source]

Return the name of a node.

Parameters:
pathnamestr

The pathname of the scoping system.

namestr

The name of the variable.

iostr

The I/O type of the variable.

Returns:
tuple of the form (‘i’ or ‘o’, name)

The node name.

print_tree(name)[source]

Print the tree of a given variable.

Parameters:
namestr

The name of the variable to print the tree of.

resolve_conn_tree(model, src_node)[source]

Resolve the connection tree rooted at src_node.

Metadata is first propagated up the tree from the absolute input nodes up to the root input node. For auto_ivc rooted trees, the propagation continues to the root auto_ivc node. Then, checking of compatability between nodes is performed from parent to child down the tree, and in some cases metadata is propagated down the tree as well.

Parameters:
modelModel

The model.

src_nodetuple

The source node. This is always an absolute output node.

resolve_down(model, parent, child, auto)[source]

Update the child node’s metadata based on the parent node’s metadata.

Parameters:
modelModel

The model.

parenttuple

The parent node.

childtuple

The target node.

autobool

Whether the source node of the connection tree is an auto_ivc node.

resolve_from_children(model, src_node, node, auto=False)[source]

Resolve metadata from children for the given node.

This propagates information up the tree from leaf inputs up to either the root input node or to the root auto_ivc node.

Parameters:
modelGroup

The model.

src_nodetuple of the form (‘i’ or ‘o’, name)

The source node.

nodetuple of the form (‘i’ or ‘o’, name)

The node.

autobool

Whether the source node is an auto_ivc node.

resolve_input_to_input_down(model, parent, child, auto)[source]

Resolve a connection between two input nodes.

Parameters:
modelModel

The model.

parenttuple of the form (‘i’, name)

The parent input node.

childtuple of the form (‘i’, name)

The child node.

autobool

Whether the source node of the connection tree is an auto_ivc node.

resolve_output_input_connection(model, src, tgt)[source]

Check the compatibility of a connection between an output and input node.

This happends when going down the tree.

Parameters:
modelGroup

The model.

srctuple of the form (‘i’ or ‘o’, name)

The source output node.

tgttuple of the form (‘i’ or ‘o’, name)

The target input node.

resolve_output_to_output_down(parent, child)[source]

Resolve metadata for a target output node based on the metadata of a parent output node.

Parameters:
modelGroup

The model.

parenttuple of the form (‘o’, name)

The source output node.

childtuple of the form (‘i’ or ‘o’, name)

The child output node.

serial2dist_fwd_shape(from_node, to_node, src_inds_list, is_full_slice)[source]

Compute the shape for a serial to distributed forward connection.

Parameters:
from_nodetuple of the form (‘i’ or ‘o’, name)

The from node.

to_nodetuple of the form (‘i’ or ‘o’, name)

The to node.

src_inds_listlist of Indexers

The source indices list.

is_full_slicebool

If True, the source is a full slice.

Returns:
tuple

The shape.

serial2dist_rev_shape(from_node, to_node, src_inds_list, is_full_slice)[source]

Compute the shape for a serial to distributed reverse connection.

Parameters:
from_nodetuple of the form (‘i’ or ‘o’, name)

The from node.

to_nodetuple of the form (‘i’ or ‘o’, name)

The to node.

src_inds_listlist of Indexers

The source indices list.

is_full_slicebool

If True, the source is a full slice.

Returns:
tuple

The shape.

serial2serial_fwd_shape(from_node, to_node, src_inds_list, is_full_slice)[source]

Compute the shape for a serial to serial connection.

Parameters:
from_nodetuple of the form (‘i’ or ‘o’, name)

The from node.

to_nodetuple of the form (‘i’ or ‘o’, name)

The to node.

src_inds_listlist of Indexers

The source indices list.

is_full_slicebool

If True, the source is a full slice.

Returns:
tuple

The shape.

serial2serial_rev_shape(from_node, to_node, src_inds_list, is_full_slice)[source]

Compute the shape for a serial to serial reverse connection.

Parameters:
from_nodetuple of the form (‘i’ or ‘o’, name)

The from node.

to_nodetuple of the form (‘i’ or ‘o’, name)

The to node.

src_inds_listlist of Indexers

The source indices list.

is_full_slicebool

If True, the source is a full slice.

Returns:
tuple

The shape.

serve(port=None, open_browser=True)[source]

Serve the connection graph web UI.

Parameters:
portint or None

The port to serve the graph on. If None, an unused port will be found.

open_browserbool

Whether to open the browser to the graph.

set_model_meta(model, node, meta, locmeta)[source]

Update node meta and locmete from the model.

Parameters:
modelGroup

The model.

nodetuple of the form (‘i’ or ‘o’, name)

The node.

metadict or None

The metadata of the node.

locmetadict or None

The local metadata of the node.

set_subarray(arr, indices_list, val, node)[source]

Set the val into the positions of the original array based on indices_list.

This function handles both views and copies by propagating changes back through the chain.

Parameters:
arrnumpy.ndarray

The original array to modify.

indices_listlist

A list of indexing objects (e.g., slices, integers, arrays for advanced indexing).

valnumpy.ndarray or compatible

The val to set (must match the shape of the final subarray).

nodetuple

The node to set the val for.

Raises:
ValueError

If the shape of val does not match the final subarray shape.

set_tree_val(model, src_node, srcval)[source]

Set the value of a source in the tree and propagate it down the tree.

Parameters:
modelModel

The model.

src_nodetuple of the form (‘i’ or ‘o’, name)

The source node.

srcvalany

The starting value to set.

set_val(system, name, val, units=None, indices=None)[source]

Set the value of a variable.

Parameters:
systemSystem

The System setting the value. system.

namestr

The name of the variable to set the value of.

valany

The value to set.

unitsstr or None

The units to convert to before setting the value.

indicesint or iter of ints or None

The indices or slice to set.

setup_global_connections(model)[source]

Compute dict of all connections between inputs and outputs.

shape_error(src, tgt, src_shape, tgt_shape)[source]

Return an error message for a shape incompatibility.

Parameters:
srctuple of the form (‘i’ or ‘o’, name)

source.

tgttuple of the form (‘i’ or ‘o’, name)

target.

src_shapetuple

source shape.

tgt_shapetuple

target shape.

Returns:
str

Returned value.

startswith(prefix, node)[source]

Check if the node name starts with the prefix.

Parameters:
prefixstr

The prefix to check.

nodetuple of the form (‘i’ or ‘o’, name)

The node to check.

Returns:
bool

True if the node name starts with the prefix, False otherwise.

sync_auto_ivcs(model)[source]

Synchronize auto_ivc values that require it.

Parameters:
modelSystem

The system containing the auto_ivcs to be synchronized.

top_name(node)[source]

Return the variable name relative to the top level group.

Parameters:
nodetuple of the form (‘i’ or ‘o’, name)

The node to get the top name for.

Returns:
str or None

The variable name relative to the top level group or None if the node is not connected.

transform_input_input_connections(model)[source]

Transform input-to-input connections into input-to-output connections.

Parameters:
modelGroup

The top level group.

units_error(going_up, src, tgt, src_units, tgt_units)[source]

Return an error message for a units incompatibility.

Parameters:
going_upbool

going up.

srctuple of the form (‘i’ or ‘o’, name)

source.

tgttuple of the form (‘i’ or ‘o’, name)

target.

src_unitsstr

source units.

tgt_unitsstr

target units.

Returns:
str

Returned value.

update_all_node_meta(model)[source]

Update all node metadata for the given model.

Parameters:
modelGroup

The model.

update_dangling_prom_inputs(model)[source]

Update dangling promoted inputs.

Parameters:
modelGroup

The top level group.

update_src_inds_lists(model)[source]

Update source indices lists.

Parameters:
modelGroup

The top level group.

value_error(going_up, src, tgt, src_val, tgt_val)[source]

Return an error message for a value incompatibility.

Parameters:
going_upbool

going up.

srctuple of the form (‘i’ or ‘o’, name)

source.

tgttuple of the form (‘i’ or ‘o’, name)

target.

src_valany

source val.

tgt_valany

target val.

Returns:
str

Returned value.

exception openmdao.core.conn_graph.ConnError(msg, ident=None)[source]

Bases: ValueError

An error raised when a connection is incompatible.

Parameters:
msgstr

The error message.

identhashable object

Identifier of the object responsible for issuing the error.

Attributes:
identhashable object

Identifier of the object responsible for issuing the error.

__init__(msg, ident=None)[source]
class openmdao.core.conn_graph.Defaults(val=None, units=None, src_shape=None)[source]

Bases: object

Container for default values of a variable.

Attributes:
valany

Default value.

unitsstr or None

Default units.

src_shapetuple or None

Default source shape.

__init__(val=None, units=None, src_shape=None)[source]
__iter__()[source]

Iterate over the attributes.

Yields:
any

The attribute value.

str or None

The units.

tuple or None

The source shape.

src_shape
units
val
class openmdao.core.conn_graph.NodeAttrs(pathname=None, rel_name=None)[source]

Bases: object

Container for per-node variable metadata used by the connection graph.

Attributes:
pathnamestr or None

The pathname of System adding the node.

rel_namestr or None

The name relative to the System adding the node.

_valany or None

The value of the node.

_shapetuple or None

The shape of the node.

_global_shapetuple or None

The global shape of the node.

_unitsstr or None

The units of the node.

_src_inds_listlist or None

The source indices list for the node.

_metadict or None

The global metadata of the node. This is always None for promoted variables nodees.

_locmetadict or None

The local metadata of the node. This is always None for promoted variables nodes.

copy_shapetuple or None

The name of the variable to copy shape from.

compute_shapetuple or None

The function to compute the shape of the node.

copy_unitsstr or None

The name of the variable to copy units from.

compute_unitsstr or None

The function to compute the units of the node.

distributedbool or None

Whether the node is distributed.

defaultsDefaults

The default values for the node.

flagsint

The flags for the node.

Methods

as_dict()

Return attributes as a dictionary, excluding internal metadata.

dist_shapes(comm)

Gather shapes from all processes in a communicator.

get(key[, default])

Get attribute by key with a default value if not found.

msgname()

Get the full message name combining pathname and relative name.

shape_from_child(node_meta, src_indices)

Get shape for a child node, accounting for defaults and src_indices.

units_from_child()

Get units, preferring defaults if available.

update(kwargs)

Update attributes from a dictionary.

update_model_meta()

Update system metadata with the metadata from this node.

val_from_child(node_meta, src_indices)

Get value for a child node, accounting for defaults and compatibility.

__getitem__(key)[source]

Get attribute by key.

Parameters:
keystr

The attribute name.

Returns:
any

The value of the attribute.

__init__(pathname=None, rel_name=None)[source]

Initialize NodeAttrs with all attributes set to None or default values.

__setitem__(key, value)[source]

Set attribute by key.

Parameters:
keystr

The attribute name.

valueany

The value to set.

property ambiguous
property ambiguous_units
property ambiguous_val
as_dict()[source]

Return attributes as a dictionary, excluding internal metadata.

Returns:
dict

A dictionary of non-None attributes excluding _meta, _locmeta, and _val.

compute_shape
compute_units
copy_shape
copy_units
defaults
property discrete
dist_shapes(comm)[source]

Gather shapes from all processes in a communicator.

Parameters:
commMPI communicator

The MPI communicator to gather from.

Returns:
list

A list of shapes from all processes if MPI size > 1, otherwise a list containing only this node’s shape.

distributed
property dyn_shape
property dyn_units
property dynamic
flags
get(key, default=None)[source]

Get attribute by key with a default value if not found.

Parameters:
keystr

The attribute name.

defaultany, optional

The default value to return if the attribute is not found.

Returns:
any

The value of the attribute or the default value.

property global_shape
property global_size
property locmeta
property meta
msgname()[source]

Get the full message name combining pathname and relative name.

Returns:
str

The full name if pathname exists, otherwise just the relative name.

pathname
rel_name
property remote
property require_connection
property shape
property shape_by_conn
shape_from_child(node_meta, src_indices)[source]

Get shape for a child node, accounting for defaults and src_indices.

Parameters:
node_metaNodeAttrs

The metadata of the child node.

src_indicesIndexer or None

The source indices applied to this node.

Returns:
tuple or None

The shape from defaults if available, None if src_indices are partial or if this node is distributed but the child is not, otherwise this node’s shape.

property size
property src_inds_list
property units
property units_by_conn
units_from_child()[source]

Get units, preferring defaults if available.

Returns:
str or None

The units from defaults if available, None if ambiguous, otherwise the node’s units.

update(kwargs)[source]

Update attributes from a dictionary.

This method is used by networkx to populate initial node attributes.

Parameters:
kwargsdict

Dictionary of attribute names and values to set.

update_model_meta()[source]

Update system metadata with the metadata from this node.

Synchronizes global and local metadata dictionaries with current node state.

property val
val_from_child(node_meta, src_indices)[source]

Get value for a child node, accounting for defaults and compatibility.

Parameters:
node_metaNodeAttrs

The metadata of the child node.

src_indicesIndexer or None

The source indices applied to this node.

Returns:
any or None

The value from defaults if available, None if ambiguous, incompatible, or if this node is distributed but the child is not, otherwise this node’s value.

openmdao.core.conn_graph.are_compatible_values(a, b, discrete, src_indices=None)[source]

Check compatibility of values a and b.

Parameters:
aany

First value to compare.

bany

Second value to compare.

discretebool

Whether the values are discrete.

src_indicesIndexer or None

The src_indices applied to a, if any.

Returns:
bool

True if a and b are compatible, False otherwise.