dgl.nodeflow (Deprecating)


This module is going to be deprecated in favor of dgl.sampling.

class dgl.NodeFlow(parent, nfobj)[source]

The NodeFlow class stores the sampling results of Neighbor sampling and Layer-wise sampling.

These sampling algorithms generate graphs with multiple layers. The edges connect the nodes between two layers, which forms blocks, while there don’t exist edges between the nodes in the same layer. As illustrated in the figure, the last layer stores the target (seed) nodes where neighbors are sampled from. Neighbors reached in different hops are placed in different layers. Edges that connect to the neighbors in the next hop are placed in a block. We store extra information, such as the node and edge mapping from the NodeFlow graph to the parent graph.


DO NOT create NodeFlow object directly. Use sampling method to generate NodeFlow instead.

  • parent (DGLGraphStale) – The parent graph.

  • nfobj (NodeFlowObject) – The nodeflow object

Querying graph structure


Get the number of layers.


Get the number of blocks.


Return the number of nodes in a specified layer.


Return the number of edges in a specified block.


Return the in-degree of the nodes in the specified layer.


Return the out-degree of the nodes in the specified layer.


Get the node Ids in the specified layer.


Get the node Ids of the parent graph in the specified layer


Get the edge Ids in the specified block.


Get the edge Ids of the parent graph in the specified block.

NodeFlow.block_edges(block_id[, remap_local])

Return the edges in a block.

Converting to other format

NodeFlow.block_adjacency_matrix(block_id, ctx)

Return the adjacency matrix representation for a specific block in a NodeFlow.

NodeFlow.block_incidence_matrix(block_id, …)

Return the incidence matrix representation of the block.

Using Node/edge features


Return a LayerView of this NodeFlow.


Return a BlockView of this NodeFlow.

NodeFlow.set_n_initializer(initializer[, …])

Set the initializer for empty node features.

NodeFlow.set_e_initializer(initializer[, …])

Set the initializer for empty edge features.


Return the node feature schemes.


Return the edge feature schemes.

Mapping between NodeFlow and parent graph


This maps the child node Ids to the parent Ids.


This maps the child edge Ids to the parent Ids.

NodeFlow.map_from_parent_nid(layer_id, …)

Map parent node Ids to NodeFlow node Ids in a certain layer.

Synchronize features between NodeFlow and parent graph


Copy node/edge features from the parent graph.

NodeFlow.copy_to_parent([node_embed_names, …])

Copy node/edge embeddings to the parent graph.

Computing with NodeFlow

NodeFlow.register_message_func(func[, block_id])

Register global message function for a block.

NodeFlow.register_reduce_func(func[, block_id])

Register global message reduce function for a block.

NodeFlow.register_apply_node_func(func[, …])

Register global node apply function for a block.

NodeFlow.register_apply_edge_func(func[, …])

Register global edge apply function for a block.

NodeFlow.apply_layer(layer_id[, func, v, …])

Apply node update function on the node embeddings in the specified layer.

NodeFlow.apply_block(block_id[, func, …])

Apply edge update function on the edge embeddings in the specified layer.

NodeFlow.block_compute(block_id[, …])

Perform the computation on the specified block.

NodeFlow.prop_flow([message_funcs, …])

Perform the computation on flows.