# dgl.DGLGraph.prop_nodes¶

DGLGraph.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.

Parameters
• nodes_generator (iterable[node IDs]) – The generator of node frontiers. Each frontier is a set of node IDs stored in Tensor or python iterables. It specifies which nodes perform pull() at each step.

• message_func (dgl.function.BuiltinFunction or callable) – The message function to generate messages along the edges. It must be either a DGL Built-in Function or a User-defined Functions.

• reduce_func (dgl.function.BuiltinFunction or callable) – The reduce function to aggregate the messages. It must be either a DGL Built-in Function or a User-defined Functions.

• apply_node_func (callable, optional) – An optional apply function to further update the node features after the message reduction. It must be a User-defined Functions.

• etype (str or (str, str, str), optional) –

The type name of the edges. The allowed type name formats are:

• (str, str, str) for source node type, edge type and destination node type.

• or one str edge type name if the name can uniquely identify a triplet format in the graph.

Can be omitted if the graph has only one type of edges.

Examples

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


Instantiate a heterogrph and perform multiple rounds of message passing.

>>> g = dgl.heterograph({('user', 'follows', 'user'): ([0, 1, 2, 3], [2, 3, 4, 4])})
>>> 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')
tensor([[1.],
[2.],
[1.],
[2.],
[3.]])