deepsnap icon indicating copy to clipboard operation
deepsnap copied to clipboard

How to convert PyG heterograph to DeepSnap heterograph?

Open Jeriousman opened this issue 3 years ago • 0 comments

I made a PyG heterograph as below.

cipdata
Out[145]: 
HeteroData(
  card={ x=[13752, 302] },
  user={ x=[10996, 304] },
  (user, solved, card)={
    edge_index=[2, 28992],
    edge_attr=[28992]
  },
  (card, rev_solved, user)={
    edge_index=[2, 28992],
    edge_attr=[28992]
  }
)

Then I tried to convert this cipdata PyG heterograph into DeepSnap's heterograph

from deepsnap.hetero_graph import HeteroGraph
graph = HeteroGraph(cipdata)

Then I get this error

graph = HeteroGraph(cipdata)
Traceback (most recent call last):

  File "/home/hojun/anaconda3/envs/geometric/lib/python3.6/site-packages/torch_geometric/data/storage.py", line 48, in __getattr__
    return self[key]

  File "/home/hojun/anaconda3/envs/geometric/lib/python3.6/site-packages/torch_geometric/data/storage.py", line 68, in __getitem__
    return self._mapping[key]

KeyError: 'number_of_nodes'


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "<ipython-input-147-5bdfc5ffc776>", line 1, in <module>
    graph = HeteroGraph(cipdata)

  File "/home/hojun/anaconda3/envs/geometric/lib/python3.6/site-packages/deepsnap/hetero_graph.py", line 94, in __init__
    self._update_tensors(init=True)

  File "/home/hojun/anaconda3/envs/geometric/lib/python3.6/site-packages/deepsnap/graph.py", line 515, in _update_tensors
    self._update_attributes()

  File "/home/hojun/anaconda3/envs/geometric/lib/python3.6/site-packages/deepsnap/graph.py", line 531, in _update_attributes
    if self.G.number_of_nodes() == 0:

  File "/home/hojun/anaconda3/envs/geometric/lib/python3.6/site-packages/torch_geometric/data/hetero_data.py", line 118, in __getattr__
    return getattr(self._global_store, key)

  File "/home/hojun/anaconda3/envs/geometric/lib/python3.6/site-packages/torch_geometric/data/storage.py", line 51, in __getattr__
    f"'{self.__class__.__name__}' object has no attribute '{key}'")

AttributeError: 'BaseStorage' object has no attribute 'number_of_nodes'

How do I easily convert pyg heterograph to deepsnap one?

I wish some detailed example code can be provided.

Jeriousman avatar Feb 25 '22 03:02 Jeriousman