Add_edges in batch graph

Does the method add_edges preserve the batch information? If not, how to do this in an efficient way.

g1 = dgl.graph(([0, 1, 2, 3, 4], [1, 2, 3, 4, 0]))
g2 = dgl.graph(([0, 3, 2, 3, 4], [1, 2, 3, 4, 0]))
bg = dgl.batch([g1, g2])
bg.add_edges([0],[3])
dgl.unbatch(bg)

Unfortunately it is not that easy as specifying which graph the new edges belongs to is not trivial. I think you will need to unbatch them, add the edges, and batch them back.

If you want to add self loops, you could add them in the graph dataset itself as a preprocessing step instead.

Thanks for your reply!! I hope to do this since several graph augmentation models requires the “add edges” operation. I also find that unbatch is time-consuming when batch size is large, while moving such augmentation to collate_fn is ok but it makes it not differentiable.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.