dgl¶
The dgl
package contains data structure for storing structural and feature data
(i.e., the DGLGraph
class) and also utilities for generating, manipulating
and transforming graphs.
Graph Create Ops¶
Operators for constructing DGLGraph
from raw data formats.
|
Create a graph and return. |
|
Create a heterogeneous graph and return. |
|
Create a graph from a SciPy sparse matrix and return. |
|
Create a graph from a NetworkX graph and return. |
|
Create a uni-directional bipartite graph from a SciPy sparse matrix and return. |
|
Create a unidirectional bipartite graph from a NetworkX graph and return. |
|
Generate a random graph of the given number of nodes/edges and return. |
|
Generate a random uni-directional bipartite graph and return. |
|
Construct a graph from a set of points according to k-nearest-neighbor (KNN) and return. |
|
Construct multiple graphs from multiple sets of points according to k-nearest-neighbor (KNN) and return. |
|
Construct a graph from a set of points with neighbors within given distance. |
|
Create a message flow graph (MFG) as a |
|
Convert a message flow graph (MFG) as a |
|
Merge a sequence of graphs together into a single graph. |
Subgraph Extraction Ops¶
Operators for extracting and returning subgraphs.
|
Return a subgraph induced on the given nodes. |
|
Return a subgraph induced on the given edges. |
|
Return the subgraph induced on given node types. |
|
Return the subgraph induced on given edge types. |
|
Return the subgraph induced on the inbound edges of all the edge types of the given nodes. |
|
Return the subgraph induced on the outbound edges of all the edge types of the given nodes. |
|
Return the subgraph induced by k-hop in-neighborhood of the specified node(s). |
|
Return the subgraph induced by k-hop out-neighborhood of the specified node(s). |
Graph Transform Ops¶
Operators for generating new graphs by manipulating the structure of the existing ones.
|
Add the given number of nodes to the graph and return a new graph. |
|
Add the edges to the graph and return a new graph. |
|
Remove the specified nodes and return a new graph. |
|
Remove the specified edges and return a new graph. |
|
Add self-loops for each node in the graph and return a new graph. |
|
Remove self-loops for each node in the graph and return a new graph. |
|
Add a reversed edge for each edge in the input graph and return a new graph. |
|
Return a new graph with every edges being the reverse ones in the input graph. |
|
Convert the graph to a bi-directional simple graph and return. |
|
Convert a graph to a simple graph without parallel edges and return. |
|
Convert a graph into a bipartite-structured block for message passing. |
|
Given a list of graphs with the same set of nodes, find and eliminate the common isolated nodes across all graphs. |
|
Convert a homogeneous graph to a heterogeneous graph and return. |
|
Convert a heterogeneous graph to a homogeneous graph and return. |
|
Convert a homogeneous graph to a NetworkX graph and return. |
|
Return the line graph of this graph. |
|
Return the graph whose edges connect the |
|
Return a graph where the successors of any node |
|
Create a weighted graph whose adjacency matrix is the product of the adjacency matrices of the given two graphs. |
|
Create a weighted graph whose adjacency matrix is the sum of the adjacency matrices of the given graphs, whose rows represent source nodes and columns represent destination nodes. |
|
Return a new graph with nodes and edges re-ordered/re-labeled according to the specified permute algorithm. |
|
Return a new graph whose CSR matrix is sorted by the given tag. |
|
Return a new graph whose CSC matrix is sorted by the given tag. |
Graph Positional Encoding Ops:¶
Operators for generating positional encodings of each node.
|
Random Walk Positional Encoding, as introduced in Graph Neural Networks with Learnable Structural and Positional Representations |
|
Laplacian Positional Encoding, as introduced in Benchmarking Graph Neural Networks |
Graph Partition Utilities¶
|
This is to partition a graph with Metis partitioning. |
|
This assigns nodes to different partitions with Metis partitioning algorithm. |
|
Partition a graph. |
Batching and Reading Out Ops¶
Operators for batching multiple graphs into one for batch processing and operators for computing graph-level representation for both single and batched graphs.
|
Batch a collection of |
|
Revert the batch operation by split the given graph into a list of small ones. |
|
Get a particular graph from a batch of graphs. |
|
Generate a graph-level representation by aggregating node features |
|
Sum the edge feature |
|
Syntax sugar for |
|
Syntax sugar for |
|
Syntax sugar for |
|
Syntax sugar for |
|
Syntax sugar for |
|
Syntax sugar for |
|
Perform graph-wise softmax on the node features. |
|
Perform graph-wise softmax on the edge features. |
|
Generate a node feature equal to the graph-level feature |
|
Generate an edge feature equal to the graph-level feature |
|
Return a graph-level representation by a graph-wise top-k on node features |
|
Return a graph-level representation by a graph-wise top-k on edge features |
Graph Traversal & Message Propagation¶
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.
g = ... # some DGLGraph
for nodes in dgl.bfs_nodes_generator(g, 0):
do_something(nodes)
|
Node frontiers generator using breadth-first search. |
|
Edges frontiers generator using breadth-first search. |
|
Node frontiers generator using topological traversal. |
|
Edge frontiers generator using depth-first-search (DFS). |
|
Produce edges in a depth-first-search (DFS) labeled by type. |
DGL provides APIs to perform message passing following graph traversal order. prop_nodes_XXX
calls traversal algorithm XXX
and triggers pull()
on the visited node
set at each iteration. prop_edges_YYY
applies traversal algorithm YYY
and triggers
send_and_recv()
on the visited edge set at each iteration.
|
Functional method for |
|
Message propagation using node frontiers generated by BFS. |
|
Message propagation using node frontiers generated by topological order. |
|
Functional method for |
|
Message propagation using edge frontiers generated by labeled DFS. |
Utilities¶
Other utilities for controlling randomness, saving and loading graphs, functions that applies the same function to every elements in a container, etc.
|
Set the random seed of DGL. |
|
Save graphs and optionally their labels to file. |
|
Load graphs and optionally their labels from file saved by |
|
Apply a function to every element in a container. |