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 |
|
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 edges to the graph and return a new graph. |
|
Add the given number of nodes to the graph and return a new graph. |
|
Add a reversed edge for each edge in the input graph and return a new graph. |
|
Add self-loops for each node in the graph and return a new graph. |
|
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. |
|
Given a list of graphs with the same set of nodes, find and eliminate the common isolated nodes across all graphs. |
|
Return the matrix of \(A^k\) where \(A\) is the adjacency matrix of the graph \(g\). |
|
Return the graph whose edges connect the |
|
Construct a graph from a set of points according to k-nearest-neighbor (KNN) and return. |
Return the largest eigenvalue of the normalized symmetric Laplacian of a graph. |
|
|
Laplacian Positional Encoding, as introduced in Benchmarking Graph Neural Networks |
|
Return the line graph of this graph. |
|
Return a graph where the successors of any node |
|
This is to partition a graph with Metis partitioning. |
|
This assigns nodes to different partitions with Metis partitioning algorithm. |
|
Calculate normalization coefficient per edge based on destination node degree. |
|
Partition a graph. |
|
Construct a graph from a set of points with neighbors within given distance. |
|
Random Walk Positional Encoding, as introduced in Graph Neural Networks with Learnable Structural and Positional Representations |
|
Remove the specified edges and return a new graph. |
|
Remove the specified nodes and return a new graph. |
|
Remove self-loops for each node in the graph and return a new graph. |
|
Return a new graph with nodes and edges re-ordered/re-labeled according to the specified permute algorithm. |
|
Return a new graph with every edges being the reverse ones in the input graph. |
|
Construct multiple graphs from multiple sets of points according to k-nearest-neighbor (KNN) and return. |
|
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. |
|
Convert the graph to a bi-directional simple graph and return. |
|
Convert a graph into a bipartite-structured block for message passing. |
|
Convert a DGL graph to a |
|
Cast this graph to use float64 (double-precision) for any floating-point edge and node feature data. |
|
Cast this graph to use float32 (single-precision) for any floating-point edge and node feature data. |
|
Cast this graph to use float16 (half-precision) for any floating-point edge and node feature data. |
|
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. |
|
Convert a graph to a simple graph without parallel edges and return. |
Convert the graph to a simple graph with no multi-edge. |
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 |
|
Double Radius Node Labeling, as introduced in Link Prediction Based on Graph Neural Networks. |
|
Compute shortest distance and paths on the given graph. |
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, setting and getting runtime configurations, 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. |
|
Set whether DGL uses libxsmm at runtime. |
Get whether the use_libxsmm flag is turned on. |