MCPcopy
hub / github.com/dmlc/dgl / reorder_graph

Function reorder_graph

python/dgl/transforms/functional.py:3078–3341  ·  view source on GitHub ↗

r"""Return a new graph with nodes and edges re-ordered/re-labeled according to the specified permute algorithm. Support homogeneous graph only for the moment. The re-ordering has two 2 steps: first re-order nodes and then re-order edges. For node permutation, users can re-order by

(
    g,
    node_permute_algo=None,
    edge_permute_algo="src",
    store_ids=True,
    permute_config=None,
)

Source from the content-addressed store, hash-verified

3076
3077
3078def reorder_graph(
3079 g,
3080 node_permute_algo=None,
3081 edge_permute_algo="src",
3082 store_ids=True,
3083 permute_config=None,
3084):
3085 r"""Return a new graph with nodes and edges re-ordered/re-labeled
3086 according to the specified permute algorithm.
3087
3088 Support homogeneous graph only for the moment.
3089
3090 The re-ordering has two 2 steps: first re-order nodes and then re-order edges.
3091
3092 For node permutation, users can re-order by the :attr:`node_permute_algo`
3093 argument. For edge permutation, user can re-arrange edges according to their
3094 source nodes or destination nodes by the :attr:`edge_permute_algo` argument.
3095 Some of the permutation algorithms are only implemented in CPU, so if the
3096 input graph is on GPU, it will be copied to CPU first. The storage order of
3097 the node and edge features in the graph are permuted accordingly.
3098
3099 Parameters
3100 ----------
3101 g : DGLGraph
3102 The homogeneous graph.
3103 node_permute_algo: str, optional
3104 The permutation algorithm to re-order nodes. If given, the options are ``rcmk`` or
3105 ``metis`` or ``custom``.
3106
3107 * ``None``: Keep the current node order.
3108 * ``rcmk``: Use the `Reverse Cuthill–McKee <https://docs.scipy.org/doc/scipy/reference/
3109 generated/scipy.sparse.csgraph.reverse_cuthill_mckee.html#
3110 scipy-sparse-csgraph-reverse-cuthill-mckee>`__ from ``scipy`` to generate nodes
3111 permutation.
3112 * ``metis``: Use the :func:`~dgl.metis_partition_assignment` function
3113 to partition the input graph, which gives a cluster assignment of each node.
3114 DGL then sorts the assignment array so the new node order will put nodes of
3115 the same cluster together. Please note that the generated nodes permutation
3116 of ``metis`` is non-deterministic due to algorithm&#x27;s nature.
3117 * ``custom``: Reorder the graph according to the user-provided node permutation
3118 array (provided in :attr:`permute_config`).
3119 edge_permute_algo: str, optional
3120 The permutation algorithm to reorder edges. Options are ``src`` or ``dst`` or
3121 ``custom``. ``src`` is the default value.
3122
3123 * ``src``: Edges are arranged according to their source nodes.
3124 * ``dst``: Edges are arranged according to their destination nodes.
3125 * ``custom``: Edges are arranged according to the user-provided edge permutation
3126 array (provided in :attr:`permute_config`).
3127 store_ids: bool, optional
3128 If True, DGL will store the original node and edge IDs in the ndata and edata
3129 of the resulting graph under name ``dgl.NID`` and ``dgl.EID``, respectively.
3130 permute_config: dict, optional
3131 Additional key-value config data for the specified permutation algorithm.
3132
3133 * For ``rcmk``, this argument is not required.
3134 * For ``metis``, users should specify the number of partitions ``k`` (e.g.,
3135 ``permute_config={'k':10}`` to partition the graph to 10 clusters).

Callers 9

processMethod · 0.85
processMethod · 0.85
processMethod · 0.85
processMethod · 0.85
processMethod · 0.85
processMethod · 0.85
processMethod · 0.85
processMethod · 0.85
processMethod · 0.85

Calls 13

DGLErrorClass · 0.85
rcmk_permFunction · 0.85
metis_permFunction · 0.85
formatMethod · 0.80
asnumpyMethod · 0.80
num_edgesMethod · 0.45
node_subgraphMethod · 0.45
num_nodesMethod · 0.45
cloneMethod · 0.45
copy_toMethod · 0.45
edgesMethod · 0.45
edge_subgraphMethod · 0.45

Tested by

no test coverage detected