nocad.io.to_networkx#

nocad.io.to_networkx(adj, labels=None, *, annotate=True, design=None, method='path_finding', drivers=None, sensors=None, node_ids='label', layout=None, weights=None, centrality=False, robustness=False)[source]#

NetworkX digraph of a network, with the annotations as node and edge attributes.

Parameters:
adjnetwork or InputOutputDesign
labelslist of str, optional

Node names (default: names of the input graph, else x1, x2, ...).

annotatebool, default=True

Add the columns of nocad.annotation.annotate() as attributes; graph attributes hold the network-level values.

design, method, drivers, sensors, centrality, robustness

Passed to annotate().

node_ids{“label”, “index”}, default=”label”

Use the labels or the integer indices as node identifiers (the label is always stored in the label attribute).

layout{“hierarchy”, “default”, …} or ndarray of shape (N, 2), optional

Store positions as x and y node attributes.

weightsarray_like, optional

Numeric adjacency matrix; its entries are stored as the weight edge attribute.

Returns:
Gnetworkx.DiGraph

Examples

>>> from nocad.datasets import load_nocad_example
>>> G = to_networkx(load_nocad_example().adj)
>>> G.nodes["x8"]["io_role"], G.edges["x8", "x6"]["control_cactus"], G.graph["n_inputs"]
('driver', 'stem', 1)