# DGL convolutions for homogeneous multigraphs?

Do any of the current DGL modules support convolutions over homogeneous multigraphs? That is:

1. For a pair of nodes i and j (potentially with i = j), there are K_{i,j} \geq 0 edges connecting the nodes.
2. Each node i has an initial feature vector v^0_i.
3. Each edge (i,j,k) has an initial feature vector u_{i,j,k}.

If not, does anyone have recommendations on where to start implementing one?

A simple example of a graph convolution in this setting, adapted from here is:

v^{t+1}_i = \sigma\left(\sum_{j,k} \text{Concat}(v^t_j, u_{i,j,k})W_c + v^t_i W_s + b\right),
where \sigma is an activation function, W_c, W_s are trainable weight matrices, and b is a trainable bias.

Thank you!

DGL supports multigraphs and you can have multiple edges from node i to node j in one graph. To perform the computation corresponding to the equation, you can do something as follows.

import dgl.function as fn

# Assume g.ndata['h'] stores input node features and
# g.edata['h'] stores input edge features
g.apply_edges(fn.copy_u('h', 'src'))
g.edata['h'] = torch.cat([g.edata['src'], g.edata['h']], dim=1)
g.update_all(fn.copy_e('h', 'm'), fn.sum('m', 'sum1'))


Once you have g.ndata['sum1'], you can then multiply it by W_c and multiply the first few columns of it by W_s.

@mufeili Thank you! This works quite well, and your explanation is clear.

A follow-on question: An modification to the convolution operation I showed is:

v^{t+1}_i = \sigma\left( \sum_{j,k} \text{Concat}(v^t_i, v^t_j, u_{i,j,k}) W_c + b\right).

Is there a change we can make to the g.apply_edges(fn.copy_u('h', 'src')) line that will copy both the v^t_i and the v^t_j features to each edge before the concatenation?

The new formula is actually equivalent to your previous formulation by linearity. When you concatenate three tensors and multiply the result by a new tensor W, it is equivalent to multiply each of the three tensors by part of W and add them.