How to concat node and edge features in update_all

Hi,

I have seen a similar question in this post.

I also want to concat node and edge features. However, I need to feed the result to a single reducer function.

For example, Zihao gives a solution which is

g.update_all([fn.copy_e('e', 'm_e'), fn.copy_u('h', 'm_n')], 
             [fn.sum('m_e', 'h_e'), fn.sum('m_n', 'h_n')])

What I want is:

graph.update_all([fn.copy_e('e', 'm_e'), fn.copy_u('h', 'm_n')], self._lstm_reducer)
# my lstm reducer
def _lstm_reducer(self, nodes):
        m_n = nodes.mailbox['m_n']  # (B, L, D)
        m_e = nodes.mailbox['m_e']
        rst = self.lstm(tf.concat([m_n, m_e], axis=-1))
        return {'neigh': rst}

where I expect the _lstm_reducer to concat m_e and m_n. However, I got a error “‘list’ object is not callable”. What is a good way to do this?

Thanks!

list of functions is not supported in DGL.

How about this:

def copy_u_e(edges):
    return {'m_n': edges.src['h'], 'm_e': edges.data['e']}
g.update_all(copy_u_e, _lstm_reducer)
1 Like

I see. So we can return multiple items to the mailbox in a user-defined messaging function. Thanks a lot!

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