Is there any way to aggregate features from both incoming AND outgoing edges with DGL?


I saw the answer in FAQ 1. Are DGLGraphs directed or not? How to represent an undirected graph?
" All DGLGraphs are directed. To represent an undirected graph, you need to create edges for both directions. dgl.to_bidirected can be helpful, which converts a DGLGraph into a new one with edges for both directions."

But in my use case it’s not suitable to do so for memory issues (graph with about one million of edges and a high dimension space for edge feature).

Is there anyway to aggregate features from both incoming AND outgoing edges when updating nodes.

With the message-passing design of DGL, I assume that

g.update_all(fn.copy_e('he', 'm'), fn.sum('m', 'he_aggr'))

will only aggregate features from incoming edges.

It seems that this functionality exists in PyTorch Geometrics (parameter “flow” of message passing method : torch_geometric.nn — pytorch_geometric 2.0.0 documentation ) as in graphnets library (parameters “use_received_edges” and “use_sent_edges” for NodeBlock: graph_nets/ at master · deepmind/graph_nets · GitHub )

We achieve aggregation of outgoing edges via dgl.reverse(), which should be quite cheap as it reuses the underlying COO/CSR/CSC array. You could perform message passing on the original graph and the reversed graph to get the same goal (which is what flow argument in PyTorch Geometric does).