Specific implementation of Data and MessagePassing for undirected graphs? #4444
-
I always find myself working with undirected graphs; having to define each edge twice (once for each direction) is a minor inconvenience and one that I can easily live with, but I often wonder if it wouldn't be worthwhile having a specific Data structure (e.g. UData) and a specific implementation UMessagePassing for undirected graphs, in which by construction always flow between both nodes linked by an edge. One reason why I think this may be worthwhile is this: imagine an application in which you want to propagate data from the line graph of a graph to the edges of the graph (e.g. because it is important to propagate information about what angles edges form among themselves). For this to work properly in an undirected graph, the line graph itself must be made undirected. For example, consider the graph with the following edge_index array (8 nodes): This looks like an ethane molecule CH3-CH3. The graph has 14 edges to make it undirected. Those 14 edges turn to 14 nodes in the line graph; the undirected line graph would have 62 edges, but 12 angles. The situation gets worse if one needs to consider the line graph of the line graph: the line graph of the line graph would have 62 nodes, and 518 edges, when really there are only 9 distinct angles to consider (the angles formed by four nodes in a line). It sounds that this kind of problem could be treated much more directly, in a more memory-efficient way, if there was a specific implementation for undirected graphs. Any thoughts? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Thanks for this interesting issue. I personally always liked the generalization of From a memory and computational perspective, there is also not much to gain here (besides saving half of memory for storing If you desperately need this feature, we could think of adding support for this in |
Beta Was this translation helpful? Give feedback.
-
Hello again. What would you think if I tried implementing this as a dense convolution? I notice that the implementation of dense convolution models does not inherit from MessagePassing, but directly from torch.nn.Module. This may actually be ideal, as the graphs I tend to work with are not so large anyway. This would mean no need to either create UMessagePassing or modify MessagePassing, which I agree would be probably not worth it. Having this discussion has been really clarifying, so I thank you very much. |
Beta Was this translation helpful? Give feedback.
Thanks for this interesting issue. I personally always liked the generalization of
MessagePassing
to both undirected and directed graphs, and adding this now to the library seems like a huge effort that might not be worth it. It also gets a little bit more confusing if we think of heterogeneous graphs and how one would define the notion of undirected graphs there.From a memory and computational perspective, there is also not much to gain here (besides saving half of memory for storing
edge_index
), since we still would need to compute and store the messages for each direction insideMessagePassing
(while also losing the ability to parallelize this step properly).If you desperately need t…