Handling 0-in-degree in HeteroGraphConv wrapper for heterogeneous graphs using EGATConv

Hey, I am working with a Heterogeneous graph, and I am using the dgl.EGATConv module since I have node and edge features that I need to use. I have currently a graph with 3 node types and 9 edge features, but the problem I am working on requires some nodes not to have any in-edges when creating and looking at the subgraph (used for the convolution using EGATConv) (see picture).

The thing is that it is important for this node to not be linked to any other since it gives information on the structure of the problem. The issue here is that when applying the forward pass, I get this error :
raise DGLError( dgl._ffi.base.DGLError: There are 0-in-degree nodes in the graph, output for those nodes will be invalid. This is harmful for some applications, causing silent performance regression. Adding a self-loop on the input graph by calling g = dgl.add_self_loop(g) will resolve the issue.

Which seems to be caused by the lonely nodes described earlier. When I try to fix this by doing as the error says, it causes a new error: It is impossible to add self-loops since we are working with a heterograph! For example if nodes ‘A’ and ‘B’ are linked using ‘followed_by’ edges. There is first: no sense in adding a ‘B’ is ‘followed_by’ ‘B’ edge and moreover, this would cause other problems with the mathematical way to make the convolution.

The thing is that I don’t understand why this way of creating the graph should lead to an issue since the mathematical theory says that we make the convolution using the neighborhood of the node we are working with and this is just the case where the neighborhood N is of size 0 (lNl = 0).

My question is pretty simple: can I still use the graph as created and is there something I am doing wrong that makes the lNl = 0 case buggy or should I modify all the graphs and add an edge feature that says “this edge shouldn’t be there !” ?

Thanks a lot for the help you may give me and have a wonderful day :slight_smile:

could you refer to the doc about adding self loop for heterogeneous graph? dgl.add_self_loop — DGL 2.2.1 documentation

If no such edge type exists, please create it beforehand.

Hello, thanks for the answer.

I have tried to add self_loops to each edge type, but unfortunately it results in the following error: DGLError(dgl._ffi.base.DGLError: add_self_loop does not support unidirectional bipartite graphs: (‘A’, ‘followed_by’, ‘B’).Please make sure the types of head node and tail node are identical.

It runs when adding only to the (‘A’, 'relation name", “A”) type of nodes (not bipartite), but is there nothing wrong doing this ?

Also, I find something kind of weird since I can get the error or not depending on where I add those self-loops.

For example :

  1. Doing it inside the forward method gives no error running the code :
    image

  2. Doing it inside the training loop gives the “There are 0-in-degree nodes in the graph” error :
    image

It seems that the EGATConv module doesn’t manage the allow_zero_in_degree parameter.

It is present in a lot of other modules as GATConv, SGConv, and so on :
image

Do u know why ?
Thanks in advance !

  1. could you try to comment out the check in code to bypass the zero in-degree issue? will it works well?
  2. could you try with EdgeGATConv — DGL 2.2.1 documentation which has argument of allow_zero_in_degree?

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