Issue with AttributeError: 'DGLGraph' object has no attribute 'adjacency_matrix_scipy'

Hello,

I am a student trying to implement the code from Benchmarking Graph Neural Networks ( GitHub - graphdeeplearning/benchmarking-gnns: Repository for benchmarking graph neural networks ). Unfortunately it seems that their code base is using DGL for a version prior to 1.0.x.

I am having the following issue, which seems to stem from the fact that method adjacency_matrix_scipy was moved from the DGLGraph class to the HeteroGraphIndex as of DGL 1.0.x.

I am not certain how to resolve this issue as I’m not very familiar with Python indexing. I assume the class HeteroGraphIndex ought to be created implicitly here? Can anyone advise?

Thank you very much for your time.

P.S. I’ve posted an issue on their github as well. But if anyone here can suggest how to update this particular issue, I would be very grateful.

AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_19948\3633482862.py in <module>
    236     cleaner_main('main_SBMs_node_classification')
    237 
--> 238     main(True,config)
    239 
    240 else:

~\AppData\Local\Temp\ipykernel_19948\3633482862.py in main(notebook_mode, config)
    197 
    198     net_params['total_param'] = view_model_param(MODEL_NAME, net_params)
--> 199     train_val_pipeline(MODEL_NAME, dataset, params, net_params, dirs)
    200 
    201 

~\AppData\Local\Temp\ipykernel_19948\760033787.py in train_val_pipeline(MODEL_NAME, dataset, params, net_params, dirs)
     18         if net_params['pos_enc']:
     19             print("[!] Adding graph positional encoding.")
---> 20             dataset._add_positional_encodings(net_params['pos_enc_dim'])
     21             print('Time PE:',time.time()-start0)
     22 

D:\ProgramData\benchmarking-gnns\data\SBMs.py in _add_positional_encodings(self, pos_enc_dim)
    241 
    242         # Graph positional encoding v/ Laplacian eigenvectors
--> 243         self.train.graph_lists = [positional_encoding(g, pos_enc_dim) for g in self.train.graph_lists]
    244         self.val.graph_lists = [positional_encoding(g, pos_enc_dim) for g in self.val.graph_lists]
    245         self.test.graph_lists = [positional_encoding(g, pos_enc_dim) for g in self.test.graph_lists]

D:\ProgramData\benchmarking-gnns\data\SBMs.py in <listcomp>(.0)
    241 
    242         # Graph positional encoding v/ Laplacian eigenvectors
--> 243         self.train.graph_lists = [positional_encoding(g, pos_enc_dim) for g in self.train.graph_lists]
    244         self.val.graph_lists = [positional_encoding(g, pos_enc_dim) for g in self.val.graph_lists]
    245         self.test.graph_lists = [positional_encoding(g, pos_enc_dim) for g in self.test.graph_lists]

D:\ProgramData\benchmarking-gnns\data\SBMs.py in positional_encoding(g, pos_enc_dim)
    126     """
    127     # Laplacian
--> 128     A = g.adjacency_matrix_scipy(return_edge_ids=False).astype(float)
    129     N = sp.diags(dgl.backend.asnumpy(g.in_degrees()).clip(1) ** -0.5, dtype=float)
    130     L = sp.eye(g.number_of_nodes()) - N * A * N

AttributeError: 'DGLGraph' object has no attribute 'adjacency_matrix_scipy'

Hi, @mtd7, you can use the api dgl.DGLGraph.adj — DGL 1.0.2 documentation as an alternative.

Specifically, replace the line

A = g.adjacency_matrix_scipy(return_edge_ids=False).astype(float)

with

A = g.adj(scipy_fmt='csr')
1 Like

That worked, thank you very much!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.