Heterogeneous graph with only CSC format created does not support to_homogeneous
- Dominant language
- Python
- Stars
- 14.3k
- Forks
- 3.1k
- PR merge metrics
- No merged PRs in 30d
Description
## 🐛 Bug
Heterogeneous graph with only CSC format created does not support `to_homogeneous` function.
## To Reproduce
```python
g = dgl.heterograph({
('A', 'AB', 'B'): ([1,2,3,4,5],[0,1,2,1,0]),
('B', 'BA', 'A'): ([0,1,2,1,0],[1,2,3,4,5]),
})
g = g.formats('csc')
dgl.to_homogeneous(g)
```
```
---------------------------------------------------------------------------
DGLError Traceback (most recent call last)
Input In [3], in ()
1 graph = dataset.graph
----> 2 graph_homogeneous = dgl.to_homogeneous(graph)
File ~/miniconda3/lib/python3.9/site-packages/dgl-1.2-py3.9-linux-x86_64.egg/dgl/convert.py:1000, in to_homogeneous(G, ndata, edata, store_type, return_count)
998 for etype_id, etype in enumerate(G.canonical_etypes):
999 srctype, _, dsttype = etype
-> 1000 src, dst = G.all_edges(etype=etype, order="eid")
1001 num_edges = len(src)
1002 srcs.append(src + int(offset_per_ntype[G.get_ntype_id(srctype)]))
File ~/miniconda3/lib/python3.9/site-packages/dgl-1.2-py3.9-linux-x86_64.egg/dgl/heterograph.py:3589, in DGLGraph.all_edges(self, form, order, etype)
3519 def all_edges(self, form="uv", order="eid", etype=None):
3520 """Return all edges with the specified edge type.
3521
3522 Parameters
(...)
3587 out_edges
3588 """
-> 3589 src, dst, eid = self._graph.edges(self.get_etype_id(etype), order)
3590 if form == "all":
3591 return src, dst, eid
File ~/miniconda3/lib/python3.9/site-packages/dgl-1.2-py3.9-linux-x86_64.egg/dgl/heterograph_index.py:696, in HeteroGraphIndex.edges(self, etype, order)
691 elif order not in ["srcdst", "eid"]:
692 raise DGLError(
693 "Expect order to be one of None, 'srcdst', 'eid', "
694 "got {}".format(order)
695 )
--> 696 edge_array = _CAPI_DGLHeteroEdges(self, int(etype), order)
697 src = F.from_dgl_nd(edge_array(0))
698 dst = F.from_dgl_nd(edge_array(1))
File dgl/_ffi/_cython/./function.pxi:295, in dgl._ffi._cy3.core.FunctionBase.__call__()
File dgl/_ffi/_cython/./function.pxi:227, in dgl._ffi._cy3.core.FuncCall()
File dgl/_ffi/_cython/./function.pxi:217, in dgl._ffi._cy3.core.FuncCall3()
DGLError: [09:11:40] /home/ubuntu/dgl/src/graph/unit_graph.cc:680: Check failed: order.empty() || order == std::string("srcdst"): CSR only support Edges of order "srcdst", but got "eid".
Stack trace:
[bt] (0) /home/ubuntu/miniconda3/lib/python3.9/site-packages/dgl-1.2-py3.9-linux-x86_64.egg/dgl/libdgl.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x4e) [0x7f10c68a5f06]
[bt] (1) /home/ubuntu/miniconda3/lib/python3.9/site-packages/dgl-1.2-py3.9-linux-x86_64.egg/dgl/libdgl.so(dgl::UnitGraph::CSR::Edges(unsigned long, std::__cxx11::basic_string, std::allocator > const&) const+0x16f) [0x7f10c6f8ff1b]
[bt] (2) /home/ubuntu/miniconda3/lib/python3.9/site-packages/dgl-1.2-py3.9-linux-x86_64.egg/dgl/libdgl.so(dgl::UnitGraph::Edges(unsigned long, std::__cxx11::basic_string, std::allocator > const&) const+0x224) [0x7f10c6f7c5ba]
[bt] (3) /home/ubuntu/miniconda3/lib/python3.9/site-packages/dgl-1.2-py3.9-linux-x86_64.egg/dgl/libdgl.so(dgl::HeteroGraph::Edges(unsigned long, std::__cxx11::basic_string, std::allocator > const&) const+0x76) [0x7f10c6e18e02]
[bt] (4) /home/ubuntu/miniconda3/lib/python3.9/site-packages/dgl-1.2-py3.9-linux-x86_64.egg/dgl/libdgl.so(+0xd9c050) [0x7f10c6e2b050]
[bt] (5) /home/ubuntu/miniconda3/lib/python3.9/site-packages/dgl-1.2-py3.9-linux-x86_64.egg/dgl/libdgl.so(+0xda915a) [0x7f10c6e3815a]
[bt] (6) /home/ubuntu/miniconda3/lib/python3.9/site-packages/dgl-1.2-py3.9-linux-x86_64.egg/dgl/libdgl.so(std::function::operator()(dgl::runtime::DGLArgs, dgl::runtime::DGLRetValue*) const+0x5a) [0x7f10c6d61a72]
[bt] (7) /home/ubuntu/miniconda3/lib/python3.9/site-packages/dgl-1.2-py3.9-linux-x86_64.egg/dgl/libdgl.so(dgl::runtime::PackedFunc::CallPacked(dgl::runtime::DGLArgs, dgl::runtime::DGLRetValue*) const+0x30) [0x7f10c6d60a72]
[bt] (8) /home/ubuntu/miniconda3/lib/python3.9/site-packages/dgl-1.2-py3.9-linux-x86_64.egg/dgl/libdgl.so(DGLFuncCall+0x95) [0x7f10c6d5e236]
```
## Expected behavior
Should work successfully.
## Environment
- DGL Version (e.g., 1.0): master
- Backend Library & Version (e.g., PyTorch 0.4.1, MXNet/Gluon 1.3):
- OS (e.g., Linux):
- How you installed DGL (`conda`, `pip`, source):
- Build command you used (if compiling from source):
- Python version:
- CUDA/cuDNN version (if applicable):
- GPU models and configuration (e.g. V100):
- Any other relevant information:
## Additional information
A workaround is to first convert the graph into COO format and then call `to_homogeneous`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.