Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
derrick710 opened this issue Apr 7, 2024 · 4 comments

Comments

@derrick710
Copy link

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
Copy link

I also have this problem

@nicolasguillard
Copy link

nicolasguillard commented Aug 30, 2024

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 pushed a commit to nicolasguillard/DIG that referenced this issue Sep 7, 2024
- dig/xgraph/method/base_explainer.py : if NetworkX version > 2.4, kwargs keys are filtered according to the available parameters of nx.draw_networkx_nodes and draw_networkx_labels.
- dig/version.py : version updated accordingly
nicolasguillard pushed a commit to nicolasguillard/DIG that referenced this issue Sep 7, 2024
- dig/xgraph/method/base_explainer.py : be sure to take care of default values set in kwargs.
@nicolasguillard
Copy link

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 pushed a commit to nicolasguillard/DIG that referenced this issue Sep 7, 2024
- dig/xgraph/method/base_explainer.py : if NetworkX version > 2.4, kwargs keys are filtered according to the available parameters of nx.draw_networkx_nodes and draw_networkx_labels.
- dig/version.py : version updated accordingly
@nicolasguillard
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants