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

networkx.drawing.nx_pydot.read_dot parses dot files incorrectly #5353

Closed
nico5300 opened this issue Feb 21, 2022 · 2 comments
Closed

networkx.drawing.nx_pydot.read_dot parses dot files incorrectly #5353

nico5300 opened this issue Feb 21, 2022 · 2 comments

Comments

@nico5300
Copy link

nico5300 commented Feb 21, 2022

I tried to load the dot file of a control flow graph created by LLVM down below into a networkx graph using this code:

import networkx.drawing.nx_pydot as nxp
import networkx as nx
g = nx.read_dot("/path/to/file/cfg.dot")
print(g.nodes)

When looking at the dotfile down below one would assume three nodes being connected by two edges. But in reality one more node gets created with the label "\\n".

Steps to Reproduce

Load following dotfile with the code above and print the node list:

digraph "CFG for 'fn_1140' function" {
	label="CFG for 'fn_1140' function";

	Node0x5563aaa6daa0 [shape=record,color="#b70d28ff", style=filled, fillcolor="#b70d2870",label="{entry_fn_1140}"];
	Node0x5563aaa6daa0 -> Node0x5563aaa6f850;
	Node0x5563aaa6dc60 [shape=record,color="#b70d28ff", style=filled, fillcolor="#b70d2870",label="{exit_fn_1140}"];
	Node0x5563aaa6f850 [shape=record,color="#b70d28ff", style=filled, fillcolor="#b70d2870",label="{bb_1140}"];
	Node0x5563aaa6f850 -> Node0x5563aaa6dc60;
}

When removing the newline immediately preceeding the closing curly brace, we get the correct graph. Also when swapping the last node definition with the last edge definition.

Environment

Python version: 3.10
NetworkX version: 2.6.3
Pydot version: 1.4.2

@rossbar
Copy link
Contributor

rossbar commented Feb 21, 2022

I suspect this is related to pydot/pydot#277. NetworkX has had to xfail the nx_pydot tests due to the pydot/pyparsing issues. You can try installing the older version of pyparsing in your environment, e.g.

pip install pyparsing==2.4.7
pip install pydot networkx

Though this certainly isn't a long term solution. Unfortunately I don't think there's anything NX can do unless/until this is fixed upstream.

@nico5300
Copy link
Author

Ah I see! Thanks for the workaround :)
I'll close the issue then.

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

No branches or pull requests

2 participants