qiskit-documentation/docs/api/qiskit/0.26/qiskit.converters.dag_to_ci...

63 lines
2.0 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_to_circuit (v0.26)
description: API reference for qiskit.converters.dag_to_circuit in qiskit v0.26
in_page_toc_min_heading_level: 1
python_api_type: function
python_api_name: qiskit.converters.dag_to_circuit
---
<span id="qiskit-converters-dag-to-circuit" />
# qiskit.converters.dag\_to\_circuit
<Function id="qiskit.converters.dag_to_circuit" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.17/qiskit/converters/dag_to_circuit.py" signature="dag_to_circuit(dag)">
Build a `QuantumCircuit` object from a `DAGCircuit`.
**Parameters**
**dag** ([*DAGCircuit*](qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit")) the input dag.
**Returns**
the circuit representing the input dag.
**Return type**
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
**Example**
```python
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.dagcircuit import DAGCircuit
from qiskit.converters import circuit_to_dag
from qiskit.circuit.library.standard_gates import CHGate, U2Gate, CXGate
from qiskit.converters import dag_to_circuit
%matplotlib inline
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)
circuit = dag_to_circuit(dag)
circuit.draw()
```
```python
┌───┐ ┌─┐
q_0: ┤ H ├──■──┤M├───────────
└───┘┌─┴─┐└╥┘┌─────────┐
q_1: ─────┤ X ├─╫─┤ RZ(0.5) ├
└───┘ ║ └────╥────┘
q_2: ───────────╫──────╫─────
║ ┌──╨──┐
c: 3/═══════════╩═══╡ = 2 ╞══
0 └─────┘
```
</Function>