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.

graph(data[, ntype, etype, num_nodes, …])

Create a graph and return.

heterograph(data_dict[, num_nodes_dict, …])

Create a heterogeneous graph and return.

from_scipy(sp_mat[, eweight_name, idtype, …])

Create a graph from a SciPy sparse matrix and return.

from_networkx(nx_graph[, node_attrs, …])

Create a graph from a NetworkX graph and return.

bipartite_from_scipy(sp_mat, utype, etype, vtype)

Create a uni-directional bipartite graph from a SciPy sparse matrix and return.

bipartite_from_networkx(nx_graph, utype, …)

Create a unidirectional bipartite graph from a NetworkX graph and return.

rand_graph(num_nodes, num_edges[, idtype, …])

Generate a random graph of the given number of nodes/edges and return.

rand_bipartite(utype, etype, vtype, …[, …])

Generate a random uni-directional bipartite graph and return.

knn_graph(x, k)

Construct a graph from a set of points according to k-nearest-neighbor (KNN) and return.

segmented_knn_graph(x, k, segs)

Construct multiple graphs from multiple sets of points according to k-nearest-neighbor (KNN) and return.

Subgraph Extraction Ops

Operators for extracting and returning subgraphs.

node_subgraph(graph, nodes)

Return a subgraph induced on the given nodes.

edge_subgraph(graph, edges[, preserve_nodes])

Return a subgraph induced on the given edges.

node_type_subgraph(graph, ntypes)

Return the subgraph induced on given node types.

edge_type_subgraph(graph, etypes)

Return the subgraph induced on given edge types.

in_subgraph(g, nodes)

Return the subgraph induced on the inbound edges of all the edge types of the given nodes.

out_subgraph(g, nodes)

Return the subgraph induced on the out-bound edges of all the edge types of the given nodes.

Graph Transform Ops

Operators for generating new graphs by manipulating the structure of the existing ones.

add_nodes(g, num[, data, ntype])

Add the given number of nodes to the graph and return a new graph.

add_edges(g, u, v[, data, etype])

Add the edges to the graph and return a new graph.

remove_nodes(g, nids[, ntype])

Remove the specified nodes and return a new graph.

remove_edges(g, eids[, etype])

Remove the specified edges and return a new graph.

add_self_loop(g[, etype])

Add self-loops for each node in the graph and return a new graph.

remove_self_loop(g[, etype])

Remove self-loops for each node in the graph and return a new graph.

add_reverse_edges(g[, readonly, copy_ndata, …])

Add an reversed edge for each edge in the input graph and return a new graph.

reverse(g[, copy_ndata, copy_edata, …])

Return a new graph with every edges being the reverse ones in the input graph.

to_bidirected(g[, copy_ndata, readonly])

Convert the graph to a bi-directional simple graph and return.

to_simple(g[, return_counts, …])

Convert a graph to a simple graph without parallel edges and return.

to_block(g[, dst_nodes, include_dst_in_src])

Convert a graph into a bipartite-structured block for message passing.

compact_graphs(graphs[, always_preserve, …])

Given a list of graphs with the same set of nodes, find and eliminate the common isolated nodes across all graphs.

to_heterogeneous(G, ntypes, etypes[, …])

Convert a homogeneous graph to a heterogeneous graph and return.

to_homogeneous(G[, ndata, edata])

Convert a heterogeneous graph to a homogeneous graph and return.

to_networkx(g[, node_attrs, edge_attrs])

Convert a homogeneous graph to a NetworkX graph and return.

line_graph(g[, backtracking, shared])

Return the line graph of this graph.

khop_graph(g, k[, copy_ndata])

Return the graph whose edges connect the k-hop neighbors of the original graph.

metapath_reachable_graph(g, metapath)

Return a graph where the successors of any node u are nodes reachable from u by the given metapath.

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(graphs[, ndata, edata, node_attrs, …])

Batch a collection of DGLGraph s into one graph for more efficient graph computation.

unbatch(g[, node_split, edge_split])

Revert the batch operation by split the given graph into a list of small ones.

readout_nodes(graph, feat[, weight, op, ntype])

Generate a graph-level representation by aggregating node features feat.

readout_edges(graph, feat[, weight, op, etype])

Sum the edge feature feat in graph, optionally multiplies it by a edge weight.

sum_nodes(graph, feat[, weight, ntype])

Syntax sugar for dgl.readout_nodes(graph, feat, weight, ntype=ntype, op='sum').

sum_edges(graph, feat[, weight, etype])

Syntax sugar for dgl.readout_edges(graph, feat, weight, etype=etype, op='sum').

mean_nodes(graph, feat[, weight, ntype])

Syntax sugar for dgl.readout_nodes(graph, feat, weight, ntype=ntype, op='mean').

mean_edges(graph, feat[, weight, etype])

Syntax sugar for dgl.readout_edges(graph, feat, weight, etype=etype, op='mean').

max_nodes(graph, feat[, weight, ntype])

Syntax sugar for dgl.readout_nodes(graph, feat, weight, ntype=ntype, op='max').

max_edges(graph, feat[, weight, etype])

Syntax sugar for dgl.readout_edges(graph, feat, weight, etype=etype, op='max').

softmax_nodes(graph, feat, *[, ntype])

Perform graph-wise softmax on the node features.

softmax_edges(graph, feat, *[, etype])

Perform graph-wise softmax on the edge features.

broadcast_nodes(graph, graph_feat, *[, ntype])

Generate a node feature equal to the graph-level feature graph_feat.

broadcast_edges(graph, graph_feat, *[, etype])

Generate an edge feature equal to the graph-level feature graph_feat.

topk_nodes(graph, feat, k, *[, descending, …])

Return a graph-level representation by a graph-wise top-k on node features feat in graph by feature at index sortby.

topk_edges(graph, feat, k, *[, descending, …])

Return a graph-level representation by a graph-wise top-k on edge features feat in graph by feature at index sortby.

Traversals

Utilities for traversing graphs.

prop_nodes(graph, nodes_generator[, …])

Functional method for dgl.DGLGraph.prop_nodes().

prop_nodes_bfs(graph, source, message_func, …)

Message propagation using node frontiers generated by BFS.

prop_nodes_topo(graph, message_func, reduce_func)

Message propagation using node frontiers generated by topological order.

prop_edges(graph, edges_generator[, …])

Functional method for dgl.DGLGraph.prop_edges().

prop_edges_dfs(graph, source, message_func, …)

Message propagation using edge frontiers generated by labeled DFS.

Utilities

Other utilities for controlling randomness, saving and loading graphs, etc.

seed(val)

Set the random seed of DGL.

save_graphs(filename, g_list[, labels])

Save graphs and optionally their labels to file.

load_graphs(filename[, idx_list])

Load graphs and optionally their labels from file saved by save_graphs().