I'm using DGL (Python package dedicated to deep learning on graphs) for training of defining a graph, defining Graph Convolutional Network (GCN) and train.

I faced a problem which I’m dealing with for two weeks. I developed my GCN code based on the link below:

enter link description here

I’m facing an error for this part of the above mentioned code:

class GCNLayer(nn.Module): def init(self, in_feats, out_feats): super(GCNLayer, self).init() self.linear = nn.Linear(in_feats, out_feats)

def forward(self, g, inputs):
    # g is the graph and the inputs is the input node features
    # first set the node features
    g.ndata['h'] = inputs
    # trigger message passing on all edges
    g.send(g.edges(), gcn_message)
    # trigger aggregation at all nodes
    g.recv(g.nodes(), gcn_reduce)
    # get the result node features
    h = g.ndata.pop('h')
    # perform linear transformation
    return self.linear(h)

I’m getting an error below:

dgl._ffi.base.DGLError: DGLGraph.send is deprecated. As a replacement, use DGLGraph.apply_edges API to compute messages as edge data. Then use DGLGraph.send_and_recv and set the message function as dgl.function.copy_e to conduct message aggregation*

As it is guided in the error, I wonder to know how can I use DGLGraph.apply_edges instead of DGLGraph.send?

In "DGLGraph.send" command we have 2 arguments "g.edges()" and "gcn_message".

How these arguments can be converted to the arguments required for "DGLGraph.apply_edges" which are (func, edges=‘ALL’, etype=None, inplace=False ) (According to this link?

Also, the same question for "DGLGraph.send_and_recv".

In "DGLGraph.recv" we had 2 arguments "g.nodes()" and "gcn_reduce".

How these arguments can be converted to the arguments required for "DGLGraph.send_and_recv" which are "(edges, message_func, reduce_func, apply_node_func=None, etype=None, inplace=False)" (According to this link)?

I would be very grateful if you can help me with this big challenge.

Thank you

2

There are 2 answers

1
Femmy Rootal On

try code below, it may solve your problem

def forward(self, g, inputs):
    g.ndata['h'] = inputs
    g.send_and_recv(g.edges(), gcn_message, gcn_reduce)
    h = g.ndata.pop('h')
    return self.linear(h)
0
Ashik Saibabu T On

DGLGraph.apply_edges(func, edges='ALL', etype=None, inplace=False) is used to update edge features using the function 'func' on all the edges in 'edges'.

DGLGraph.send_and_recv(edges, message_func, reduce_func, apply_node_func=None, etype=None, inplace=False) is used to pass messages, reduce messages and update the node features for all the edges in 'edges'.

To get your forward method to work you can update your code as below

def forward(self, g, inputs):
    g.ndata['h'] = inputs
    g.send_and_recv(g.edges(), fn.copy_src("h", "m"), fn.sum("m", "h"))
    h = g.ndata.pop("h")

    return self.linear(h)

You can use your own message_func (message generation) and reduce_func (message aggregation) to fit your purpose.