About cookies on this site Our websites require some cookies to function properly (required). In addition, other cookies may be used with your consent to analyze site usage, improve the user experience and for advertising. For more information, please review your options. By visiting our website, you agree to our processing of information as described in IBM’sprivacy statement. To provide a smooth navigation, your cookie preferences will be shared across the IBM web domains listed here.
qiskit.visualization.dag_drawer
qiskit.visualization.dag_drawer(dag, scale=0.7, filename=None, style='color')
Plot the directed acyclic graph (dag) to represent operation dependencies in a quantum circuit.
This function calls the graphviz_draw()
function from the rustworkx
package to draw the DAG.
Parameters
- dag (DAGCircuit) – The dag to draw.
- scale (float) – scaling factor
- filename (str) – file path to save image to (format inferred from name)
- style (str) – ‘plain’: B&W graph ‘color’ (default): color input/output/op nodes
Returns
if in Jupyter notebook and not saving to file,
otherwise None.
Return type
PIL.Image
Raises
- VisualizationError – when style is not recognized.
- InvalidFileError – when filename provided is not valid
Example
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)
Was this page helpful?
Report a bug or request content on GitHub.