Graph loading error from networkx

I am trying to load a graph from networkx and I am getting the error below. My question is: Is MultiDiGraph not supported? If that’s not the case, how would I trouble-shoot what’s causing this error?

DGLError: [11:11:41] /Users/wanminji/miniconda3/conda-bld/dgl_1552084874854/work/src/graph/graph.cc:37: Check failed: HasVertex(src) && HasVertex(dst) Invalid vertices: src=565264 dst=569360
Stack trace returned 10 entries:
[bt] (0) 0 libdgl.dylib 0x0000000106d4d48b dmlc::StackTrace() + 299
[bt] (1) 1 libdgl.dylib 0x0000000106d4d21f dmlc::LogMessageFatal::~LogMessageFatal() + 47
[bt] (2) 2 libdgl.dylib 0x0000000106d5047e dgl::Graph::Graph(dgl::runtime::NDArray, dgl::runtime::NDArray, dgl::runtime::NDArray, unsigned long, bool) + 1134
[bt] (3) 3 libdgl.dylib 0x0000000106d5cf4e std::__1::__function::__func<dgl::_1, std::__1::allocator<dgl::_1>, void (dgl::runtime::DGLArgs, dgl::runtime::DGLRetValue*)>::operator()(dgl::runtime::DGLArgs&&, dgl::runtime::DGLRetValue*&&) + 702
[bt] (4) 4 libdgl.dylib 0x0000000106d99928 DGLFuncCall + 72
[bt] (5) 5 core.cpython-36m-darwin.so 0x0000000106e1b968 pyx_pw_3dgl_4_ffi_4_cy3_4core_12FunctionBase_5__call(_object*, _object*, _object*) + 904
[bt] (6) 6 python 0x0000000105194ef1 _PyObject_FastCallDict + 177
[bt] (7) 7 python 0x00000001052eb718 call_function + 392
[bt] (8) 8 python 0x00000001052e9175 _PyEval_EvalFrameDefault + 46837
[bt] (9) 9 python 0x00000001052eb9dc fast_function + 188

DGLError: Error while creating graph from input of type “<class ‘networkx.classes.multidigraph.MultiDiGraph’>”

The code corresponding to your error message is here:

This is because the vertex id exceeds the number of nodes in the graph, for example:

import networkx as nx
import dgl
g_nx = nx.MultiDiGraph()
g_nx.add_nodes_from([0, 2, 4, 6, 8])
g_nx.add_edge(0, 8)
g = dgl.DGLGraph(g_nx)

This would trigger the error. Unlike networkx, in DGL the vertex ids are consecutive, if you map [0, 2, 4, 6, 8] to [0, 1, 2, 3, 4], the snippet should work:

import networkx as nx
import dgl
g_nx = nx.MultiDiGraph()
g_nx.add_nodes_from([0, 1, 2, 3, 4])
g_nx.add_edge(0, 4)
g = dgl.DGLGraph(g_nx)

So one way to solve your problem is to map the vertex ids to range(number_of_vertices) manually.
DGL could support this, you could create a issue in DGL’s github repo with prefix [feature request] and our team would resolve this.

Thank you very much. It works