dmlc / dgl

Python package built to ease deep learning on graph, on top of existing DL frameworks.
http://dgl.ai
Apache License 2.0
13.38k stars 3k forks source link

to_homo() type error #1158

Closed craig0a closed 4 years ago

craig0a commented 4 years ago

🐛 Bug

Calling dgl.to_homo() raises type error: expecting int64, received float

To Reproduce

Steps to reproduce the behavior:

import dgl
follows_g = dgl.graph([(0, 1), (1, 2)], 'user', 'follows')
devs_g = dgl.bipartite([(0, 0), (1, 1)], 'developer', 'develops', 'game')
hetero_g = dgl.hetero_from_relations([follows_g, devs_g])
homo_g = dgl.to_homo(hetero_g)
---------------------------------------------------------------------------
DGLError                                  Traceback (most recent call last)
<ipython-input-13-3542cc2f0c78> in <module>
----> 1 homo_g = dgl.to_homo(hetero_g)

~/Desktop/python3.7/lib/python3.7/site-packages/dgl/convert.py in to_homo(G)
    596         eids.append(F.arange(0, num_edges))
    597 
--> 598     retg = graph((F.cat(srcs, 0), F.cat(dsts, 0)), card=total_num_nodes)
    599     retg.ndata[NTYPE] = F.cat(ntype_ids, 0)
    600     retg.ndata[NID] = F.cat(nids, 0)

~/Desktop/python3.7/lib/python3.7/site-packages/dgl/convert.py in graph(data, ntype, etype, card, **kwargs)
    109     if isinstance(data, tuple):
    110         u, v = data
--> 111         return create_from_edges(u, v, ntype, etype, ntype, urange, vrange)
    112     elif isinstance(data, list):
    113         return create_from_edge_list(data, ntype, etype, ntype, urange, vrange)

~/Desktop/python3.7/lib/python3.7/site-packages/dgl/convert.py in create_from_edges(u, v, utype, etype, vtype, urange, vrange)
    644     DGLHeteroGraph
    645     """
--> 646     u = utils.toindex(u)
    647     v = utils.toindex(v)
    648     urange = urange or (int(F.asnumpy(F.max(u.tousertensor(), dim=0))) + 1)

~/Desktop/python3.7/lib/python3.7/site-packages/dgl/utils.py in toindex(data)
    240     Index
    241     """
--> 242     return data if isinstance(data, Index) else Index(data)
    243 
    244 def zero_index(size):

~/Desktop/python3.7/lib/python3.7/site-packages/dgl/utils.py in __init__(self, data)
     13     """Index class that can be easily converted to list/tensor."""
     14     def __init__(self, data):
---> 15         self._initialize_data(data)
     16 
     17     def _initialize_data(self, data):

~/Desktop/python3.7/lib/python3.7/site-packages/dgl/utils.py in _initialize_data(self, data)
     20         self._dgl_tensor_data = None  # a dgl ndarray
     21         self._slice_data = None # a slice type data
---> 22         self._dispatch(data)
     23 
     24     def __iter__(self):

~/Desktop/python3.7/lib/python3.7/site-packages/dgl/utils.py in _dispatch(self, data)
     45         if F.is_tensor(data):
     46             if F.dtype(data) != F.int64:
---> 47                 raise DGLError('Index data must be an int64 vector, but got: %s' % str(data))
     48             if len(F.shape(data)) > 1:
     49                 raise DGLError('Index data must be 1D int64 vector, but got: %s' % str(data))

DGLError: Index data must be an int64 vector, but got: tensor([0., 1., 3., 4.])
mufeili commented 4 years ago

This seems to be the same bug as #1018 and #1053 and should be fixed with the master branch. You can install from source and see if the error still exists.

craig0a commented 4 years ago

Thank you for your help! I just tried installing from source and received the following error:

Traceback (most recent call last):
  File "setup.py", line 38, in <module>
    LIBS, VERSION = get_lib_path()
  File "setup.py", line 33, in get_lib_path
    lib_path = libinfo['find_lib_path']()
  File "./dgl/_ffi/libinfo.py", line 80, in find_lib_path
    raise RuntimeError(message)
RuntimeError: Cannot find the files.
List of candidates:
/dgl/python/dgl/libdgl.dylib
/dgl/build/libdgl.dylib
/dgl/build/Release/libdgl.dylib
/dgl/lib/libdgl.dylib
/libdgl.dylib

It looks to me like it this isn't missing dependency issue, but that the build didn't make an expected file?

mufeili commented 4 years ago

@craig0a Did you follow exactly the instructions here?

jermainewang commented 4 years ago

Please export DGL_LIBRARY_PATH=<the-path-to-the-build-directory> or install the latest nightly build. Thanks!