qiskit-documentation/docs/api/qiskit/1.2/qiskit.visualization.dag_dr...

61 lines
2.4 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: dag_drawer (v1.2)
description: API reference for qiskit.visualization.dag_drawer in qiskit v1.2
in_page_toc_min_heading_level: 1
python_api_type: function
python_api_name: qiskit.visualization.dag_drawer
---
<span id="qiskit-visualization-dag-drawer" />
# qiskit.visualization.dag\_drawer
<Function id="qiskit.visualization.dag_drawer" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/visualization/dag_visualization.py#L29-L230" signature="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()`](https://www.rustworkx.org/apiref/rustworkx.visualization.graphviz_draw.html#rustworkx.visualization.graphviz_draw "(in rustworkx v0.15)") function from the `rustworkx` package to draw the DAG.
**Parameters**
* **dag** ([*DAGCircuit*](qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit")) The dag to draw.
* **scale** ([*float*](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")) scaling factor
* **filename** ([*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")) file path to save image to (format inferred from name)
* **style** ([*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")) 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**](visualization#qiskit.visualization.VisualizationError "qiskit.visualization.VisualizationError") when style is not recognized.
* [**InvalidFileError**](exceptions#qiskit.exceptions.InvalidFileError "qiskit.exceptions.InvalidFileError") when filename provided is not valid
**Example**
```python
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)
```
</Function>