How to apply NN modules on DGLHeteroGraph?

I have a DGLHeteroGraph, and I want to process it as a homo-graph after some operation and calling dgl.to_homo(), however this method still returns a DGLHeteroGraph. If I want to use NN modules on it,

homo_g = dgl.to_homo(g)
self.gat1 = GATConv(in_feats=self.entity_dim, out_feats=8, num_heads=8, activation=nn.ELU(),
                            feat_drop=0.6, attn_drop=0.6)
node_feats = self.gat1(homo_g, homo_g.nodes['_N'].data['feature'])

the following error would occur,

File "/home/weiguoao/anaconda3/envs/wga/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/weiguoao/projects/KG-GAT/models.py", line 167, in forward
    node_feats = self.gat1(homo_g, homo_g.nodes['_N'].data['feature'])
  File "/home/weiguoao/anaconda3/envs/wga/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/weiguoao/anaconda3/envs/wga/lib/python3.7/site-packages/dgl/nn/pytorch/conv/gatconv.py", line 111, in forward
    graph.edata['a'] = self.attn_drop(edge_softmax(graph, e))
  File "/home/weiguoao/anaconda3/envs/wga/lib/python3.7/site-packages/dgl/nn/pytorch/softmax.py", line 179, in edge_softmax
    return EdgeSoftmax.apply(graph, logits, eids)
  File "/home/weiguoao/anaconda3/envs/wga/lib/python3.7/site-packages/dgl/nn/pytorch/softmax.py", line 52, in forward
    gidx = g._graph.get_immutable_gidx(utils.to_dgl_context(score.device))
  File "dgl/_ffi/_cython/./object.pxi", line 64, in dgl._ffi._cy3.core.ObjectBase.__getattr__
AttributeError: '<class 'dgl.heterograph_index.HeteroGraphIndex'>' object has no attribute 'get_immutable_gidx'

is there any way I could apply NN modules on homo DGLHeteroGraph? Maybe I can convert DGLHeteroGraph to DGLGraph?

OS: Ubuntu 16.04
DGL version: dgl-cu100 0.4.2

Hi, currently our SAGEConv model supports DGLHeteroGraph.
For our models, I’m working on refactoring the code to let them support heterographs, please stay tuned.

Hi,

The problem should be fixed in the nightly builds. Could you try installing the nightly build and run it again?

pip install --pre dgl  (or pip install --pre dgl-cu100 for CUDA 10.0 etc.)

My previously DGLHeteroGraph was saved as .pkl. I installed the nightly builds and tried to load from .pkl, this error occured,

  File "/home/weiguoao/projects/KG-GAT/dataset.py", line 33, in __init__
    self.g = pickle.load(f)
  File "/home/weiguoao/anaconda3/envs/dgl-pre/lib/python3.7/site-packages/dgl/heterograph_index.py", line 32, in __setstate__
    self.__init_handle_by_constructor__(_CAPI_DGLHeteroUnpickle, state)
  File "dgl/_ffi/_cython/./object.pxi", line 86, in dgl._ffi._cy3.core.ObjectBase.__init_handle_by_constructor__
  File "dgl/_ffi/_cython/./function.pxi", line 244, in dgl._ffi._cy3.core.ConstructorCall
  File "dgl/_ffi/_cython/./function.pxi", line 222, in dgl._ffi._cy3.core.FuncCall
  File "dgl/_ffi/_cython/./function.pxi", line 210, in dgl._ffi._cy3.core.FuncCall3
  File "dgl/_ffi/_cython/./function.pxi", line 135, in dgl._ffi._cy3.core.make_arg
  File "/home/weiguoao/anaconda3/envs/dgl-pre/lib/python3.7/site-packages/dgl/_ffi/object_generic.py", line 38, in convert_to_object
    value = [convert_to_object(x) for x in value]
  File "/home/weiguoao/anaconda3/envs/dgl-pre/lib/python3.7/site-packages/dgl/_ffi/object_generic.py", line 38, in <listcomp>
    value = [convert_to_object(x) for x in value]
  File "/home/weiguoao/anaconda3/envs/dgl-pre/lib/python3.7/site-packages/dgl/_ffi/object_generic.py", line 38, in convert_to_object
    value = [convert_to_object(x) for x in value]
  File "/home/weiguoao/anaconda3/envs/dgl-pre/lib/python3.7/site-packages/dgl/_ffi/object_generic.py", line 38, in <listcomp>
    value = [convert_to_object(x) for x in value]
  File "/home/weiguoao/anaconda3/envs/dgl-pre/lib/python3.7/site-packages/dgl/_ffi/object_generic.py", line 38, in convert_to_object
    value = [convert_to_object(x) for x in value]
  File "/home/weiguoao/anaconda3/envs/dgl-pre/lib/python3.7/site-packages/dgl/_ffi/object_generic.py", line 38, in <listcomp>
    value = [convert_to_object(x) for x in value]
  File "/home/weiguoao/anaconda3/envs/dgl-pre/lib/python3.7/site-packages/dgl/_ffi/object_generic.py", line 51, in convert_to_object
    return _api_internal._Value(value)
  File "dgl/_ffi/_cython/./function.pxi", line 287, in dgl._ffi._cy3.core.FunctionBase.__call__
  File "dgl/_ffi/_cython/./function.pxi", line 222, in dgl._ffi._cy3.core.FuncCall
  File "dgl/_ffi/_cython/./function.pxi", line 210, in dgl._ffi._cy3.core.FuncCall3
  File "dgl/_ffi/_cython/./function.pxi", line 154, in dgl._ffi._cy3.core.make_arg
TypeError: Don't know how to handle type <class 'dgl.utils.Index'>

I rebuild the graph and try to save&load, the same error still occured.

Hi,

I don’t think we maintain the compatibility of pickle dumps across DGL versions.

However, since you mentioned rebuilding the graph and saving/loading afterwards, I tried saving and loading with a heterograph with pickle and could not reproduce the error. Could you tell us how you save and load the graph? Thanks!

I found that the problem occurred because I save the graph using 0.4.2 but load with 0.4.3, thank you for your answer anyway.
By the way, is there an official API for saving&loading heterograph?