Skip to content

Commit

Permalink
Restore the use of rustworkx.graphviz_draw() for non-DAGCircuit dag v…
Browse files Browse the repository at this point in the history
…isualization
  • Loading branch information
mtreinish committed Aug 7, 2024
1 parent f4e0655 commit b6236dc
Showing 1 changed file with 38 additions and 25 deletions.
63 changes: 38 additions & 25 deletions qiskit/visualization/dag_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import io
import subprocess

from rustworkx.visualization import graphviz_draw

from qiskit.dagcircuit.dagnode import DAGOpNode, DAGInNode, DAGOutNode
from qiskit.dagcircuit.dagcircuit import DAGCircuit
from qiskit.circuit import Qubit, Clbit, ClassicalRegister
from qiskit.circuit.classical import expr
from qiskit.converters import dagdependency_to_circuit
Expand Down Expand Up @@ -273,31 +276,41 @@ def edge_attr_func(edge):
f"{IMAGE_TYPES}"
)

dot_str = dag._to_dot(
graph_attrs,
node_attr_func,
edge_attr_func,
)

prog = "dot"
if not filename:
dot_result = subprocess.run(
[prog, "-T", image_type],
input=dot_str.encode("utf-8"),
capture_output=True,
encoding=None,
check=True,
text=False,
if isinstance(dag, DAGCircuit):
dot_str = dag._to_dot(
graph_attrs,
node_attr_func,
edge_attr_func,
)
dot_bytes_image = io.BytesIO(dot_result.stdout)
image = Image.open(dot_bytes_image)
return image

prog = "dot"
if not filename:
dot_result = subprocess.run(
[prog, "-T", image_type],
input=dot_str.encode("utf-8"),
capture_output=True,
encoding=None,
check=True,
text=False,
)
dot_bytes_image = io.BytesIO(dot_result.stdout)
image = Image.open(dot_bytes_image)
return image
else:
subprocess.run(
[prog, "-T", image_type, "-o", filename],
input=dot_str,
check=True,
encoding="utf8",
text=True,
)
return None
else:
subprocess.run(
[prog, "-T", image_type, "-o", filename],
input=dot_str,
check=True,
encoding="utf8",
text=True,
return graphviz_draw(
dag._multi_graph,
node_attr_func,
edge_attr_func,
graph_attrs,
filename,
image_type,
)
return None

0 comments on commit b6236dc

Please sign in to comment.