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

ValueError: agread: bad input data, first read normal. second error, retry second normal #489

Open
GGBond8488 opened this issue Dec 11, 2023 · 5 comments
Labels

Comments

@GGBond8488
Copy link

I have a batch processing task that will read batch dot files. Reading the first dot file is normal. When reading the second file, an error will be reported. However, if the second file is read again, it will be normal.

Error: syntax error in line 51 near 'subgraph'
Traceback (most recent call last):
File "/root/miniconda3/lib/python3.11/site-packages/pygraphviz/agraph.py", line 1249, in read
self.handle = gv.agread(fh, None)
^^^^^^^^^^^^^^^^^^^
File "/root/miniconda3/lib/python3.11/site-packages/pygraphviz/graphviz.py", line 82, in agread
return _graphviz.agread(input_file, arg2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: agread: bad input data

@dschult
Copy link
Contributor

dschult commented Dec 11, 2023

What is the code you are using and with what inputs. I don’t understand the output. It says at the top there is a syntax error at a line you don’t show here. Then it says there is a ValueError. But what was the value provided to the function. Ideally we would have a short bit of code that reproduces the error along with system and library version so we can reproduce it locally.

@GGBond8488
Copy link
Author

import pygraphviz as pgv


a = pgv.AGraph('./cinn_subgraph.dot') #normal

try:
    b = pgv.AGraph('./cinn_subgraph.dot') #exception
except Exception as e:
    c = pgv.AGraph('./cinn_subgraph.dot') # normal
    print(c)

you can reproduce it with this code

@dschult
Copy link
Contributor

dschult commented Dec 12, 2023

Thanks, that helps. I created a dot file with a single edge and two nodes with the name from the example. I was able to run the example code without error. And I separately loaded the file 3 times to different variables and could check that they have the same nodes and edges.

my installed pygraphviz is v1.10. And the Python version I used is 3.10.
What version of Python and pygraphviz are you using?

———
I’ve tried it now also with Python 3.11 and pygraphviz 1.11. That also worked. Perhaps it has something to do with the dot file contents? Or the OS interface with the dot file?

@GGBond8488
Copy link
Author

pygrphviz-1.11

Name: pygraphviz
Version: 1.11
Summary: Python interface to Graphviz
Home-page: http://pygraphviz.github.io
Author: Aric Hagberg
Author-email: aric.hagberg@gmail.com
License: BSD

python-3.10

Python 3.10.12 (main, Jul 5 2023, 18:54:27) [GCC 11.2.0] on linux

dot_file

digraph G {
   node_2[label="fill_constant_5.tmp_0
[1]
INT64" shape="box" style="rounded,filled,bold" color="#dddddd" fontcolor="#000000"]
   node_0[label="fetch" shape="box" style="rounded,filled,bold" color="#303A3A" fontcolor="#ffffff"]
   node_1[label="fill_constant" shape="box" style="rounded,filled,bold" color="#303A3A" fontcolor="#ffffff"]
   node_1->node_2
   node_2->node_0
} // end G

test_code (add print(e))

import pygraphviz as pgv


a = pgv.AGraph('./cinn_subgraph.dot') #normal

try:
    b = pgv.AGraph('./cinn_subgraph.dot') #exception
except Exception as e:
    c = pgv.AGraph('./cinn_subgraph.dot') # normal
    print(c)

run_ret

Error: syntax error in line 8 near 'node_2'
Invalid Input
digraph G {
node_2 [color="#dddddd",
fontcolor="#000000",
label="fill_constant_5.tmp_0
[1]
INT64",
shape=box,
style="rounded,filled,bold"];
node_0 [color="#303A3A",
fontcolor="#ffffff",
label=fetch,
shape=box,
style="rounded,filled,bold"];
node_2 -> node_0;
node_1 [color="#303A3A",
fontcolor="#ffffff",
label=fill_constant,
shape=box,
style="rounded,filled,bold"];
node_1 -> node_2;
}

OS:

Linux version 5.10.0-1.0.0.26 (gcc (GCC) 8.3.1 20191121 (Red Hat 8.3.1-5), GNU ld version 2.30-79.el8) #1 SMP Thu Apr 20 06:40:16 UTC 2023

graphviz version:

dot - graphviz version 2.40.1 (20161225.0304)

@rossbar
Copy link
Contributor

rossbar commented Dec 12, 2023

I can't reproduce this with pygraphviz 1.10 or 1.11 on either Python 3.10 or 3.11.

If I copy the contents dot_file from the previous post into a file called cinn_subgraph.dot locally then run the following:

>>> import pygraphviz as pgv
>>> pgv.__version__  # for example
'1.11'
>>> for _ in range(10):  # read from file 10 times
...     A = pgv.AGraph("cinn_subgraph.dot")

I don't get any exceptions, and the results are the same every time:

>>> expected = pgv.AGraph("cinn_subgraph.dot")
>>> for _ in range(100):
...     A = pgv.AGraph("cinn_subgraph.dot")
...     assert A.nodes() == expected.nodes()
...     assert A.edges() == expected.edges()

In the OP you mention a batch process - are you reading and writing to files in these batch processes? Bear in mind that graphviz can modify the underlying dotfiles when modifying the AGraph for some operations, e.g. during layout (depending on how things are called). So if you have a script that is e.g. reading and laying out graphs (esp. if it's multithreaded) then that'd be my prime suspect for the source of the issue you're experiencing.

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

No branches or pull requests

3 participants