DGLHeteroGraph.prop_nodes(nodes_generator, message_func, reduce_func, apply_node_func=None, etype=None)[source]

Propagate messages using graph traversal by sequentially triggering pull() on nodes.

The traversal order is specified by the nodes_generator. It generates node frontiers, which is a list or a tensor of nodes. The nodes in the same frontier will be triggered together, while nodes in different frontiers will be triggered according to the generating order.

  • nodes_generator (iterable, each element is a list or a tensor of node ids) – The generator of node frontiers. It specifies which nodes perform pull() at each timestep.
  • message_func (callable) – Message function on the edges. The function should be an Edge UDF.
  • reduce_func (callable) – Reduce function on the node. The function should be a Node UDF.
  • apply_node_func (callable, optional) – Apply function on the nodes. The function should be a Node UDF. (Default: None)
  • etype (str, optional) – The edge type. Can be omitted if there is only one edge type in the graph. (Default: None)


>>> import torch
>>> import dgl
>>> import dgl.function as fn

Instantiate a heterogrph and perform multiple rounds of message passing.

>>> g = dgl.graph(([0, 1, 2, 3], [2, 3, 4, 4]), 'user', 'follows')
>>> g.nodes['user'].data['h'] = torch.tensor([[1.], [2.], [3.], [4.], [5.]])
>>> g['follows'].prop_nodes([[2, 3], [4]], fn.copy_src('h', 'm'),
>>>                         fn.sum('m', 'h'), etype='follows')

See also