Multi-edge DGL graph to NetworkX graph--missing the multi-edge information, meanwhile, I cannot recover the DGL graph from induced NetworkX graph

See code as follows

def build_karate_club_graph():
g = dgl.DGLGraph()
node_id = torch.arange(0, 4, dtype=torch.long).view(-1, 1)
# add 34 nodes into the graph; nodes are labeled from 0~33
g.add_nodes(4)
g.ndata[‘n_id’] = node_id
# all 78 edges as a list of tuples
edge_list = [(1,0), (2, 0), (2, 1), (3, 0), (2,1)]
# add edges two lists of nodes: src and dst
src, dst = tuple(zip(*edge_list))
g.add_edges(src, dst)
# edges are directional in DGL; make them bi-directional
# g.add_edges(dst, src)
g.edata[‘e_label’] = torch.randint(low=0, high=1, size=(1,5)).squeeze(0)
return g

#========

graph = build_karate_club_graph()
nxGraph = graph.to_networkx()
nx_dgl_graph = dgl.DGLGraph(nxGraph)

Hi, for graphs with multi-edges, you need to specify multigraph=True when creating this DGLGraph, for example:

>>> import dgl
>>> g = dgl.DGLGraph(multigraph=True)
>>> g.add_nodes(3)
>>> g.add_edge(1, 1)
>>> g.add_edge(1, 1)
>>> g.add_edge(1, 1)
>>> g_nx = g.to_networkx()
>>> g_nx.number_of_edges()
3

Thank you. :+1: It seems that without the parameter multigraph, dgl graph can also add multi edges between two nodes. Does this mean that such parameter works for ‘DGL --> NetWorkX’?

Thanks.