divelab / DIG

A library for graph deep learning research
https://diveintographs.readthedocs.io/
GNU General Public License v3.0
1.85k stars 281 forks source link

TypeError: draw_networkx_nodes() got an unexpected keyword argument 'with_labels' #242

Open derrick710 opened 6 months ago

derrick710 commented 6 months ago

I am trying to recreate the GNNExplainer on Google Colab using the example xgraph_code_tutorial.ipynb. Everything works great until I try to visualize the graph. Thank you for your help


sparsity = 0.7
import matplotlib.pyplot as plt

# Visualization
gnnexplainer_related_preds = \
    gnnexplainer(data.x, data.edge_index, sparsity=sparsity, num_classes=num_classes, node_idx=node_idx)
ax, G = gnnexplainer.visualize_graph(node_idx=node_idx,
                                     edge_index=data.edge_index,
                                     edge_mask=gnnexplainer_related_preds[1][prediction],
                                     y=data.y)
plt.show()

TypeError                                 Traceback (most recent call last)
[<ipython-input-8-413a9bd50c1c>](https://localhost:8080/#) in <cell line: 7>()
      5 gnnexplainer_related_preds = \
      6     gnnexplainer(data.x, data.edge_index, sparsity=sparsity, num_classes=num_classes, node_idx=node_idx)
----> 7 ax, G = gnnexplainer.visualize_graph(node_idx=node_idx,
      8                                      edge_index=data.edge_index,
      9                                      edge_mask=gnnexplainer_related_preds[1][prediction],

[/usr/local/lib/python3.10/dist-packages/dig/xgraph/method/base_explainer.py](https://localhost:8080/#) in visualize_graph(self, node_idx, edge_index, edge_mask, y, threshold, nolabel, **kwargs)
    240                     connectionstyle="arc3,rad=0.08",  # rad control angle
    241                 ))
--> 242         nx.draw_networkx_nodes(G, pos, node_color=node_colors, **kwargs)
    243         # define node labels
    244         if self.molecule:

TypeError: draw_networkx_nodes() got an unexpected keyword argument 'with_labels'
Moses14159 commented 4 months ago

I also have this problem

nicolasguillard commented 1 month ago

The draw_networkx_nodes() function doesn't accept any more extra argument (and with_labels is not a regular one) since version 2.5 of NetworkX. I tried to install version 2.4 but I got a depency issue, trying to run the notebook in Colab. I have sourced the bug, so I am trying to fix it then submit a pull request, and to provide an alternative way to install the fix meanwhile.

nicolasguillard commented 3 weeks ago

Hi,

You can install the last release + bug fix from the sources of my fork until the pull request is approved and the 1.1.1 release is provided to pypi, following the instructions (inspired from the DIG installation from source procedure )

Locally, in a virtual env (recommanded) :

git clone --branch Main_111_hotfix_issue_242 https://github.com/nicolasguillard/DIG.git
pip -q install ./DIG

In Google Colab :

!git clone --branch Main_111_hotfix_issue_242 https://github.com/nicolasguillard/DIG.git
!pip -q install ./DIG

Let me know if you have any new issue.

Regards.

nicolasguillard commented 3 weeks ago

In addition, if you are using the dig-stable version, you can install the sources including bug fix #242 by following these instructions :

Locally, in a virtual env (recommanded) :

git clone --branch bugfix_issue_242 https://github.com/nicolasguillard/DIG.git
pip -q install ./DIG

In Google Colab :

!git clone --branch bugfix_issue_242 https://github.com/nicolasguillard/DIG.git
!pip -q install ./DIG