Error while creating graph from networkx

I have a DGLGraph g which I am modifying (like removing edges and adding edges). Next, I am converting the DGLGraph to networks graph, clearing the original DGLGraph and re loading it from networks graph as below:

g is a DGLGraph

> nxg = g.to_networkx()
> g.clear()
> g.from_networkx(nxg)   

It throws the following error

g.from_networkx(nxg)
File “/home/uday/anaconda3/envs/py36/lib/python3.6/site-packages/dgl/graph.py”, line 1373, in from_networkx
self._graph = graph_index.from_networkx(nx_graph, self.is_readonly)
File “/home/uday/anaconda3/envs/py36/lib/python3.6/site-packages/dgl/graph_index.py”, line 1128, in from_networkx
src[eid] = u
IndexError: index 13949 is out of bounds for axis 0 with size 13948

Hi, the networkx graph need to have consecutive node/edge ids if you would like to convert it into a DGLGraph.

I agree with that. However, I am creating the networkx graph from DGL and converting it back to DGL graph right.

    # g is a DGL graph (cora dataset)
    nxg = g.to_networkx()
    g.clear()
    g = DGLGraph()
    g.from_networkx(nxg)

Would you mind sharing the graph data with us (e.g. via dropbox) to help us locate the bug?

I am using the builtin dataset:

from dgl.data import citation_graph as citegrh
data = citegrh.load_cora()
g = data.graph 

nxg = g.to_networkx()
g.clear()
g = DGLGraph()
g.from_networkx(nxg)

The behavior is observed for all the benchmark citation networks: cora, citeseer, and pubmed.

Hi, sorry but I cannot reproduce you bug, I my machine with latest DGL all three datasets works fine for me when I convert a DGLGraph to networkx graph then convert it back to a DGLGraph. (BTW, the data.graph is a networkx.DiGraph class rather than a dgl.DGLGraph class).

Could you please try using the latest version of DGL (0.4.3) and see if the problem persists?