Dose the dst node in the subgraph obtained by EdgeDataloader has an order?

for example, if we use code below to construct a dgl graph:

src = [0,1,2,3,4,.......]
dst = [9,8,7,6,5,.......]
g = dgl.graph([])
g.add_nodes(num_nodes)
g.add_edges(src, dst)

then we use the first edge [0,9] and the second edge [1,8] to do EdgeDataloader, after that the subgraph’s dst node will be [0,1,9,8](we can get it from blocks[-1].dstdata[’_ID’] or pair_graph.dstdata[’_ID’]).

my question is: If the node ids in dstdata have an order?

EdgeDataLoader does not guarantee order of the output nodes (i.e. pair_graph.dstdata[’_ID’]). The edges of the pair graph however are guaranteed to be in the same order as the EdgeDataLoader iterates (e.g. if shuffle is False, the edge IDs of pair graph from the first batch will be 0, 1, ..., batch_size - 1).

Thank you for your reply.
This means that if I need to get the out feature of the specified node, I need to traverse pair_graph.dstdata[’_ID’] to get the corresponding index, and take it out from dstdata[‘out_ft’][index]. Am I right?

Right. Just curious: why would you like to do this?

I am trying to do link prediction using ‘FB15k-237’, and I want to get the output node’s embedding and these node’s related relation in triplets to do score function.

There is another question. After I get a block through sampling, can I add a self-loop to the dstnode in the block?
I noticed that in the block, block.srcnodes()[:dstnodes_num] seems equal to block.dstnodes(), can this be guaranteed?
then I try to add edges by

block.add_edges(graph.dstnodes(), graph.dstnodes())

but the num_src_nodes and num_dst_nodes` in block become the same value, means I seem to get the wrong result…

Yes, this is guaranteed.

Blocks are not designed to be mutable, although DGL currently does not prevent you from doing so. The behavior would be undefined.

As per self-loops, I assume you want to combine the features of the center nodes with the aggregation of the neighbors. In this case you can simply copy the features in block.srcdata[...][:dstnodes_num] to block.dstdata[...] and perform the combination in block.dstdata[...]. No need to add edges.

good idea! but in my case, I want to do edge_softmax before aggregation, so it seems not to work for me.
Does it seem that I can only add self-loop when building the complete graph?

In this case yes, you need to add self-loops before sampling.