Error when assign node features

the error info:
the DGLGraph has 505243 nodes and has 0 edge.
when I assign features to the nodes(num=505243),

 # sth like this
g.readonly(False)
g.remove_edges(np.arange(g.number_of_edges()))
# g = dgl.transform.add_self_loop(g)
g.readonly()
g.ndata['h'] = torch.rand(g.number_of_nodes(),5)

it reported error bellow.

Traceback (most recent call last):
  ... ... # local py scripts
  File "/usr/local/lib/python3.6/dist-packages/dgl/view.py", line 65, in __setitem__
    self._graph.set_n_repr({key : val}, self._nodes)
  File "/usr/local/lib/python3.6/dist-packages/dgl/graph.py", line 2285, in set_n_repr
    self._node_frame[key] = val
  File "/usr/local/lib/python3.6/dist-packages/dgl/frame.py", line 671, in __setitem__
    self.update_data(key, val, inplace=False)
  File "/usr/local/lib/python3.6/dist-packages/dgl/frame.py", line 698, in update_data
    self.update_column(key, val, inplace=inplace)
  File "/usr/local/lib/python3.6/dist-packages/dgl/frame.py", line 729, in update_column
    self._frame[name] = data
  File "/usr/local/lib/python3.6/dist-packages/dgl/frame.py", line 328, in __setitem__
    self.update_column(name, data)
  File "/usr/local/lib/python3.6/dist-packages/dgl/frame.py", line 415, in update_column
    (self.num_rows, len(col)))
dgl._ffi.base.DGLError: Expected data to have 0 rows, got 505243.

however, when I did g = dgl.transform.add_self_loop(g), everything became ok.

I have tried following scrip for comparision, it worked well too, so why?

g = dgl.DGLGraph()
g.add_nodes(5)
g.ndata['h'] = torch.rand(5,4)

I cannot reproduce your issue. Can you try creating a minimal example for reproducing the issue along with the graph structure?

Hi,

Could you try the latest dgl version? By pip install --upgrade --pre dgl (or dgl-cu100 or other cuda version)

We’ve recently fixed a bug due to removing edges

Thanks, you can try this demo, it will reproduce the issure.

import dgl
from dgl.data.utils import load_graphs,save_graphs
import torch
import numpy as np

g = dgl.DGLGraph()
g.add_nodes(10)
g.add_edges([1,2,5,4,3,6,4],[1,0,2,5,4,9,8])

g.readonly(False)
g.remove_edges(np.arange(g.number_of_edges()))
g.ndata['h'] = torch.rand(10,5)
print(g.ndata)

thanks, my dgl version is 0.4.3.post2, i tried pip install --upgrade --pre dgl-cu101, it seems that 0.4.3.post2 is already the latest dgl version and sadly the error still happens.

torch version 1.5.1, dgl version 0.4.3.post2, cuda 10.1

It doesn’t crash on my machine. I think you may need to uninstall dgl first and make sure that you cannot import it in python. And then you may follow the instructions by @VoVAllen.

Hi,

I guess there might be multiple dgl version on your machine. I created a notebook on Google Colab Notebook and couldn’t reproduce your issue.

And if you successfully installed nightly version with --pre , the version will be like 0.5a200701 instaed of 0.4.3post2

thanks, I installed 0.5a20070707, and everything works well.

you are right, I changed the dgl version to 0.5a, and everything works well, thanks a lot