nocad.io.from_networkx#

nocad.io.from_networkx(G, weight=None, nodes=None)[source]#

Network of state variables from a NetworkX graph.

Parameters:
Gnetworkx.DiGraph (an undirected graph is read as symmetric)
weightstr, optional

Edge attribute with the numeric values of \(a_{ij}\) (structure only if None).

nodeslist, optional

Node order (default: G.nodes()).

Returns:
netBunch with adj (sparse adjacency), labels (node names as strings),

nodes (original node objects), node_data (DataFrame of node attributes), drivers / sensors (from boolean driver / sensor attributes, if any) and weights (sparse weighted adjacency if weight is given).

Examples

>>> import networkx as nx
>>> G = nx.DiGraph([("tank1", "tank2"), ("tank2", "tank2")])
>>> net = from_networkx(G)
>>> net.labels, net.adj.toarray().astype(int).tolist()
(['tank1', 'tank2'], [[0, 1], [0, 1]])