Python networkx.OrderedMultiDiGraph() Examples
The following are 9
code examples of networkx.OrderedMultiDiGraph().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
networkx
, or try the search function
.
Example #1
Source File: utils_np_test.py From graph_nets with Apache License 2.0 | 6 votes |
def test_networkxs_to_graphs_tuple_with_none_fields(self): graph_nx = nx.OrderedMultiDiGraph() data_dict = utils_np.networkx_to_data_dict( graph_nx, node_shape_hint=None, edge_shape_hint=None) self.assertEqual(None, data_dict["edges"]) self.assertEqual(None, data_dict["globals"]) self.assertEqual(None, data_dict["nodes"]) graph_nx.add_node(0, features=None) data_dict = utils_np.networkx_to_data_dict( graph_nx, node_shape_hint=1, edge_shape_hint=None) self.assertEqual(None, data_dict["nodes"]) graph_nx.add_edge(0, 0, features=None) data_dict = utils_np.networkx_to_data_dict( graph_nx, node_shape_hint=[1], edge_shape_hint=[1]) self.assertEqual(None, data_dict["edges"]) graph_nx.graph["features"] = None utils_np.networkx_to_data_dict(graph_nx) self.assertEqual(None, data_dict["globals"])
Example #2
Source File: graph.py From mayo with MIT License | 5 votes |
def __init__(self, model): super().__init__() self.nx_graph = nx.OrderedMultiDiGraph() self._input_names = inputs = model.get('inputs', 'input') self._output_names = outputs = model.get('outputs', 'output') self._add_module(inputs, outputs, model['name'], model, []) self._optimize() self._validate() # import pdb; pdb.set_trace()
Example #3
Source File: test_ordered.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
def test_multidigraph(): G = nx.OrderedMultiDiGraph()
Example #4
Source File: test_ordered.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_multidigraph(self): G = nx.OrderedMultiDiGraph()
Example #5
Source File: test_ordered.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_multidigraph(): G = nx.OrderedMultiDiGraph()
Example #6
Source File: utils_np.py From graph_nets with Apache License 2.0 | 5 votes |
def _check_key(node_index, key): if node_index != key: raise ValueError( "Nodes of the networkx.OrderedMultiDiGraph must have sequential " "integer keys consistent with the order of the nodes (e.g. " "`list(graph_nx.nodes)[i] == i`), found node with index {} and key {}" .format(node_index, key)) return True
Example #7
Source File: utils_np.py From graph_nets with Apache License 2.0 | 5 votes |
def graphs_tuple_to_networkxs(graphs_tuple): """Converts a `graphs.GraphsTuple` to a sequence of networkx graphs. Args: graphs_tuple: A `graphs.GraphsTuple` instance containing numpy arrays. Returns: The list of `networkx.OrderedMultiDiGraph`s. The node keys will be the data dict integer node indices. """ return [ data_dict_to_networkx(x) for x in graphs_tuple_to_data_dicts(graphs_tuple) ]
Example #8
Source File: utils_np_test.py From graph_nets with Apache License 2.0 | 5 votes |
def _single_data_dict_to_networkx(data_dict): graph_nx = nx.OrderedMultiDiGraph() if data_dict["nodes"].size > 0: for i, x in enumerate(data_dict["nodes"]): graph_nx.add_node(i, features=x) if data_dict["edges"].size > 0: edge_data = zip(data_dict["senders"], data_dict["receivers"], [{ "features": x } for x in data_dict["edges"]]) graph_nx.add_edges_from(edge_data) graph_nx.graph["features"] = data_dict["globals"] return graph_nx
Example #9
Source File: utils_np.py From graph_nets with Apache License 2.0 | 4 votes |
def networkxs_to_graphs_tuple(graph_nxs, node_shape_hint=None, edge_shape_hint=None, data_type_hint=np.float32): """Constructs an instance from an iterable of networkx graphs. The networkx graph should be set up such that, for fixed shapes `node_shape`, `edge_shape` and `global_shape`: - `graph_nx.nodes(data=True)[i][-1]["features"]` is, for any node index i, a tensor of shape `node_shape`, or `None`; - `graph_nx.edges(data=True)[i][-1]["features"]` is, for any edge index i, a tensor of shape `edge_shape`, or `None`; - `graph_nx.edges(data=True)[i][-1]["index"]`, if present, defines the order in which the edges will be sorted in the resulting `data_dict`; - `graph_nx.graph["features"] is a tensor of shape `global_shape`, or `None`. The output data is a sequence of data dicts with fields: NODES, EDGES, RECEIVERS, SENDERS, GLOBALS, N_NODE, N_EDGE. Args: graph_nxs: A container of `networkx.OrderedMultiDiGraph`s. The node keys must be sequential integer values following the order in which nodes are added to the graph starting from zero. That is `list(graph_nx.nodes)[i] == i`. node_shape_hint: (iterable of `int` or `None`, default=`None`) If the graph does not contain nodes, the trailing shape for the created `NODES` field. If `None` (the default), this field is left `None`. This is not used if `graph_nx` contains at least one node. edge_shape_hint: (iterable of `int` or `None`, default=`None`) If the graph does not contain edges, the trailing shape for the created `EDGES` field. If `None` (the default), this field is left `None`. This is not used if `graph_nx` contains at least one edge. data_type_hint: (numpy dtype, default=`np.float32`) If the `NODES` or `EDGES` fields are autocompleted, their type. Returns: The instance. Raises: ValueError: If `graph_nxs` is not an iterable of networkx instances. """ data_dicts = [] try: for graph_nx in graph_nxs: data_dict = networkx_to_data_dict(graph_nx, node_shape_hint, edge_shape_hint, data_type_hint) data_dicts.append(data_dict) except TypeError: raise ValueError("Could not convert some elements of `graph_nxs`. " "Did you pass an iterable of networkx instances?") return data_dicts_to_graphs_tuple(data_dicts)