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

dag_drawer should check the existence of filename extension #3099

Closed
we-taper opened this issue Sep 14, 2019 · 13 comments · Fixed by #7447
Closed

dag_drawer should check the existence of filename extension #3099

we-taper opened this issue Sep 14, 2019 · 13 comments · Fixed by #7447
Assignees
Labels
bug Something isn't working good first issue Good for newcomers priority: low

Comments

@we-taper
Copy link

Information

  • Qiskit Terra version: 0.10.0.dev0+831d942
  • Python version: 3.7
  • Operating system: Mac

What is the current behavior?

If a filename without extension is passed to the function dag_drawer, this line reports two errors:

nxpd.pydot.InvocationException: Program terminated with status: 1. stderr follows: Format: "XXXXX" not recognized. Use one of: ......
During handling of the above exception, another exception occurred:
qiskit.visualization.exceptions.VisualizationError: 'dag_drawer requires GraphViz installed in the system. Check https://www.graphviz.org/download/ for details on how to install GraphViz in your system.'

This is confusing because the second error thrown by Qiskit is not the cause of the problem.

Steps to reproduce the problem

Try dag_drawer(dag, filename='abc')

What is the expected behavior?

Make the error catching better.

Suggested solutions

We could either catch this error by reading and filtering the error message, or we could check the existence of the filename's extension, and provide a default one.

@kdk kdk added bug Something isn't working good first issue Good for newcomers labels Sep 16, 2019
@kdk kdk added this to To do in Transpiler via automation Sep 16, 2019
@kdk kdk added this to the 0.10 milestone Sep 16, 2019
@kdk
Copy link
Member

kdk commented Sep 16, 2019

Hi @we-taper , thanks for reporting, and I agree the conflicting error messages are confusing. It looks like the error catching around https://github.com/Qiskit/qiskit-terra/blob/d090eca91dc1afdb68f563885c4ccf13b31de20e/qiskit/visualization/dag_visualization.py#L91 could be refined to either inspect the raised nxpd.pydot.InvocationException to try to determine the cause of the error, or at least include the generated stderr in the VisualizationError that's raised by qiskit.

@splch

This comment has been minimized.

@1ucian0

This comment has been minimized.

@mtreinish mtreinish modified the milestones: 0.10, 0.11 Nov 7, 2019
@mtreinish mtreinish modified the milestones: 0.11, 0.12 Dec 5, 2019
@kdk kdk removed this from the 0.12 milestone Dec 10, 2019
@Rajan117
Copy link

Rajan117 commented Jul 6, 2021

Newcomer here, recently started learning QisKit. Would not mind taking a crack at this.

@javabster
Copy link
Contributor

go for it @Rajan117! I've assigned to you, let us know if you have any questions

@Rajan117
Copy link

Thanks.
I am using this code to reproduce the error.
`from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.dagcircuit import DAGCircuit
from qiskit.converters import circuit_to_dag
from qiskit.visualization import dag_drawer

q = QuantumRegister(3, 'q')
c = ClassicalRegister(3, 'c')
circ = QuantumCircuit(q, c)
circ.h(q[0])
circ.cx(q[0], q[1])
circ.measure(q[0], c[0])
circ.rz(0.5, q[1]).c_if(c, 2)

dag = circuit_to_dag(circ)
dag_drawer(dag, filename='abc')`

But I instead get this error.

image

I assume I have done something wrong in setting up my test environment but unsure how, followed the official QisKit YouTube guide.

@Rajan117
Copy link

I will be honest, I have had a lot of issues in setting up test environments to attempt fixing issues. Is there an easy way to do it?

@javabster
Copy link
Contributor

I will be honest, I have had a lot of issues in setting up test environments to attempt fixing issues. Is there an easy way to do it?

It's best to follow the steps outlined here for the best way to set up your environment (including pip install -e .)

@Rajan117
Copy link

Thanks! Will give this another go over the weekend then :)

@1ucian0
Copy link
Member

1ucian0 commented Sep 17, 2021

unassigning due to lack of activity.

@iuliazidaru
Copy link
Contributor

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.dagcircuit import DAGCircuit
from qiskit.converters import circuit_to_dag
from qiskit.visualization import dag_drawer

q = QuantumRegister(3, 'q')
c = ClassicalRegister(3, 'c')
circ = QuantumCircuit(q, c)
circ.h(q[0])
circ.cx(q[0], q[1])
circ.measure(q[0], c[0])
circ.rz(0.5, q[1]).c_if(c, 2)

dag = circuit_to_dag(circ)
dag_drawer(dag, filename='abc')
"dot" with args ['-Tabc', '/tmp/tmp9ngv_7rl'] returned code: 1

stdout, stderr:
 b''
b'Format: "abc" not recognized. Use one of: bmp canon cmap cmapx cmapx_np dot dot_json eps fig gd gd2 gif gv ico imap imap_np ismap jpe jpeg jpg json json0 mp pdf pic plain plain-ext png pov ps ps2 svg svgz tif tiff tk vdx vml vmlz vrml wbmp webp xdot xdot1.2 xdot1.4 xdot_json\n'

Traceback (most recent call last):
  File "/tmp/ipykernel_78/1404195018.py", line 15, in <module>
    dag_drawer(dag, filename='abc')
  File "/opt/conda/lib/python3.8/site-packages/qiskit/visualization/dag_visualization.py", line 170, in dag_drawer
    dot.write(filename, format=extension)
  File "/opt/conda/lib/python3.8/site-packages/pydot.py", line 1828, in write
    s = self.create(prog, format, encoding=encoding)
  File "/opt/conda/lib/python3.8/site-packages/pydot.py", line 1956, in create
    assert process.returncode == 0, (
AssertionError: "dot" with args ['-Tabc', '/tmp/tmp9ngv_7rl'] returned code: 1

Use %tb to get the full traceback.

I think the message is pretty clear now.

@javabster
Copy link
Contributor

thanks for checking if this is still valid @iuliazidaru! However I think the error is still not very user friendly and it would be good if we could catch it better in the dag_drawer

@iuliazidaru
Copy link
Contributor

@javabster Please assign the issue to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers priority: low
8 participants