graph_utils.py#
Various graph related utilities.
- openmdao.utils.graph_utils.add_shape_node(graph, name, io, meta)[source]
Add a shape node to the graph.
- Parameters:
- graphnetworkx.DiGraph
Graph to add the shape node to.
- namestr
Name of the shape node.
- iostr
Input or output.
- metadict
Metadata for the variable.
- openmdao.utils.graph_utils.add_units_node(graph, name, io, meta)[source]
Add a units node to the graph.
- Parameters:
- graphnetworkx.DiGraph
Graph to add the units node to.
- namestr
Name of the units node.
- iostr
Input or output.
- metadict
Metadata for the variable.
- openmdao.utils.graph_utils.are_connected(graph, start, end)[source]
Return True if the given source and target are connected.
- Parameters:
- graphnetworkx.DiGraph
Directed graph of Systems and variables.
- startstr
Name of the starting node.
- endstr
Name of the ending node.
- Returns:
- bool
True if the given source and target are connected.
- openmdao.utils.graph_utils.get_active_edges(graph, knowns, meta_name)[source]
Return all active single edges and active multi nodes.
Active edges are those that are connected on one end to a variable with ‘known’ metadata and on the other end to a variable with ‘unknown’ metadata. Active nodes are those that have ‘unknown’ metadata but are connected to a variable with ‘known’ metadata.
Single edges correspond to ‘x_by_conn’ and ‘copy_x’ connections. Multi nodes are variables that have ‘compute_x’ set to True so they connect to multiple nodes of the opposite io type in a component. For example a ‘compute_shape’ output variable will connect to all inputs in the component and each of those edges will be labeled as ‘multi’. So a multi node is a node that has ‘multi’ incoming edges.
- Parameters:
- graphnx.DiGraph
Graph containing all variables with known/unknown info.
- knownslist of str
List of nodes with ‘known’ metadata.
- meta_namestr
The name of the node metadata to check for ‘known’/’unknown’ status.
- Returns:
- active_single_edgesset of (str, str)
Set of active ‘single’ edges (for copy_x and x_by_conn).
- computed_nodesset of str
Set of active nodes with ‘multi’ edges (for compute_x).
- openmdao.utils.graph_utils.get_cycle_tree(group)[source]
Compute the tree of cycles for the given group.
- Parameters:
- group<Group>
The specified Group.
- Returns:
- networkx.DiGraph
The component graph for the given Group.
- dict
A mapping of group path name to a tuple of the form (children, recursive_scc, unique_scc, scc_index, path, parent path or None).
- openmdao.utils.graph_utils.get_out_of_order_nodes(graph, orders)[source]
Return a list of nodes that are out of order.
- Parameters:
- graphnetworkx.DiGraph
Directed graph of Systems.
- ordersdict
A dict of order values keyed by node name.
- Returns:
- list of sets of str
A list of strongly connected components in topological order.
- list of str
A list of nodes that are out of order.
- openmdao.utils.graph_utils.get_sccs_topo(graph)[source]
Return strongly connected subsystems of the given Group in topological order.
- Parameters:
- graphnetworkx.DiGraph
Directed graph of Systems.
- Returns:
- list of sets of str
A list of strongly connected components in topological order.
- openmdao.utils.graph_utils.get_unresolved_knowns(graph, meta_name, nodes)[source]
Return all unresolved nodes with known shape.
Unresolved means that the node has known shape and at least one neighbor with unknown shape.
- Parameters:
- graphnx.DiGraph
Graph containing all variables with shape info.
- meta_namestr
The name of the node metadata variable to check.
- nodesset of str
Set of nodes to check. All nodes must be in the graph.
- Returns:
- set of str
Set of nodes with known shape but at least one neighbor with unknown shape.
- openmdao.utils.graph_utils.is_unresolved(graph, node, meta_name)[source]
Return True if the given node is unresolved.
Unresolved means that the node has at least one neighbor with unknown shape.
- Parameters:
- graphnx.DiGraph
Graph containing all variables with shape info.
- nodestr
Node to check.
- meta_namestr
The name of the node metadata variable to check.
- Returns:
- bool
True if the node is unresolved.
- openmdao.utils.graph_utils.meta2node_data(meta, to_extract)[source]
Return a dict containing select metadata for the given variable.
- Parameters:
- metadict
Metadata for the variable.
- to_extracttuple of str
Tuple of metadata names to extract.
- Returns:
- dict
Dict containing select metadata for the variable.
- openmdao.utils.graph_utils.print_cycle_tree(group)[source]
Print the tree of cycles for the given group.
- Parameters:
- group<Group>
The specified Group.