dgl.rst 4.07 KB
Newer Older
Minjie Wang's avatar
Minjie Wang committed
1
2
3
4
5
6
.. _apidgl:

dgl
=============================

.. currentmodule:: dgl
7
8
9
.. automodule:: dgl

.. _api-graph-create-ops:
Minjie Wang's avatar
Minjie Wang committed
10
11
12
13

Graph Create Ops
-------------------------

14
15
Operators for constructing :class:`DGLGraph` from raw data formats.

Minjie Wang's avatar
Minjie Wang committed
16
17
18
19
20
21
22
23
24
25
26
27
28
.. autosummary::
    :toctree: ../../generated/

    graph
    heterograph
    from_scipy
    from_networkx
    bipartite_from_scipy
    bipartite_from_networkx
    rand_graph
    rand_bipartite
    knn_graph
    segmented_knn_graph
29
30
    create_block
    block_to_graph
Mufei Li's avatar
Mufei Li committed
31
    merge
Minjie Wang's avatar
Minjie Wang committed
32

33
34
.. _api-subgraph-extraction:

35
Subgraph Extraction Ops
Minjie Wang's avatar
Minjie Wang committed
36
37
-------------------------------------

38
39
Operators for extracting and returning subgraphs.

Minjie Wang's avatar
Minjie Wang committed
40
41
42
43
44
45
46
47
48
.. autosummary::
    :toctree: ../../generated/

    node_subgraph
    edge_subgraph
    node_type_subgraph
    edge_type_subgraph
    in_subgraph
    out_subgraph
49
50
    khop_in_subgraph
    khop_out_subgraph
Minjie Wang's avatar
Minjie Wang committed
51

52
53
54
55
56
57
.. _api-transform:

Graph Transform Ops
----------------------------------

Operators for generating new graphs by manipulating the structure of the existing ones.
Minjie Wang's avatar
Minjie Wang committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

.. autosummary::
    :toctree: ../../generated/

    add_nodes
    add_edges
    remove_nodes
    remove_edges
    add_self_loop
    remove_self_loop
    add_reverse_edges
    reverse
    to_bidirected
    to_simple
    to_block
    compact_graphs
74
75
    to_heterogeneous
    to_homogeneous
Minjie Wang's avatar
Minjie Wang committed
76
77
78
79
    to_networkx
    line_graph
    khop_graph
    metapath_reachable_graph
80
81
    adj_product_graph
    adj_sum_graph
82
    reorder_graph
83
84
    sort_csr_by_tag
    sort_csc_by_tag
Minjie Wang's avatar
Minjie Wang committed
85

86
87
88
89
90
91
92
93
94
95
96
97
98
.. _api-positional-encoding:

Graph Positional Encoding Ops:
-----------------------------------------

Operators for generating positional encodings of each node.

.. autosummary::
    :toctree: ../../generated

    random_walk_pe
    laplacian_pe

99
100
101
102
103
104
105
106
107
108
109
.. _api-partition:

Graph Partition Utilities
-------------------------
.. autosummary::
    :toctree: ../../generated/

    metis_partition
    metis_partition_assignment
    partition_graph_with_halo

110
111
112
.. _api-batch:

Batching and Reading Out Ops
Minjie Wang's avatar
Minjie Wang committed
113
114
-------------------------------

115
116
117
Operators for batching multiple graphs into one for batch processing and
operators for computing graph-level representation for both single and batched graphs.

Minjie Wang's avatar
Minjie Wang committed
118
119
120
121
122
.. autosummary::
    :toctree: ../../generated/

    batch
    unbatch
123
    slice_batch
Minjie Wang's avatar
Minjie Wang committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
    readout_nodes
    readout_edges
    sum_nodes
    sum_edges
    mean_nodes
    mean_edges
    max_nodes
    max_edges
    softmax_nodes
    softmax_edges
    broadcast_nodes
    broadcast_edges
    topk_nodes
    topk_edges

139
Adjacency Related Utilities
Minjie Wang's avatar
Minjie Wang committed
140
141
-------------------------------

142
143
Utilities for computing adjacency matrix and Lapacian matrix.

Minjie Wang's avatar
Minjie Wang committed
144
145
146
147
148
149
.. autosummary::
    :toctree: ../../generated/

    khop_adj
    laplacian_lambda_max

150
Graph Traversal & Message Propagation
Minjie Wang's avatar
Minjie Wang committed
151
152
------------------------------------------

153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
DGL implements graph traversal algorithms implemented as python generators,
which returns the visited set of nodes or edges (in ID tensor) at each iteration.
The naming convention is ``<algorithm>_[nodes|edges]_generator``.
An example usage is as follows.

.. code:: python

    g = ...  # some DGLGraph
    for nodes in dgl.bfs_nodes_generator(g, 0):
        do_something(nodes)

.. autosummary::
    :toctree: ../../generated/

    bfs_nodes_generator
    bfs_edges_generator
    topological_nodes_generator
    dfs_edges_generator
    dfs_labeled_edges_generator

DGL provides APIs to perform message passing following graph traversal order. ``prop_nodes_XXX``
calls traversal algorithm ``XXX`` and triggers :func:`~DGLGraph.pull()` on the visited node
set at each iteration. ``prop_edges_YYY`` applies traversal algorithm ``YYY`` and triggers
:func:`~DGLGraph.send_and_recv()` on the visited edge set at each iteration.
177

Minjie Wang's avatar
Minjie Wang committed
178
179
180
181
182
183
184
185
186
187
188
.. autosummary::
    :toctree: ../../generated/

    prop_nodes
    prop_nodes_bfs
    prop_nodes_topo
    prop_edges
    prop_edges_dfs

Utilities
-----------------------------------------------
189

190
191
Other utilities for controlling randomness, saving and loading graphs, functions that applies
the same function to every elements in a container, etc.
192

Minjie Wang's avatar
Minjie Wang committed
193
194
195
196
.. autosummary::
    :toctree: ../../generated/

    seed
Jinjing Zhou's avatar
Jinjing Zhou committed
197
198
    save_graphs
    load_graphs
199
    apply_each