---
title: QuantumCircuit (latest version)
description: API reference for qiskit.circuit.QuantumCircuit in the latest version of qiskit
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit/qiskit.circuit.QuantumCircuit
---

# [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") class

*class* `qiskit.circuit.QuantumCircuit(*regs, name=None, global_phase=0, metadata=None, inputs=(), captures=(), declarations=())`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L111-L7794)

Bases: [`object`](https://docs.python.org/3/library/functions.html#object)

Core Qiskit representation of a quantum circuit.

> **Note**
>
> For more details setting the [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") in context of all of the data structures that go with it, how it fits into the rest of the [`qiskit`](/docs/api/qiskit/index#module-qiskit "qiskit") package, and the different regimes of quantum-circuit descriptions in Qiskit, see the module-level documentation of [`qiskit.circuit`](/docs/api/qiskit/circuit#module-qiskit.circuit "qiskit.circuit").

Example:

```python
from qiskit import QuantumCircuit

# Create a new circuit with two qubits
qc = QuantumCircuit(2)

# Add a Hadamard gate to qubit 0
qc.h(0)

# Perform a controlled-X gate on qubit 1, controlled by qubit 0
qc.cx(0, 1)

# Return a text drawing of the circuit.
qc.draw()
```

```text
     ┌───┐
q_0: ┤ H ├──■──
     └───┘┌─┴─┐
q_1: ─────┤ X ├
          └───┘
```

## Circuit attributes

[`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") has a small number of public attributes, which are mostly older functionality. Most of its functionality is accessed through methods.

A small handful of the attributes are intentionally mutable, the rest are data attributes that should be considered immutable.

| Mutable attribute                                                                                          | Summary                                                                                                     |
| ---------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| [`global_phase`](#qiskit.circuit.QuantumCircuit.global_phase "qiskit.circuit.QuantumCircuit.global_phase") | The global phase of the circuit, measured in radians.                                                       |
| [`metadata`](#qiskit.circuit.QuantumCircuit.metadata "qiskit.circuit.QuantumCircuit.metadata")             | Arbitrary user mapping, which Qiskit will preserve through the transpiler, but otherwise completely ignore. |
| [`name`](#qiskit.circuit.QuantumCircuit.name "qiskit.circuit.QuantumCircuit.name")                         | An optional string name for the circuit.                                                                    |

| Immutable data attribute                                                                                                                 | Summary                                                                                                                                                                                                                                                    |
| ---------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`ancillas`](#qiskit.circuit.QuantumCircuit.ancillas "qiskit.circuit.QuantumCircuit.ancillas")                                           | List of [`AncillaQubit`](/docs/api/qiskit/circuit#qiskit.circuit.AncillaQubit "qiskit.circuit.AncillaQubit")s tracked by the circuit.                                                                                                                      |
| [`cregs`](#qiskit.circuit.QuantumCircuit.cregs "qiskit.circuit.QuantumCircuit.cregs")                                                    | List of [`ClassicalRegister`](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister")s tracked by the circuit.                                                                                                       |
| [`clbits`](#qiskit.circuit.QuantumCircuit.clbits "qiskit.circuit.QuantumCircuit.clbits")                                                 | List of [`Clbit`](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")s tracked by the circuit.                                                                                                                                           |
| [`data`](#qiskit.circuit.QuantumCircuit.data "qiskit.circuit.QuantumCircuit.data")                                                       | List of individual [`CircuitInstruction`](/docs/api/qiskit/qiskit.circuit.CircuitInstruction "qiskit.circuit.CircuitInstruction")s that make up the circuit.                                                                                               |
| `_data`                                                                                                                                  | Python-space handle to the C API `QkCircuit` object.                                                                                                                                                                                                       |
| [`duration`](#qiskit.circuit.QuantumCircuit.duration "qiskit.circuit.QuantumCircuit.duration")                                           | Total duration of the circuit, added by scheduling transpiler passes. This attribute is deprecated and [`estimate_duration()`](#qiskit.circuit.QuantumCircuit.estimate_duration "qiskit.circuit.QuantumCircuit.estimate_duration") should be used instead. |
| [`layout`](#qiskit.circuit.QuantumCircuit.layout "qiskit.circuit.QuantumCircuit.layout")                                                 | Hardware layout and routing information added by the transpiler.                                                                                                                                                                                           |
| [`num_ancillas`](#qiskit.circuit.QuantumCircuit.num_ancillas "qiskit.circuit.QuantumCircuit.num_ancillas")                               | The number of ancilla qubits in the circuit.                                                                                                                                                                                                               |
| [`num_clbits`](#qiskit.circuit.QuantumCircuit.num_clbits "qiskit.circuit.QuantumCircuit.num_clbits")                                     | The number of clbits in the circuit.                                                                                                                                                                                                                       |
| [`num_captured_vars`](#qiskit.circuit.QuantumCircuit.num_captured_vars "qiskit.circuit.QuantumCircuit.num_captured_vars")                | Number of captured real-time classical variables.                                                                                                                                                                                                          |
| [`num_captured_stretches`](#qiskit.circuit.QuantumCircuit.num_captured_stretches "qiskit.circuit.QuantumCircuit.num_captured_stretches") | Number of captured stretches.                                                                                                                                                                                                                              |
| [`num_declared_vars`](#qiskit.circuit.QuantumCircuit.num_declared_vars "qiskit.circuit.QuantumCircuit.num_declared_vars")                | Number of locally declared real-time classical variables in the outer circuit scope.                                                                                                                                                                       |
| [`num_declared_stretches`](#qiskit.circuit.QuantumCircuit.num_declared_stretches "qiskit.circuit.QuantumCircuit.num_declared_stretches") | Number of locally declared stretches in the outer circuit scope.                                                                                                                                                                                           |
| [`num_input_vars`](#qiskit.circuit.QuantumCircuit.num_input_vars "qiskit.circuit.QuantumCircuit.num_input_vars")                         | Number of input real-time classical variables.                                                                                                                                                                                                             |
| [`num_parameters`](#qiskit.circuit.QuantumCircuit.num_parameters "qiskit.circuit.QuantumCircuit.num_parameters")                         | Number of compile-time [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter")s in the circuit.                                                                                                                                |
| [`num_qubits`](#qiskit.circuit.QuantumCircuit.num_qubits "qiskit.circuit.QuantumCircuit.num_qubits")                                     | Number of qubits in the circuit.                                                                                                                                                                                                                           |
| [`num_vars`](#qiskit.circuit.QuantumCircuit.num_vars "qiskit.circuit.QuantumCircuit.num_vars")                                           | Total number of real-time classical variables in the outer circuit scope.                                                                                                                                                                                  |
| [`num_stretches`](#qiskit.circuit.QuantumCircuit.num_stretches "qiskit.circuit.QuantumCircuit.num_stretches")                            | Total number of stretches in the outer circuit scope.                                                                                                                                                                                                      |
| [`num_identifiers`](#qiskit.circuit.QuantumCircuit.num_identifiers "qiskit.circuit.QuantumCircuit.num_identifiers")                      | Total number of both variables and stretches in the outer circuit.                                                                                                                                                                                         |
| [`op_start_times`](#qiskit.circuit.QuantumCircuit.op_start_times "qiskit.circuit.QuantumCircuit.op_start_times")                         | Start times of scheduled operations, added by scheduling transpiler passes.                                                                                                                                                                                |
| [`parameters`](#qiskit.circuit.QuantumCircuit.parameters "qiskit.circuit.QuantumCircuit.parameters")                                     | Ordered set-like view of the compile-time [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter")s tracked by the circuit.                                                                                                     |
| [`qregs`](#qiskit.circuit.QuantumCircuit.qregs "qiskit.circuit.QuantumCircuit.qregs")                                                    | List of [`QuantumRegister`](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")s tracked by the circuit.                                                                                                             |
| [`qubits`](#qiskit.circuit.QuantumCircuit.qubits "qiskit.circuit.QuantumCircuit.qubits")                                                 | List of [`Qubit`](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")s tracked by the circuit.                                                                                                                                           |
| [`unit`](#qiskit.circuit.QuantumCircuit.unit "qiskit.circuit.QuantumCircuit.unit")                                                       | The unit of the [`duration`](#qiskit.circuit.QuantumCircuit.duration "qiskit.circuit.QuantumCircuit.duration") field.                                                                                                                                      |

The core attribute is [`data`](#qiskit.circuit.QuantumCircuit.data "qiskit.circuit.QuantumCircuit.data"). This is a sequence-like object that exposes the [`CircuitInstruction`](/docs/api/qiskit/qiskit.circuit.CircuitInstruction "qiskit.circuit.CircuitInstruction")s contained in an ordered form. You generally should not mutate this object directly; [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") is only designed for append-only operations (which should use [`append()`](#qiskit.circuit.QuantumCircuit.append "qiskit.circuit.QuantumCircuit.append")). Most operations that mutate circuits in place should be written as transpiler passes ([`qiskit.transpiler`](/docs/api/qiskit/transpiler#module-qiskit.transpiler "qiskit.transpiler")). The C API interacts with an internal object, called `_data`, which is not part of the public Python API, other than as a handle to pass to C-API calls.

### data

The circuit data (instructions and context).

**Example**

```python
from qiskit import QuantumCircuit

qc = QuantumCircuit(2, 2)
qc.measure([0], [1])
print(qc.data)
```

```text
[CircuitInstruction(operation=Instruction(name='measure', num_qubits=1,
num_clbits=1, params=[]), qubits=(Qubit(QuantumRegister(2, 'q'), 0),),
clbits=(Clbit(ClassicalRegister(2, 'c'), 1),))]
```

**Returns**

A list-like object containing the [`CircuitInstruction`](/docs/api/qiskit/qiskit.circuit.CircuitInstruction "qiskit.circuit.CircuitInstruction") instances in the circuit.

Alongside the [`data`](#qiskit.circuit.QuantumCircuit.data "qiskit.circuit.QuantumCircuit.data"), the [`global_phase`](#qiskit.circuit.QuantumCircuit.global_phase "qiskit.circuit.QuantumCircuit.global_phase") of a circuit can have some impact on its output, if the circuit is used to describe a [`Gate`](/docs/api/qiskit/qiskit.circuit.Gate "qiskit.circuit.Gate") that may be controlled. This is measured in radians and is directly settable.

### global\_phase

The global phase of the current circuit scope in radians.

**Example**

```python
from qiskit import QuantumCircuit

circuit = QuantumCircuit(2)
circuit.h(0)
circuit.cx(0, 1)
print(circuit.global_phase)
```

```text
0.0
```

```python
from numpy import pi

circuit.global_phase = pi/4
print(circuit.global_phase)
```

```text
0.7853981633974483
```

The [`name`](#qiskit.circuit.QuantumCircuit.name "qiskit.circuit.QuantumCircuit.name") of a circuit becomes the name of the [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction") or [`Gate`](/docs/api/qiskit/qiskit.circuit.Gate "qiskit.circuit.Gate") resulting from [`to_instruction()`](#qiskit.circuit.QuantumCircuit.to_instruction "qiskit.circuit.QuantumCircuit.to_instruction") and [`to_gate()`](#qiskit.circuit.QuantumCircuit.to_gate "qiskit.circuit.QuantumCircuit.to_gate") calls, which can be handy for visualizations.

### name

Type: `str`

A human-readable name for the circuit.

**Example**

```python
from qiskit import QuantumCircuit

qc = QuantumCircuit(2, 2, name="my_circuit")
print(qc.name)
```

```text
my_circuit
```

You can attach arbitrary [`metadata`](#qiskit.circuit.QuantumCircuit.metadata "qiskit.circuit.QuantumCircuit.metadata") to a circuit. No part of core Qiskit will inspect this or change its behavior based on metadata, but it will be faithfully passed through the transpiler, so you can tag your circuits yourself. When serializing a circuit with QPY (see [`qiskit.qpy`](/docs/api/qiskit/qpy#module-qiskit.qpy "qiskit.qpy")), the metadata will be JSON-serialized and you may need to pass a custom serializer to handle non-JSON-compatible objects within it (see [`qpy.dump()`](/docs/api/qiskit/qpy#qiskit.qpy.dump "qiskit.qpy.dump") for more detail). This field is ignored during export to OpenQASM 2 or 3.

### metadata

Arbitrary user-defined dictionary of metadata for the circuit.

Qiskit will not examine the content of this mapping, but it will pass it through the transpiler and reattach it to the output, so you can track your own metadata.

**Example**

```python
from qiskit import QuantumCircuit

qc = QuantumCircuit(2, 2, metadata={'experiment_type': 'Bell state experiment'})

print(qc.metadata)
```

```text
{'experiment_type': 'Bell state experiment'}
```

[`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") exposes data attributes tracking its internal quantum and classical bits and registers. These appear as Python [`list`](https://docs.python.org/3/library/stdtypes.html#list)s, but you should treat them as immutable; changing them will *at best* have no effect, and more likely will simply corrupt the internal data of the [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit").

### qregs

A list of [`Qubit`](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")s in the order that they were added. You should not mutate this.

### cregs

A list of [`Clbit`](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")s in the order that they were added. You should not mutate this.

### qubits

A list of [`Qubit`](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")s in the order that they were added. You should not mutate this.

### ancillas

A list of [`AncillaQubit`](/docs/api/qiskit/circuit#qiskit.circuit.AncillaQubit "qiskit.circuit.AncillaQubit")s in the order that they were added. You should not mutate this.

### clbits

A list of [`Clbit`](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")s in the order that they were added. You should not mutate this.

**Example**

```python
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit

qr1 = QuantumRegister(2)
qr2 = QuantumRegister(1)
cr1 = ClassicalRegister(2)
cr2 = ClassicalRegister(1)
qc = QuantumCircuit(qr1, qr2, cr1, cr2)

print("List the qubits in this circuit:", qc.qubits)
print("List the classical bits in this circuit:", qc.clbits)
```

```text
List the qubits in this circuit: [Qubit(QuantumRegister(2, 'q0'), 0),
Qubit(QuantumRegister(2, 'q0'), 1), Qubit(QuantumRegister(1, 'q1'), 0)]
List the classical bits in this circuit: [Clbit(ClassicalRegister(2, 'c0'), 0),
Clbit(ClassicalRegister(2, 'c0'), 1), Clbit(ClassicalRegister(1, 'c1'), 0)]
```

The [compile-time parameters](/docs/api/qiskit/circuit#circuit-compile-time-parameters) present in instructions on the circuit are available in [`parameters`](#qiskit.circuit.QuantumCircuit.parameters "qiskit.circuit.QuantumCircuit.parameters"). This has a canonical order (mostly lexical, except in the case of [`ParameterVector`](/docs/api/qiskit/qiskit.circuit.ParameterVector "qiskit.circuit.ParameterVector")), which matches the order that parameters will be assigned when using the list forms of [`assign_parameters()`](#qiskit.circuit.QuantumCircuit.assign_parameters "qiskit.circuit.QuantumCircuit.assign_parameters"), but also supports [`set`](https://docs.python.org/3/library/stdtypes.html#set)-like constant-time membership testing.

### parameters

The parameters defined in the circuit.

This attribute returns the [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter") objects in the circuit sorted alphabetically. Note that parameters instantiated with a [`ParameterVector`](/docs/api/qiskit/qiskit.circuit.ParameterVector "qiskit.circuit.ParameterVector") are still sorted numerically.

**Examples**

The snippet below shows that insertion order of parameters does not matter.

```python
>>> from qiskit.circuit import QuantumCircuit, Parameter
>>> a, b, elephant = Parameter("a"), Parameter("b"), Parameter("elephant")
>>> circuit = QuantumCircuit(1)
>>> circuit.rx(b, 0)
>>> circuit.rz(elephant, 0)
>>> circuit.ry(a, 0)
>>> circuit.parameters  # sorted alphabetically!
ParameterView([Parameter(a), Parameter(b), Parameter(elephant)])
```

Bear in mind that alphabetical sorting might be unintuitive when it comes to numbers. The literal “10” comes before “2” in strict alphabetical sorting.

```python
>>> from qiskit.circuit import QuantumCircuit, Parameter
>>> angles = [Parameter("angle_1"), Parameter("angle_2"), Parameter("angle_10")]
>>> circuit = QuantumCircuit(1)
>>> circuit.u(*angles, 0)
>>> circuit.draw()
   ┌─────────────────────────────┐
q: ┤ U(angle_1,angle_2,angle_10) ├
   └─────────────────────────────┘
>>> circuit.parameters
ParameterView([Parameter(angle_1), Parameter(angle_10), Parameter(angle_2)])
```

To respect numerical sorting, a [`ParameterVector`](/docs/api/qiskit/qiskit.circuit.ParameterVector "qiskit.circuit.ParameterVector") can be used.

```python
>>> from qiskit.circuit import QuantumCircuit, Parameter, ParameterVector
>>> x = ParameterVector("x", 12)
>>> circuit = QuantumCircuit(1)
>>> for x_i in x:
...     circuit.rx(x_i, 0)
>>> circuit.parameters
ParameterView([
    ParameterVectorElement(x[0]), ParameterVectorElement(x[1]),
    ParameterVectorElement(x[2]), ParameterVectorElement(x[3]),
    ..., ParameterVectorElement(x[11])
])
```

**Returns**

The sorted [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter") objects in the circuit.

If you have transpiled your circuit, so you have a physical circuit, you can inspect the [`layout`](#qiskit.circuit.QuantumCircuit.layout "qiskit.circuit.QuantumCircuit.layout") attribute for information stored by the transpiler about how the virtual qubits of the source circuit map to the hardware qubits of your physical circuit, both at the start and end of the circuit.

### layout

Return any associated layout information about the circuit.

This attribute contains an optional [`TranspileLayout`](/docs/api/qiskit/qiskit.transpiler.TranspileLayout "qiskit.transpiler.TranspileLayout") object. This is typically set on the output from [`transpile()`](/docs/api/qiskit/compiler#qiskit.compiler.transpile "qiskit.compiler.transpile") or [`PassManager.run()`](/docs/api/qiskit/qiskit.transpiler.PassManager#run "qiskit.transpiler.PassManager.run") to retain information about the permutations caused on the input circuit by transpilation.

There are two types of permutations caused by the [`transpile()`](/docs/api/qiskit/compiler#qiskit.compiler.transpile "qiskit.compiler.transpile") function: an initial layout that permutes the qubits based on the selected physical qubits on the [`Target`](/docs/api/qiskit/qiskit.transpiler.Target "qiskit.transpiler.Target"), and a final layout, which is an output permutation caused by [`SwapGate`](/docs/api/qiskit/qiskit.circuit.library.SwapGate "qiskit.circuit.library.SwapGate")s inserted during routing.

**Example**

```python
from qiskit import QuantumCircuit
from qiskit.providers.fake_provider import GenericBackendV2
from qiskit.transpiler import generate_preset_pass_manager

# Create circuit to test transpiler on
qc = QuantumCircuit(3, 3)
qc.h(0)
qc.cx(0, 1)
qc.swap(1, 2)
qc.cx(0, 1)

# Add measurements to the circuit
qc.measure([0, 1, 2], [0, 1, 2])

# Specify the QPU to target
backend = GenericBackendV2(3)

# Transpile the circuit
pass_manager = generate_preset_pass_manager(
optimization_level=1, backend=backend
)
transpiled = pass_manager.run(qc)

# Print the layout after transpilation
print(transpiled.layout.routing_permutation())
```

```text
[0, 1, 2]
```

If your circuit was also *scheduled* as part of a transpilation, it will expose the individual timings of each instruction, along with the total [`duration`](#qiskit.circuit.QuantumCircuit.duration "qiskit.circuit.QuantumCircuit.duration") of the circuit.

### duration

The total duration of the circuit, set by a scheduling transpiler pass. Its unit is specified by [`unit`](#qiskit.circuit.QuantumCircuit.unit "qiskit.circuit.QuantumCircuit.unit").

> **Deprecated since version 1.3.0**
>
> The property `qiskit.circuit.quantumcircuit.QuantumCircuit.duration` is deprecated as of Qiskit 1.3.0. It will be removed in Qiskit 3.0.0.

### unit

The unit that [`duration`](#qiskit.circuit.QuantumCircuit.duration "qiskit.circuit.QuantumCircuit.duration") is specified in.

> **Deprecated since version 1.3.0**
>
> The property `qiskit.circuit.quantumcircuit.QuantumCircuit.unit` is deprecated as of Qiskit 1.3.0. It will be removed in Qiskit 3.0.0.

### op\_start\_times

Return a list of operation start times.

> **Note**
>
> This attribute computes the estimate starting time of the operations in the scheduled circuit and only works for simple circuits that have no control flow or other classical feed-forward operations.

This attribute is enabled once one of scheduling analysis passes runs on the quantum circuit.

**Example**

```python
from qiskit import QuantumCircuit
from qiskit.providers.fake_provider import GenericBackendV2
from qiskit.transpiler import generate_preset_pass_manager

qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()

# Print the original circuit
print("Original circuit:")
print(qc)

# Transpile the circuit with a specific basis gates list and print the resulting circuit
backend = GenericBackendV2(2, basis_gates=['u1', 'u2', 'u3', 'cx'])
pm = generate_preset_pass_manager(
    optimization_level=1, backend=backend, scheduling_method="alap"
)
transpiled_qc = pm.run(qc)
print("Transpiled circuit with basis gates ['u1', 'u2', 'u3', 'cx']:")
print(transpiled_qc)

# Print the start times of each instruction in the transpiled circuit
print("Start times of instructions in the transpiled circuit:")
for instruction, start_time in zip(transpiled_qc.data, transpiled_qc.op_start_times):
    print(f"{instruction.operation.name}: {start_time}")
```

```text
Original circuit:
        ┌───┐      ░ ┌─┐
q_0: ┤ H ├──■───░─┤M├───
        └───┘┌─┴─┐ ░ └╥┘┌─┐
q_1: ─────┤ X ├─░──╫─┤M├
            └───┘ ░  ║ └╥┘
meas: 2/══════════════╩══╩═
                    0  1

Transpiled circuit with basis gates ['u1', 'u2', 'u3', 'cx']:
            ┌─────────┐          ░ ┌─────────────────┐┌─┐
q_0 -> 0 ───┤ U2(0,π) ├──────■───░─┤ Delay(1255[dt]) ├┤M├
        ┌──┴─────────┴───┐┌─┴─┐ ░ └───────┬─┬───────┘└╥┘
q_1 -> 1 ┤ Delay(196[dt]) ├┤ X ├─░─────────┤M├─────────╫─
        └────────────────┘└───┘ ░         └╥┘         ║
meas: 2/═══════════════════════════════════╩══════════╩═
                                            1          0

Start times of instructions in the transpiled circuit:
u2: 0
delay: 0
cx: 196
barrier: 2098
delay: 2098
measure: 3353
measure: 2098
```

**Returns**

List of integers representing instruction estimated start times. The index corresponds to the index of instruction in [`QuantumCircuit.data`](#qiskit.circuit.QuantumCircuit.data "qiskit.circuit.QuantumCircuit.data").

**Raises**

[**AttributeError**](https://docs.python.org/3/library/exceptions.html#AttributeError) – When circuit is not scheduled.

Finally, [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") exposes several simple properties as dynamic read-only numeric attributes.

### num\_ancillas

Return the number of ancilla qubits.

**Example**

```python
from qiskit import QuantumCircuit, QuantumRegister, AncillaRegister

# Create a 2-qubit quantum circuit
reg = QuantumRegister(2)
qc = QuantumCircuit(reg)

# Create an ancilla register with 1 qubit
anc = AncillaRegister(1)
qc.add_register(anc)  # Add the ancilla register to the circuit

print("Number of ancilla qubits:", qc.num_ancillas)
```

```text
Number of ancilla qubits: 1
```

### num\_clbits

Return number of classical bits.

**Example**

```python
from qiskit import QuantumCircuit

# Create a new circuit with two qubits and one classical bit
qc = QuantumCircuit(2, 1)
print("Number of classical bits:", qc.num_clbits)
```

```text
Number of classical bits: 1
```

### num\_captured\_vars

The number of real-time classical variables in the circuit marked as captured from an enclosing scope.

This is the length of the [`iter_captured_vars()`](#qiskit.circuit.QuantumCircuit.iter_captured_vars "qiskit.circuit.QuantumCircuit.iter_captured_vars") iterable. If this is non-zero, [`num_input_vars`](#qiskit.circuit.QuantumCircuit.num_input_vars "qiskit.circuit.QuantumCircuit.num_input_vars") must be zero.

### num\_captured\_stretches

The number of stretches in the circuit marked as captured from an enclosing scope.

This is the length of the [`iter_captured_stretches()`](#qiskit.circuit.QuantumCircuit.iter_captured_stretches "qiskit.circuit.QuantumCircuit.iter_captured_stretches") iterable. If this is non-zero, [`num_input_vars`](#qiskit.circuit.QuantumCircuit.num_input_vars "qiskit.circuit.QuantumCircuit.num_input_vars") must be zero.

### num\_declared\_vars

The number of real-time classical variables in the circuit that are declared by this circuit scope, excluding inputs or captures.

This is the length of the [`iter_declared_vars()`](#qiskit.circuit.QuantumCircuit.iter_declared_vars "qiskit.circuit.QuantumCircuit.iter_declared_vars") iterable.

### num\_declared\_stretches

The number of stretches in the circuit that are declared by this circuit scope, excluding captures.

This is the length of the [`iter_declared_stretches()`](#qiskit.circuit.QuantumCircuit.iter_declared_stretches "qiskit.circuit.QuantumCircuit.iter_declared_stretches") iterable.

### num\_input\_vars

The number of real-time classical variables in the circuit marked as circuit inputs.

This is the length of the [`iter_input_vars()`](#qiskit.circuit.QuantumCircuit.iter_input_vars "qiskit.circuit.QuantumCircuit.iter_input_vars") iterable. If this is non-zero, [`num_captured_vars`](#qiskit.circuit.QuantumCircuit.num_captured_vars "qiskit.circuit.QuantumCircuit.num_captured_vars") must be zero.

### num\_identifiers

The number of real-time classical variables and stretches in the circuit.

This is equal to [`num_vars()`](#qiskit.circuit.QuantumCircuit.num_vars "qiskit.circuit.QuantumCircuit.num_vars") + [`num_stretches()`](#qiskit.circuit.QuantumCircuit.num_stretches "qiskit.circuit.QuantumCircuit.num_stretches").

### num\_parameters

The number of parameter objects in the circuit.

### num\_qubits

Return number of qubits.

### num\_stretches

The number of stretches in the circuit.

This is the length of the [`iter_stretches()`](#qiskit.circuit.QuantumCircuit.iter_stretches "qiskit.circuit.QuantumCircuit.iter_stretches") iterable.

### num\_vars

The number of real-time classical variables in the circuit.

This is the length of the [`iter_vars()`](#qiskit.circuit.QuantumCircuit.iter_vars "qiskit.circuit.QuantumCircuit.iter_vars") iterable.

## Creating new circuits

| Method                                                                                                                      | Summary                                                                                                |
| --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| [`__init__()`](#qiskit.circuit.QuantumCircuit.__init__ "qiskit.circuit.QuantumCircuit.__init__")                            | Default constructor of no-instruction circuits.                                                        |
| [`copy()`](#qiskit.circuit.QuantumCircuit.copy "qiskit.circuit.QuantumCircuit.copy")                                        | Make a complete copy of an existing circuit.                                                           |
| [`copy_empty_like()`](#qiskit.circuit.QuantumCircuit.copy_empty_like "qiskit.circuit.QuantumCircuit.copy_empty_like")       | Copy data objects from one circuit into a new one without any instructions.                            |
| [`from_instructions()`](#qiskit.circuit.QuantumCircuit.from_instructions "qiskit.circuit.QuantumCircuit.from_instructions") | Infer data objects needed from a list of instructions.                                                 |
| [`from_qasm_file()`](#qiskit.circuit.QuantumCircuit.from_qasm_file "qiskit.circuit.QuantumCircuit.from_qasm_file")          | Legacy interface to [`qasm2.load()`](/docs/api/qiskit/qasm2#qiskit.qasm2.load "qiskit.qasm2.load").    |
| [`from_qasm_str()`](#qiskit.circuit.QuantumCircuit.from_qasm_str "qiskit.circuit.QuantumCircuit.from_qasm_str")             | Legacy interface to [`qasm2.loads()`](/docs/api/qiskit/qasm2#qiskit.qasm2.loads "qiskit.qasm2.loads"). |

The default constructor (`QuantumCircuit(...)`) produces a circuit with no initial instructions. The arguments to the default constructor can be used to seed the circuit with quantum and classical data storage, and to provide a name, global phase and arbitrary metadata. All of these fields can be expanded later.

### \_\_init\_\_

`__init__(*regs, name=None, global_phase=0, metadata=None, inputs=(), captures=(), declarations=())`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L1075-L1237)

Default constructor of [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit").

**Parameters**

- **regs** ([*Register*](/docs/api/qiskit/circuit#qiskit.circuit.Register "qiskit.circuit.Register")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Bit*](/docs/api/qiskit/circuit#qiskit.circuit.Bit "qiskit.circuit.Bit")*]*) –

  The registers to be included in the circuit.

  - If a list of [`Register`](/docs/api/qiskit/circuit#qiskit.circuit.Register "qiskit.circuit.Register") objects, represents the [`QuantumRegister`](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister") and/or [`ClassicalRegister`](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister") objects to include in the circuit.

    For example:

    > - `QuantumCircuit(QuantumRegister(4))`
    > - `QuantumCircuit(QuantumRegister(4), ClassicalRegister(3))`
    > - `QuantumCircuit(QuantumRegister(4, 'qr0'), QuantumRegister(2, 'qr1'))`

  - If a list of `int`, the amount of qubits and/or classical bits to include in the circuit. It can either be a single int for just the number of quantum bits, or 2 ints for the number of quantum bits and classical bits, respectively.

    For example:

    > - `QuantumCircuit(4) # A QuantumCircuit with 4 qubits`
    > - `QuantumCircuit(4, 3) # A QuantumCircuit with 4 qubits and 3 classical bits`

  - If a list of python lists containing [`Bit`](/docs/api/qiskit/circuit#qiskit.circuit.Bit "qiskit.circuit.Bit") objects, a collection of [`Bit`](/docs/api/qiskit/circuit#qiskit.circuit.Bit "qiskit.circuit.Bit") s to be added to the circuit.

- **name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – the name of the quantum circuit. If not set, an automatically generated string will be assigned.

- **global\_phase** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The global phase of the circuit in radians.

- **metadata** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict) *| None*) – Arbitrary key value metadata to associate with the circuit. This gets stored as free-form data in a dict in the [`metadata`](#qiskit.circuit.QuantumCircuit.metadata "qiskit.circuit.QuantumCircuit.metadata") attribute. It will not be directly used in the circuit.

- **inputs** ([*Iterable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)*\[*[*Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit._accelerate.circuit.classical.expr.Var")*]*) – any variables to declare as `input` runtime variables for this circuit. These should already be existing [`expr.Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") nodes that you build from somewhere else; if you need to create the inputs as well, use [`QuantumCircuit.add_input()`](#qiskit.circuit.QuantumCircuit.add_input "qiskit.circuit.QuantumCircuit.add_input"). The variables given in this argument will be passed directly to [`add_input()`](#qiskit.circuit.QuantumCircuit.add_input "qiskit.circuit.QuantumCircuit.add_input"). A circuit cannot have both `inputs` and `captures`.

- **captures** ([*Iterable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)*\[*[*Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit._accelerate.circuit.classical.expr.Var")  *|*[*Stretch*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit._accelerate.circuit.classical.expr.Stretch")*]*) – any variables that this circuit scope should capture from a containing scope. The variables given here will be passed directly to [`add_capture()`](#qiskit.circuit.QuantumCircuit.add_capture "qiskit.circuit.QuantumCircuit.add_capture"). A circuit cannot have both `inputs` and `captures`.

- **declarations** ([*Mapping*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping)*\[*[*Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit._accelerate.circuit.classical.expr.Var")*,* [*Expr*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Expr "qiskit._accelerate.circuit.classical.expr.Expr")*] |* [*Iterable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)*\[*[*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)*\[*[*Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit._accelerate.circuit.classical.expr.Var")*,* [*Expr*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Expr "qiskit._accelerate.circuit.classical.expr.Expr")*]]*) –

  any variables that this circuit should declare and initialize immediately. You can order this input so that later declarations depend on earlier ones (including inputs or captures). If you need to depend on values that will be computed later at runtime, use [`add_var()`](#qiskit.circuit.QuantumCircuit.add_var "qiskit.circuit.QuantumCircuit.add_var") at an appropriate point in the circuit execution.

  This argument is intended for convenient circuit initialization when you already have a set of created variables. The variables used here will be directly passed to [`add_var()`](#qiskit.circuit.QuantumCircuit.add_var "qiskit.circuit.QuantumCircuit.add_var"), which you can use directly if this is the first time you are creating the variable.

**Raises**

- [**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if the circuit name, if given, is not valid.
- [**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if both `inputs` and `captures` are given.

If you have an existing circuit, you can produce a copy of it using [`copy()`](#qiskit.circuit.QuantumCircuit.copy "qiskit.circuit.QuantumCircuit.copy"), including all its instructions. This is useful if you want to keep partial circuits while extending another, or to have a version you can mutate in-place while leaving the prior one intact.

### copy

`copy(name=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4341-L4355)

Copy the circuit.

**Parameters**

**name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) – name to be given to the copied circuit. If None, then the name stays the same.

**Returns**

a deepcopy of the current circuit, with the specified name

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

Similarly, if you want a circuit that contains all the same data objects (bits, registers, variables, etc) but with none of the instructions, you can use [`copy_empty_like()`](#qiskit.circuit.QuantumCircuit.copy_empty_like "qiskit.circuit.QuantumCircuit.copy_empty_like"). This is quite common when you want to build up a new layer of a circuit to then apply onto the back with [`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose"), or to do a full rewrite of a circuit’s instructions.

### copy\_empty\_like

`copy_empty_like(name=None, *, vars_mode='alike')`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4357-L4417)

Return a copy of self with the same structure but empty.

That structure includes:

- name and other metadata
- global phase
- all the qubits and clbits, including the registers
- the realtime variables defined in the circuit, handled according to the `vars` keyword argument.

> **Warning**
>
> If the circuit contains any local variable declarations (those added by the `declarations` argument to the circuit constructor, or using [`add_var()`](#qiskit.circuit.QuantumCircuit.add_var "qiskit.circuit.QuantumCircuit.add_var")), they may be **uninitialized** in the output circuit. You will need to manually add store instructions for them (see [`Store`](/docs/api/qiskit/circuit#qiskit.circuit.Store "qiskit.circuit.Store") and [`QuantumCircuit.store()`](#qiskit.circuit.QuantumCircuit.store "qiskit.circuit.QuantumCircuit.store")) to initialize them.

**Parameters**

- **name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – Name for the copied circuit. If None, then the name stays the same.

- **vars\_mode** ([*Literal*](https://docs.python.org/3/library/typing.html#typing.Literal)*\['alike', 'captures', 'drop']*) –

  The mode to handle realtime variables in.

  **alike**

  The variables in the output circuit will have the same declaration semantics as in the original circuit. For example, `input` variables in the source will be `input` variables in the output circuit. Note that this causes the local variables to be uninitialised, because the stores are not copied. This can leave the circuit in a potentially dangerous state for users if they don’t re-add initializer stores.

  **captures**

  All variables will be converted to captured variables. This is useful when you are building a new layer for an existing circuit that you will want to [`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose") onto the base, since [`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose") can inline captures onto the base circuit (but not other variables).

  **drop**

  The output circuit will have no variables defined.

**Returns**

An empty copy of self.

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

In some cases, it is most convenient to generate a list of [`CircuitInstruction`](/docs/api/qiskit/qiskit.circuit.CircuitInstruction "qiskit.circuit.CircuitInstruction")s separately to an entire circuit context, and then to build a circuit from this. The [`from_instructions()`](#qiskit.circuit.QuantumCircuit.from_instructions "qiskit.circuit.QuantumCircuit.from_instructions") constructor will automatically capture all [`Qubit`](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit") and [`Clbit`](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit") instances used in the instructions, and create a new [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") object that has the correct resources and all the instructions.

### from\_instructions

*static* `from_instructions(instructions, *, qubits=(), clbits=(), name=None, global_phase=0, metadata=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L1271-L1322)

Construct a circuit from an iterable of [`CircuitInstruction`](/docs/api/qiskit/qiskit.circuit.CircuitInstruction "qiskit.circuit.CircuitInstruction")s.

**Parameters**

- **instructions** (*Iterable\[*[*CircuitInstruction*](/docs/api/qiskit/qiskit.circuit.CircuitInstruction "qiskit.circuit.CircuitInstruction")  *|*[*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)*\[*[*qiskit.circuit.Instruction*](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction")*] |* [*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)*\[*[*qiskit.circuit.Instruction*](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction")*, Iterable\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")*]] |* [*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)*\[*[*qiskit.circuit.Instruction*](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction")*, Iterable\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")*], Iterable\[*[*Clbit*](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")*]]]*) – The instructions to add to the circuit.
- **qubits** (*Iterable\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")*]*) – Any qubits to add to the circuit. This argument can be used, for example, to enforce a particular ordering of qubits.
- **clbits** (*Iterable\[*[*Clbit*](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")*]*) – Any classical bits to add to the circuit. This argument can be used, for example, to enforce a particular ordering of classical bits.
- **name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The name of the circuit.
- **global\_phase** (*ParameterValueType*) – The global phase of the circuit in radians.
- **metadata** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict) *| None*) – Arbitrary key value metadata to associate with the circuit.

**Returns**

The quantum circuit.

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

[`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") also still has two constructor methods that are legacy wrappers around the importers in [`qiskit.qasm2`](/docs/api/qiskit/qasm2#module-qiskit.qasm2 "qiskit.qasm2"). These automatically apply [the legacy compatibility settings](/docs/api/qiskit/qasm2#qasm2-legacy-compatibility) of [`load()`](/docs/api/qiskit/qasm2#qiskit.qasm2.load "qiskit.qasm2.load") and [`loads()`](/docs/api/qiskit/qasm2#qiskit.qasm2.loads "qiskit.qasm2.loads").

### from\_qasm\_file

*static* `from_qasm_file(path)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4749-L4772)

Read an OpenQASM 2.0 program from a file and convert to an instance of [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit").

**Parameters**

**path** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*PathLike*](https://docs.python.org/3/library/os.html#os.PathLike)) – Path to the file for an OpenQASM 2 program

**Returns**

The QuantumCircuit object for the input OpenQASM 2.

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

> **See also**
>
> [`qasm2.load()`](/docs/api/qiskit/qasm2#qiskit.qasm2.load "qiskit.qasm2.load"): the complete interface to the OpenQASM 2 importer.

### from\_qasm\_str

*static* `from_qasm_str(qasm_str)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4774-L4795)

Convert a string containing an OpenQASM 2.0 program to a [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit").

**Parameters**

**qasm\_str** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) – A string containing an OpenQASM 2.0 program.

**Returns**

The QuantumCircuit object for the input OpenQASM 2

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

> **See also**
>
> [`qasm2.loads()`](/docs/api/qiskit/qasm2#qiskit.qasm2.loads "qiskit.qasm2.loads"): the complete interface to the OpenQASM 2 importer.

## Data objects on circuits

### Adding data objects

| Method                                                                                                                                  | Adds this kind of data                                                                                                                                                                                                                                                                    |
| --------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`add_bits()`](#qiskit.circuit.QuantumCircuit.add_bits "qiskit.circuit.QuantumCircuit.add_bits")                                        | [`Qubit`](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")s and [`Clbit`](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")s.                                                                                                                    |
| [`add_register()`](#qiskit.circuit.QuantumCircuit.add_register "qiskit.circuit.QuantumCircuit.add_register")                            | [`QuantumRegister`](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister") and [`ClassicalRegister`](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister").                                                    |
| [`add_var()`](#qiskit.circuit.QuantumCircuit.add_var "qiskit.circuit.QuantumCircuit.add_var")                                           | [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") nodes with local scope and initializers.                                                                                                                                |
| [`add_stretch()`](#qiskit.circuit.QuantumCircuit.add_stretch "qiskit.circuit.QuantumCircuit.add_stretch")                               | [`Stretch`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch") nodes with local scope.                                                                                                                                     |
| [`add_input()`](#qiskit.circuit.QuantumCircuit.add_input "qiskit.circuit.QuantumCircuit.add_input")                                     | [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") nodes that are treated as circuit inputs.                                                                                                                               |
| [`add_capture()`](#qiskit.circuit.QuantumCircuit.add_capture "qiskit.circuit.QuantumCircuit.add_capture")                               | [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") or [`Stretch`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch") nodes captured from containing scopes. |
| [`add_uninitialized_var()`](#qiskit.circuit.QuantumCircuit.add_uninitialized_var "qiskit.circuit.QuantumCircuit.add_uninitialized_var") | [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") nodes with local scope and undefined state.                                                                                                                             |

Typically you add most of the data objects ([`Qubit`](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit"), [`Clbit`](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit"), [`ClassicalRegister`](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister"), etc) to the circuit as part of using the [`__init__()`](#qiskit.circuit.QuantumCircuit.__init__ "qiskit.circuit.QuantumCircuit.__init__") default constructor, or [`copy_empty_like()`](#qiskit.circuit.QuantumCircuit.copy_empty_like "qiskit.circuit.QuantumCircuit.copy_empty_like"). However, it is also possible to add these afterwards. Typed classical data, such as standalone [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") nodes (see [Real-time classical computation](/docs/api/qiskit/circuit#circuit-repr-real-time-classical)), can be both constructed and added with separate methods.

New registerless [`Qubit`](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit") and [`Clbit`](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit") objects are added using [`add_bits()`](#qiskit.circuit.QuantumCircuit.add_bits "qiskit.circuit.QuantumCircuit.add_bits"). These objects must not already be present in the circuit. You can check if a bit exists in the circuit already using [`find_bit()`](#qiskit.circuit.QuantumCircuit.find_bit "qiskit.circuit.QuantumCircuit.find_bit").

#### add\_bits

`add_bits(bits)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3665-L3696)

Add Bits to the circuit.

> **Warning**
>
> If the quantum circuit has an existing [`layout`](#qiskit.circuit.QuantumCircuit.layout "qiskit.circuit.QuantumCircuit.layout") attribute, adding a [`Qubit`](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit") will only increase the number of qubits. It will not update the layout.

**Parameters**

**bits** ([*Iterable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)*\[*[*Bit*](/docs/api/qiskit/circuit#qiskit.circuit.Bit "qiskit.circuit.Bit")*]*)

**Return type**

None

Registers are added to the circuit with [`add_register()`](#qiskit.circuit.QuantumCircuit.add_register "qiskit.circuit.QuantumCircuit.add_register"). In this method, it is not an error if some of the bits are already present in the circuit. In this case, the register will be an “alias” over the bits. This is not generally well-supported by hardware backends; it is probably best to stay away from relying on it. The registers a given bit is in are part of the return of [`find_bit()`](#qiskit.circuit.QuantumCircuit.find_bit "qiskit.circuit.QuantumCircuit.find_bit").

#### add\_register

`add_register(*regs)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3600-L3663)

Add registers.

> **Warning**
>
> If the quantum circuit has an existing [`layout`](#qiskit.circuit.QuantumCircuit.layout "qiskit.circuit.QuantumCircuit.layout") attribute, adding a [`QuantumRegister`](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister") will only increase the number of qubits. It will not update the layout.

**Parameters**

**regs** ([*Register*](/docs/api/qiskit/circuit#qiskit.circuit.Register "qiskit.circuit.Register")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Bit*](/docs/api/qiskit/circuit#qiskit.circuit.Bit "qiskit.circuit.Bit")*]*)

**Return type**

None

[Real-time, typed classical data](/docs/api/qiskit/circuit#circuit-repr-real-time-classical) is represented on the circuit by [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") nodes with a well-defined [`Type`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.types.Type "qiskit.circuit.classical.types.Type"). It is possible to instantiate these separately to a circuit (see [`Var.new()`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var.new "qiskit.circuit.classical.expr.Var.new")), but it is often more convenient to use circuit methods that will automatically manage the types and expression initialization for you. The two most common methods are [`add_var()`](#qiskit.circuit.QuantumCircuit.add_var "qiskit.circuit.QuantumCircuit.add_var") (locally scoped variables) and [`add_input()`](#qiskit.circuit.QuantumCircuit.add_input "qiskit.circuit.QuantumCircuit.add_input") (inputs to the circuit). Additionally, the method [`add_stretch()`](#qiskit.circuit.QuantumCircuit.add_stretch "qiskit.circuit.QuantumCircuit.add_stretch") can be used to add stretches to the circuit.

#### add\_var

`add_var(name_or_var, /, initial)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3396-L3488)

Add a classical variable with automatic storage and scope to this circuit.

The variable is considered to have been “declared” at the beginning of the circuit, but it only becomes initialized at the point of the circuit that you call this method, so it can depend on variables defined before it.

**Parameters**

- **name\_or\_var** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit._accelerate.circuit.classical.expr.Var")) – either a string of the variable name, or an existing instance of [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") to re-use. Variables cannot shadow names that are already in use within the circuit.

- **initial** ([*Any*](https://docs.python.org/3/library/typing.html#typing.Any)) –

  the value to initialize this variable with. If the first argument was given as a string name, the type of the resulting variable is inferred from the initial expression; to control this more manually, either use [`Var.new()`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var.new "qiskit.circuit.classical.expr.Var.new") to manually construct a new variable with the desired type, or use [`expr.cast()`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.cast "qiskit.circuit.classical.expr.cast") to cast the initializer to the desired type.

  This must be either a [`Expr`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Expr "qiskit.circuit.classical.expr.Expr") node, or a value that can be lifted to one using `expr.lift`.

**Returns**

The created variable. If a [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") instance was given, the exact same object will be returned.

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if the variable cannot be created due to shadowing an existing identifier.

**Return type**

[*Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit._accelerate.circuit.classical.expr.Var")

**Examples**

Define a new variable given just a name and an initializer expression:

```python
from qiskit.circuit import QuantumCircuit

qc = QuantumCircuit(2)
my_var = qc.add_var("my_var", False)
```

Reuse a variable that may have been taken from a related circuit, or otherwise constructed manually, and initialize it to some more complicated expression:

```python
from qiskit.circuit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.circuit.classical import expr, types

my_var = expr.Var.new("my_var", types.Uint(8))

cr1 = ClassicalRegister(8, "cr1")
cr2 = ClassicalRegister(8, "cr2")
qc = QuantumCircuit(QuantumRegister(8), cr1, cr2)

# Get some measurement results into each register.
qc.h(0)
for i in range(1, 8):
    qc.cx(0, i)
qc.measure(range(8), cr1)

qc.reset(range(8))
qc.h(0)
for i in range(1, 8):
    qc.cx(0, i)
qc.measure(range(8), cr2)

# Now when we add the variable, it is initialized using the real-time state of the
# two classical registers we measured into above.
qc.add_var(my_var, expr.bit_and(cr1, cr2))
```

#### add\_input

`add_input(name_or_var: str, type_: Type, /) → Var`

`add_input(name_or_var: Var, type_: None = None, /) → Var`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3571-L3598)

Register a variable as an input to the circuit.

**Parameters**

- **name\_or\_var** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit._accelerate.circuit.classical.expr.Var")) – either a string name, or an existing [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") node to use as the input variable.
- **type** – if the name is given as a string, then this must be a [`Type`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.types.Type "qiskit.circuit.classical.types.Type") to use for the variable. If the variable is given as an existing [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var"), then this must not be given, and will instead be read from the object itself.
- **type\_** ([*Type*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.types.Type "qiskit._accelerate.circuit.classical.types.Type") *| None*)

**Returns**

the variable created, or the same variable as was passed in.

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if the variable cannot be created due to shadowing an existing variable.

**Return type**

[*Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit._accelerate.circuit.classical.expr.Var")

#### add\_stretch

`add_stretch(name_or_stretch)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3362-L3394)

Declares a new stretch scoped to this circuit.

**Parameters**

**name\_or\_stretch** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*Stretch*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit._accelerate.circuit.classical.expr.Stretch")) – either a string of the stretch name, or an existing instance of [`Stretch`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch") to re-use. Stretches cannot shadow names that are already in use within the circuit.

**Returns**

The created stretch. If a [`Stretch`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch") instance was given, the exact same object will be returned.

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if the stretch cannot be created due to shadowing an existing identifier.

**Return type**

[*Stretch*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit._accelerate.circuit.classical.expr.Stretch")

**Examples**

Define and use a new stretch given just a name:

```python
from qiskit.circuit import QuantumCircuit, Duration
from qiskit.circuit.classical import expr

qc = QuantumCircuit(2)
my_stretch = qc.add_stretch("my_stretch")

qc.delay(expr.add(Duration.dt(200), my_stretch), 1)
```

In addition, there are two lower-level methods that can be useful for programmatic generation of circuits. When working interactively, you will most likely not need these; most uses of [`add_uninitialized_var()`](#qiskit.circuit.QuantumCircuit.add_uninitialized_var "qiskit.circuit.QuantumCircuit.add_uninitialized_var") are part of [`copy_empty_like()`](#qiskit.circuit.QuantumCircuit.copy_empty_like "qiskit.circuit.QuantumCircuit.copy_empty_like"), and most uses of [`add_capture()`](#qiskit.circuit.QuantumCircuit.add_capture "qiskit.circuit.QuantumCircuit.add_capture") would be better off using [the control-flow builder interface](#circuit-control-flow-methods).

#### add\_uninitialized\_var

`add_uninitialized_var(var, /)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3490-L3521)

Add a variable with no initializer.

In most cases, you should use [`add_var()`](#qiskit.circuit.QuantumCircuit.add_var "qiskit.circuit.QuantumCircuit.add_var") to initialize the variable. To use this function, you must already hold a [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") instance, as the use of the function typically only makes sense in copying contexts.

> **Warning**
>
> Qiskit makes no assertions about what an uninitialized variable will evaluate to at runtime, and some hardware may reject this as an error.
>
> You should treat this function with caution, and as a low-level primitive that is useful only in special cases of programmatically rebuilding two like circuits.

**Parameters**

**var** ([*Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit._accelerate.circuit.classical.expr.Var")) – the variable to add.

#### add\_capture

`add_capture(var: Var)`

`add_capture(stretch: Stretch)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3529-L3563)

Add an identifier to the circuit that it should capture from a scope it will be contained within.

This method requires a [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") or [`Stretch`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch") node to enforce that you’ve got a handle to an identifier, because you will need to declare the same identifier using the same object in the outer circuit.

This is a low-level method, which is only really useful if you are manually constructing control-flow operations. You typically will not need to call this method, assuming you are using the builder interface for control-flow scopes (`with` context-manager statements for [`if_test()`](#qiskit.circuit.QuantumCircuit.if_test "qiskit.circuit.QuantumCircuit.if_test") and the other scoping constructs). The builder interface will automatically make the inner scopes closures on your behalf by capturing any identifiers that are used within them.

**Parameters**

**var** (*Union\[*[*expr.Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var")*,* [*expr.Stretch*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch")*]*) – the variable or stretch to capture from an enclosing scope.

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if the identifier cannot be created due to shadowing an existing identifier.

### Working with bits and registers

A [`Bit`](/docs/api/qiskit/circuit#qiskit.circuit.Bit "qiskit.circuit.Bit") instance is, on its own, just a unique handle for circuits to use in their own contexts. If you have got a [`Bit`](/docs/api/qiskit/circuit#qiskit.circuit.Bit "qiskit.circuit.Bit") instance and a circuit, you can find the contexts that the bit exists in using [`find_bit()`](#qiskit.circuit.QuantumCircuit.find_bit "qiskit.circuit.QuantumCircuit.find_bit"), such as its integer index in the circuit and any registers it is contained in.

#### find\_bit

`find_bit(bit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3698-L3759)

Find locations in the circuit which can be used to reference a given [`Bit`](/docs/api/qiskit/circuit#qiskit.circuit.Bit "qiskit.circuit.Bit").

In particular, this function can find the integer index of a qubit, which corresponds to its hardware index for a transpiled circuit.

> **Note**
>
> The circuit index of a [`AncillaQubit`](/docs/api/qiskit/circuit#qiskit.circuit.AncillaQubit "qiskit.circuit.AncillaQubit") will be its index in [`qubits`](#qiskit.circuit.QuantumCircuit.qubits "qiskit.circuit.QuantumCircuit.qubits"), not [`ancillas`](#qiskit.circuit.QuantumCircuit.ancillas "qiskit.circuit.QuantumCircuit.ancillas").

**Parameters**

**bit** ([*Bit*](/docs/api/qiskit/circuit#qiskit.circuit.Bit "qiskit.circuit.Bit")) – The bit to locate.

**Returns**

A 2-tuple. The first element (`index`) contains the index at which the `Bit` can be found (in either [`qubits`](#qiskit.circuit.QuantumCircuit.qubits "qiskit.circuit.QuantumCircuit.qubits"), [`clbits`](#qiskit.circuit.QuantumCircuit.clbits "qiskit.circuit.QuantumCircuit.clbits"), depending on its type). The second element (`registers`) is a list of `(register, index)` pairs with an entry for each [`Register`](/docs/api/qiskit/circuit#qiskit.circuit.Register "qiskit.circuit.Register") in the circuit which contains the [`Bit`](/docs/api/qiskit/circuit#qiskit.circuit.Bit "qiskit.circuit.Bit") (and the index in the [`Register`](/docs/api/qiskit/circuit#qiskit.circuit.Register "qiskit.circuit.Register") at which it can be found).

**Return type**

namedtuple([int](https://docs.python.org/3/library/functions.html#int), List\[Tuple([Register](/docs/api/qiskit/circuit#qiskit.circuit.Register "qiskit.circuit.Register"), [int](https://docs.python.org/3/library/functions.html#int))])

**Raises**

- [**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – If the supplied [`Bit`](/docs/api/qiskit/circuit#qiskit.circuit.Bit "qiskit.circuit.Bit") was of an unknown type.
- [**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – If the supplied [`Bit`](/docs/api/qiskit/circuit#qiskit.circuit.Bit "qiskit.circuit.Bit") could not be found on the circuit.

**Examples**

Loop through a circuit, getting the qubit and clbit indices of each operation:

```python
from qiskit.circuit import QuantumCircuit, Qubit

qc = QuantumCircuit(3, 3)
qc.h(0)
qc.cx(0, 1)
qc.cx(1, 2)
qc.measure([0, 1, 2], [0, 1, 2])

# The `.qubits` and `.clbits` fields are not integers.
assert isinstance(qc.data[0].qubits[0], Qubit)
# ... but we can use `find_bit` to retrieve them.
assert qc.find_bit(qc.data[0].qubits[0]).index == 0

simple = [
    (
        instruction.operation.name,
        [qc.find_bit(bit).index for bit in instruction.qubits],
        [qc.find_bit(bit).index for bit in instruction.clbits],
    )
    for instruction in qc.data
]
```

Similarly, you can query a circuit to see if a register has already been added to it by using [`has_register()`](#qiskit.circuit.QuantumCircuit.has_register "qiskit.circuit.QuantumCircuit.has_register").

#### has\_register

`has_register(register)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L1626-L1641)

Test if this circuit has the register r.

**Parameters**

**register** ([*Register*](/docs/api/qiskit/circuit#qiskit.circuit.Register "qiskit.circuit.Register")) – a quantum or classical register.

**Returns**

True if the register is contained in this circuit.

**Return type**

[bool](https://docs.python.org/3/library/functions.html#bool)

### Working with compile-time parameters

> **See also**
>
> **[Compile-time parametrization](/docs/api/qiskit/circuit#circuit-compile-time-parameters)**
>
> A more complete discussion of what compile-time parametrization is, and how it fits into Qiskit’s data model.

Unlike bits, registers, and real-time typed classical data, compile-time symbolic parameters are not manually added to a circuit. Their presence is inferred by being contained in operations added to circuits and the global phase. An ordered list of all parameters currently in a circuit is at [`QuantumCircuit.parameters`](#qiskit.circuit.QuantumCircuit.parameters "qiskit.circuit.QuantumCircuit.parameters").

The most common operation on [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter") instances is to replace them in symbolic operations with some numeric value, or another symbolic expression. This is done with [`assign_parameters()`](#qiskit.circuit.QuantumCircuit.assign_parameters "qiskit.circuit.QuantumCircuit.assign_parameters").

#### assign\_parameters

`assign_parameters(parameters: Mapping[Parameter, ParameterExpression | float] | Iterable[ParameterExpression | float], inplace: Literal[False] = False, *, flat_input: bool = False, strict: bool = True) → QuantumCircuit`

`assign_parameters(parameters: Mapping[Parameter, ParameterExpression | float] | Iterable[ParameterExpression | float], inplace: Literal[True] = False, *, flat_input: bool = False, strict: bool = True) → None`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4956-L5074)

Assign parameters to new parameters or values.

If `parameters` is passed as a dictionary, the keys should be [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter") instances in the current circuit. The values of the dictionary can either be numeric values or new parameter objects.

If `parameters` is passed as a list or array, the elements are assigned to the current parameters in the order of [`parameters`](#qiskit.circuit.QuantumCircuit.parameters "qiskit.circuit.QuantumCircuit.parameters") which is sorted alphabetically (while respecting the ordering in [`ParameterVector`](/docs/api/qiskit/qiskit.circuit.ParameterVector "qiskit.circuit.ParameterVector") objects).

The values can be assigned to the current circuit object or to a copy of it.

> **Note**
>
> When `parameters` is given as a mapping, it is permissible to have keys that are strings of the parameter names; these will be looked up using [`get_parameter()`](#qiskit.circuit.QuantumCircuit.get_parameter "qiskit.circuit.QuantumCircuit.get_parameter"). You can also have keys that are [`ParameterVector`](/docs/api/qiskit/qiskit.circuit.ParameterVector "qiskit.circuit.ParameterVector") instances, and in this case, the dictionary value should be a sequence of values of the same length as the vector.
>
> If you use either of these cases, you must leave the setting `flat_input=False`; changing this to `True` enables the fast path, where all keys must be [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter") instances.

**Parameters**

- **parameters** ([*Mapping*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping)*\[*[*Parameter*](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit._accelerate.circuit.Parameter")*,* [*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)*] |* [*Iterable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)*\[*[*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)*]*) – Either a dictionary or iterable specifying the new parameter values.
- **inplace** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – If False, a copy of the circuit with the bound parameters is returned. If True the circuit instance itself is modified.
- **flat\_input** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – If `True` and `parameters` is a mapping type, it is assumed to be exactly a mapping of `{parameter: value}`. By default (`False`), the mapping may also contain [`ParameterVector`](/docs/api/qiskit/qiskit.circuit.ParameterVector "qiskit.circuit.ParameterVector") keys that point to a corresponding sequence of values, and these will be unrolled during the mapping, or string keys, which will be converted to [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter") instances using [`get_parameter()`](#qiskit.circuit.QuantumCircuit.get_parameter "qiskit.circuit.QuantumCircuit.get_parameter").
- **strict** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – If `False`, any parameters given in the mapping that are not used in the circuit will be ignored. If `True` (the default), an error will be raised indicating a logic error.

**Raises**

- [**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – If parameters is a dict and contains parameters not present in the circuit.
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If parameters is a list/array and the length mismatches the number of free parameters in the circuit.

**Returns**

A copy of the circuit with bound parameters if `inplace` is False, otherwise None.

**Return type**

[*QuantumCircuit*](#qiskit.circuit.QuantumCircuit "qiskit.circuit.quantumcircuit.QuantumCircuit") | None

**Examples**

Create a parameterized circuit and assign the parameters in-place.

```python
from qiskit.circuit import QuantumCircuit, Parameter

circuit = QuantumCircuit(2)
params = [Parameter('A'), Parameter('B'), Parameter('C')]
circuit.ry(params[0], 0)
circuit.crx(params[1], 0, 1)
circuit.draw('mpl')
circuit.assign_parameters({params[0]: params[2]}, inplace=True)
circuit.draw('mpl')
```

![Circuit diagram output by the previous code.](https://eu-de.quantum.cloud.ibm.com/docs/images/api/qiskit/qiskit-circuit-QuantumCircuit-15_00.avif)

![Circuit diagram output by the previous code.](https://eu-de.quantum.cloud.ibm.com/docs/images/api/qiskit/qiskit-circuit-QuantumCircuit-15_01.avif)

Bind the values out-of-place by list and get a copy of the original circuit.

```python
from qiskit.circuit import QuantumCircuit, ParameterVector

circuit = QuantumCircuit(2)
params = ParameterVector('P', 2)
circuit.ry(params[0], 0)
circuit.crx(params[1], 0, 1)

bound_circuit = circuit.assign_parameters([1, 2])
bound_circuit.draw('mpl')

circuit.draw('mpl')
```

![Circuit diagram output by the previous code.](https://eu-de.quantum.cloud.ibm.com/docs/images/api/qiskit/qiskit-circuit-QuantumCircuit-16_00.avif)

![Circuit diagram output by the previous code.](https://eu-de.quantum.cloud.ibm.com/docs/images/api/qiskit/qiskit-circuit-QuantumCircuit-16_01.avif)

The circuit tracks parameters by [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter") instances themselves, and forbids having multiple parameters of the same name to avoid some problems when interoperating with OpenQASM or other external formats. You can use [`has_parameter()`](#qiskit.circuit.QuantumCircuit.has_parameter "qiskit.circuit.QuantumCircuit.has_parameter") and [`get_parameter()`](#qiskit.circuit.QuantumCircuit.get_parameter "qiskit.circuit.QuantumCircuit.get_parameter") to query the circuit for a parameter with the given string name.

#### has\_parameter

`has_parameter(name_or_param, /)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3083-L3106)

Check whether a parameter object exists in this circuit.

**Parameters**

**name\_or\_param** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*Parameter*](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit._accelerate.circuit.Parameter")) – the parameter, or name of a parameter to check. If this is a [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter") node, the parameter must be exactly the given one for this function to return `True`.

**Returns**

whether a matching parameter is assignable in this circuit.

**Return type**

[bool](https://docs.python.org/3/library/functions.html#bool)

> **See also**
>
> **[`QuantumCircuit.get_parameter()`](#qiskit.circuit.QuantumCircuit.get_parameter "qiskit.circuit.QuantumCircuit.get_parameter")**
>
> Retrieve the [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter") instance from this circuit by name.
>
> **[`QuantumCircuit.has_var()`](#qiskit.circuit.QuantumCircuit.has_var "qiskit.circuit.QuantumCircuit.has_var")**
>
> A similar method to this, but for run-time [`expr.Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") variables instead of compile-time [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter")s.

#### get\_parameter

`get_parameter(name: str, default: T) → Parameter | T`

`get_parameter(name: str, default: builtin_types.EllipsisType = Ellipsis) → Parameter`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3036-L3081)

Retrieve a compile-time parameter that is accessible in this circuit scope by name.

**Parameters**

- **name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) – the name of the parameter to retrieve.
- **default** ([*Any*](https://docs.python.org/3/library/typing.html#typing.Any)) – if given, this value will be returned if the parameter is not present. If it is not given, a [`KeyError`](https://docs.python.org/3/library/exceptions.html#KeyError) is raised instead.

**Returns**

The corresponding parameter.

**Raises**

[**KeyError**](https://docs.python.org/3/library/exceptions.html#KeyError) – if no default is given, but the parameter does not exist in the circuit.

**Return type**

[*Parameter*](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit._accelerate.circuit.Parameter")

**Examples**

Retrieve a parameter by name from a circuit:

```python
from qiskit.circuit import QuantumCircuit, Parameter

my_param = Parameter("my_param")

# Create a parametrized circuit.
qc = QuantumCircuit(1)
qc.rx(my_param, 0)

# We can use 'my_param' as a parameter, but let's say we've lost the Python object
# and need to retrieve it.
my_param_again = qc.get_parameter("my_param")

assert my_param == my_param_again
```

Get a variable from a circuit by name, returning some default if it is not present:

```python
assert qc.get_parameter("my_param", None) == my_param
assert qc.get_parameter("unknown_param", None) is None
```

> **See also**
>
> **[`get_var()`](#qiskit.circuit.QuantumCircuit.get_var "qiskit.circuit.QuantumCircuit.get_var")**
>
> A similar method, but for [`expr.Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") run-time variables instead of [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter") compile-time parameters.

### Working with real-time typed classical data

> **See also**
>
> **[`qiskit.circuit.classical`](/docs/api/qiskit/circuit_classical#module-qiskit.circuit.classical "qiskit.circuit.classical")**
>
> Module-level documentation for how the variable-, expression- and type-systems work, the objects used to represent them, and the classical operations available.
>
> **[Real-time classical computation](/docs/api/qiskit/circuit#circuit-repr-real-time-classical)**
>
> A discussion of how real-time data fits into the entire [`qiskit.circuit`](/docs/api/qiskit/circuit#module-qiskit.circuit "qiskit.circuit") data model as a whole.
>
> **[Adding data objects](#circuit-adding-data-objects)**
>
> The methods for adding new [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") or [`Stretch`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch") identifiers to a circuit after initialization.

You can retrieve identifiers attached to a circuit (e.g. a [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") or [`Stretch`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch")) by name with methods [`get_var()`](#qiskit.circuit.QuantumCircuit.get_var "qiskit.circuit.QuantumCircuit.get_var"), [`get_stretch()`](#qiskit.circuit.QuantumCircuit.get_stretch "qiskit.circuit.QuantumCircuit.get_stretch"), or [`get_identifier()`](#qiskit.circuit.QuantumCircuit.get_identifier "qiskit.circuit.QuantumCircuit.get_identifier"). You can also check if a circuit contains a given identifier with [`has_var()`](#qiskit.circuit.QuantumCircuit.has_var "qiskit.circuit.QuantumCircuit.has_var"), [`has_stretch()`](#qiskit.circuit.QuantumCircuit.has_stretch "qiskit.circuit.QuantumCircuit.has_stretch"), or [`has_identifier()`](#qiskit.circuit.QuantumCircuit.has_identifier "qiskit.circuit.QuantumCircuit.has_identifier").

#### get\_var

`get_var(name: str, default: T) → Var | T`

`get_var(name: str, default: builtin_types.EllipsisType = Ellipsis) → Var`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3114-L3157)

Retrieve a variable that is accessible in this circuit scope by name.

**Parameters**

- **name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) – the name of the variable to retrieve.
- **default** ([*Any*](https://docs.python.org/3/library/typing.html#typing.Any)) – if given, this value will be returned if the variable is not present. If it is not given, a [`KeyError`](https://docs.python.org/3/library/exceptions.html#KeyError) is raised instead.

**Returns**

The corresponding variable.

**Raises**

[**KeyError**](https://docs.python.org/3/library/exceptions.html#KeyError) – if no default is given, but the variable does not exist.

**Examples**

Retrieve a variable by name from a circuit:

```python
from qiskit.circuit import QuantumCircuit

# Create a circuit and create a variable in it.
qc = QuantumCircuit()
my_var = qc.add_var("my_var", False)

# We can use 'my_var' as a variable, but let's say we've lost the Python object and
# need to retrieve it.
my_var_again = qc.get_var("my_var")

assert my_var == my_var_again
```

Get a variable from a circuit by name, returning some default if it is not present:

```python
assert qc.get_var("my_var", None) == my_var
assert qc.get_var("unknown_variable", None) is None
```

> **See also**
>
> **[`get_parameter()`](#qiskit.circuit.QuantumCircuit.get_parameter "qiskit.circuit.QuantumCircuit.get_parameter")**
>
> A similar method, but for [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter") compile-time parameters instead of [`expr.Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") run-time variables.

#### get\_stretch

`get_stretch(name: str, default: T) → Stretch | T`

`get_stretch(name: str, default: builtin_types.EllipsisType = Ellipsis) → Stretch`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3186-L3224)

Retrieve a stretch that is accessible in this circuit scope by name.

**Parameters**

- **name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) – the name of the stretch to retrieve.
- **default** ([*Any*](https://docs.python.org/3/library/typing.html#typing.Any)) – if given, this value will be returned if the variable is not present. If it is not given, a [`KeyError`](https://docs.python.org/3/library/exceptions.html#KeyError) is raised instead.

**Returns**

The corresponding stretch.

**Raises**

[**KeyError**](https://docs.python.org/3/library/exceptions.html#KeyError) – if no default is given, but the variable does not exist.

**Examples**

Retrieve a stretch by name from a circuit:

```python
from qiskit.circuit import QuantumCircuit

# Create a circuit and create a variable in it.
qc = QuantumCircuit()
my_stretch = qc.add_stretch("my_stretch")

# We can use 'my_stretch' as a variable, but let's say we've lost the Python object and
# need to retrieve it.
my_stretch_again = qc.get_stretch("my_stretch")

assert my_stretch == my_stretch_again
```

Get a variable from a circuit by name, returning some default if it is not present:

```python
assert qc.get_stretch("my_stretch", None) == my_stretch
assert qc.get_stretch("unknown_stretch", None) is None
```

#### get\_identifier

`get_identifier(name: str, default: T) → Var | Stretch | T`

`get_identifier(name: str, default: builtin_types.EllipsisType = Ellipsis) → Var | Stretch`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3253-L3284)

Retrieve an identifier that is accessible in this circuit scope by name.

This currently includes both real-time classical variables and stretches.

**Parameters**

- **name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) – the name of the identifier to retrieve.
- **default** ([*Any*](https://docs.python.org/3/library/typing.html#typing.Any)) – if given, this value will be returned if the variable is not present. If it is not given, a [`KeyError`](https://docs.python.org/3/library/exceptions.html#KeyError) is raised instead.

**Returns**

The corresponding variable.

**Raises**

[**KeyError**](https://docs.python.org/3/library/exceptions.html#KeyError) – if no default is given, but the identifier does not exist.

> **See also**
>
> **[`get_var()`](#qiskit.circuit.QuantumCircuit.get_var "qiskit.circuit.QuantumCircuit.get_var")**
>
> Gets an identifier known to be a [`expr.Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") instance.
>
> **[`get_stretch()`](#qiskit.circuit.QuantumCircuit.get_stretch "qiskit.circuit.QuantumCircuit.get_stretch")**
>
> Gets an identifier known to be a [`expr.Stretch`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch") instance.
>
> **[`get_parameter()`](#qiskit.circuit.QuantumCircuit.get_parameter "qiskit.circuit.QuantumCircuit.get_parameter")**
>
> A similar method, but for [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter") compile-time parameters instead of [`expr.Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") run-time variables.

#### has\_var

`has_var(name_or_var, /)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3159-L3179)

Check whether a variable is accessible in this scope.

**Parameters**

**name\_or\_var** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit._accelerate.circuit.classical.expr.Var")) – the variable, or name of a variable to check. If this is a [`expr.Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") node, the variable must be exactly the given one for this function to return `True`.

**Returns**

whether a matching variable is accessible.

**Return type**

[bool](https://docs.python.org/3/library/functions.html#bool)

> **See also**
>
> **[`QuantumCircuit.get_var()`](#qiskit.circuit.QuantumCircuit.get_var "qiskit.circuit.QuantumCircuit.get_var")**
>
> Retrieve the [`expr.Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") instance from this circuit by name.
>
> **[`QuantumCircuit.has_parameter()`](#qiskit.circuit.QuantumCircuit.has_parameter "qiskit.circuit.QuantumCircuit.has_parameter")**
>
> A similar method to this, but for compile-time [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter")s instead of run-time [`expr.Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") variables.

#### has\_stretch

`has_stretch(name_or_stretch, /)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3226-L3243)

Check whether a stretch is accessible in this scope.

**Parameters**

**name\_or\_stretch** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*Stretch*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit._accelerate.circuit.classical.expr.Stretch")) – the stretch, or name of a stretch to check. If this is a [`expr.Stretch`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch") node, the stretch must be exactly the given one for this function to return `True`.

**Returns**

whether a matching stretch is accessible.

**Return type**

[bool](https://docs.python.org/3/library/functions.html#bool)

> **See also**
>
> **[`QuantumCircuit.get_stretch()`](#qiskit.circuit.QuantumCircuit.get_stretch "qiskit.circuit.QuantumCircuit.get_stretch")**
>
> Retrieve the [`expr.Stretch`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch") instance from this circuit by name.

#### has\_identifier

`has_identifier(name_or_ident, /)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3286-L3313)

Check whether an identifier is accessible in this scope.

**Parameters**

**name\_or\_ident** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit._accelerate.circuit.classical.expr.Var")  *|*[*Stretch*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit._accelerate.circuit.classical.expr.Stretch")) – the instance, or name of the identifier to check. If this is a [`expr.Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") or [`expr.Stretch`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch") node, the matched instance must be exactly the given one for this function to return `True`.

**Returns**

whether a matching identifier is accessible.

**Return type**

[bool](https://docs.python.org/3/library/functions.html#bool)

> **See also**
>
> **[`QuantumCircuit.get_identifier()`](#qiskit.circuit.QuantumCircuit.get_identifier "qiskit.circuit.QuantumCircuit.get_identifier")**
>
> Retrieve the [`expr.Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") or [`expr.Stretch`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch") instance from this circuit by name.
>
> **[`QuantumCircuit.has_var()`](#qiskit.circuit.QuantumCircuit.has_var "qiskit.circuit.QuantumCircuit.has_var")**
>
> The same as this method, but ignoring anything that isn’t a run-time `expr.Var` variable.
>
> **[`QuantumCircuit.has_stretch()`](#qiskit.circuit.QuantumCircuit.has_stretch "qiskit.circuit.QuantumCircuit.has_stretch")**
>
> The same as this method, but ignoring anything that isn’t a run-time `expr.Stretch` variable.
>
> **[`QuantumCircuit.has_parameter()`](#qiskit.circuit.QuantumCircuit.has_parameter "qiskit.circuit.QuantumCircuit.has_parameter")**
>
> A similar method to this, but for compile-time [`Parameter`](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter")s instead of run-time [`expr.Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") variables.

There are also several iterator methods that you can use to get the full set of identifiers tracked by a circuit. At least one of [`iter_input_vars()`](#qiskit.circuit.QuantumCircuit.iter_input_vars "qiskit.circuit.QuantumCircuit.iter_input_vars") and [`iter_captured_vars()`](#qiskit.circuit.QuantumCircuit.iter_captured_vars "qiskit.circuit.QuantumCircuit.iter_captured_vars") will be empty, as inputs and captures are mutually exclusive. All of the iterators have corresponding dynamic properties on [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") that contain their length: [`num_vars`](#qiskit.circuit.QuantumCircuit.num_vars "qiskit.circuit.QuantumCircuit.num_vars"), [`num_stretches`](#qiskit.circuit.QuantumCircuit.num_stretches "qiskit.circuit.QuantumCircuit.num_stretches"), [`num_input_vars`](#qiskit.circuit.QuantumCircuit.num_input_vars "qiskit.circuit.QuantumCircuit.num_input_vars"), [`num_captured_vars`](#qiskit.circuit.QuantumCircuit.num_captured_vars "qiskit.circuit.QuantumCircuit.num_captured_vars"), [`num_captured_stretches`](#qiskit.circuit.QuantumCircuit.num_captured_stretches "qiskit.circuit.QuantumCircuit.num_captured_stretches"), [`num_declared_vars`](#qiskit.circuit.QuantumCircuit.num_declared_vars "qiskit.circuit.QuantumCircuit.num_declared_vars"), or [`num_declared_stretches`](#qiskit.circuit.QuantumCircuit.num_declared_stretches "qiskit.circuit.QuantumCircuit.num_declared_stretches").

#### iter\_vars

`iter_vars()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L2662-L2674)

Get an iterable over all real-time classical variables in scope within this circuit.

This method will iterate over all variables in scope. For more fine-grained iterators, see [`iter_declared_vars()`](#qiskit.circuit.QuantumCircuit.iter_declared_vars "qiskit.circuit.QuantumCircuit.iter_declared_vars"), [`iter_input_vars()`](#qiskit.circuit.QuantumCircuit.iter_input_vars "qiskit.circuit.QuantumCircuit.iter_input_vars") and [`iter_captured_vars()`](#qiskit.circuit.QuantumCircuit.iter_captured_vars "qiskit.circuit.QuantumCircuit.iter_captured_vars").

**Return type**

[*Iterable*](https://docs.python.org/3/library/typing.html#typing.Iterable)\[[*Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit._accelerate.circuit.classical.expr.Var")]

#### iter\_stretches

`iter_stretches()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L2676-L2688)

Get an iterable over all stretches in scope within this circuit.

This method will iterate over all stretches in scope. For more fine-grained iterators, see [`iter_declared_stretches()`](#qiskit.circuit.QuantumCircuit.iter_declared_stretches "qiskit.circuit.QuantumCircuit.iter_declared_stretches") and [`iter_captured_stretches()`](#qiskit.circuit.QuantumCircuit.iter_captured_stretches "qiskit.circuit.QuantumCircuit.iter_captured_stretches").

**Return type**

[*Iterable*](https://docs.python.org/3/library/typing.html#typing.Iterable)\[[*Stretch*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit._accelerate.circuit.classical.expr.Stretch")]

#### iter\_input\_vars

`iter_input_vars()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L2705-L2711)

Get an iterable over all real-time classical variables that are declared as inputs to this circuit scope. This excludes locally declared variables (see [`iter_declared_vars()`](#qiskit.circuit.QuantumCircuit.iter_declared_vars "qiskit.circuit.QuantumCircuit.iter_declared_vars")) and captured variables (see [`iter_captured_vars()`](#qiskit.circuit.QuantumCircuit.iter_captured_vars "qiskit.circuit.QuantumCircuit.iter_captured_vars")).

**Return type**

[*Iterable*](https://docs.python.org/3/library/typing.html#typing.Iterable)\[[*Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit._accelerate.circuit.classical.expr.Var")]

#### iter\_captured\_vars

`iter_captured_vars()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L2725-L2731)

Get an iterable over all real-time classical variables that are captured by this circuit scope from a containing scope. This excludes input variables (see [`iter_input_vars()`](#qiskit.circuit.QuantumCircuit.iter_input_vars "qiskit.circuit.QuantumCircuit.iter_input_vars")) and locally declared variables (see [`iter_declared_vars()`](#qiskit.circuit.QuantumCircuit.iter_declared_vars "qiskit.circuit.QuantumCircuit.iter_declared_vars")).

**Return type**

[*Iterable*](https://docs.python.org/3/library/typing.html#typing.Iterable)\[[*Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit._accelerate.circuit.classical.expr.Var")]

#### iter\_captured\_stretches

`iter_captured_stretches()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L2733-L2739)

Get an iterable over stretches that are captured by this circuit scope from a containing scope. This excludes locally declared stretches (see [`iter_declared_stretches()`](#qiskit.circuit.QuantumCircuit.iter_declared_stretches "qiskit.circuit.QuantumCircuit.iter_declared_stretches")).

**Return type**

[*Iterable*](https://docs.python.org/3/library/typing.html#typing.Iterable)\[[*Stretch*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit._accelerate.circuit.classical.expr.Stretch")]

#### iter\_declared\_vars

`iter_declared_vars()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L2690-L2696)

Get an iterable over all real-time classical variables that are declared with automatic storage duration in this scope. This excludes input variables (see [`iter_input_vars()`](#qiskit.circuit.QuantumCircuit.iter_input_vars "qiskit.circuit.QuantumCircuit.iter_input_vars")) and captured variables (see [`iter_captured_vars()`](#qiskit.circuit.QuantumCircuit.iter_captured_vars "qiskit.circuit.QuantumCircuit.iter_captured_vars")).

**Return type**

[*Iterable*](https://docs.python.org/3/library/typing.html#typing.Iterable)\[[*Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit._accelerate.circuit.classical.expr.Var")]

#### iter\_declared\_stretches

`iter_declared_stretches()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L2698-L2703)

Get an iterable over all stretches that are declared in this scope. This excludes captured stretches (see [`iter_captured_stretches()`](#qiskit.circuit.QuantumCircuit.iter_captured_stretches "qiskit.circuit.QuantumCircuit.iter_captured_stretches")).

**Return type**

[*Iterable*](https://docs.python.org/3/library/typing.html#typing.Iterable)\[[*Stretch*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit._accelerate.circuit.classical.expr.Stretch")]

## Adding operations to circuits

You can add anything that implements the [`Operation`](/docs/api/qiskit/qiskit.circuit.Operation "qiskit.circuit.Operation") interface to a circuit as a single instruction, though most things you will want to add will be [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction") or [`Gate`](/docs/api/qiskit/qiskit.circuit.Gate "qiskit.circuit.Gate") instances.

> **See also**
>
> **[Operations, instructions and gates](/docs/api/qiskit/circuit#circuit-operations-instructions)**
>
> The [`qiskit.circuit`](/docs/api/qiskit/circuit#module-qiskit.circuit "qiskit.circuit")-level documentation on the different interfaces that Qiskit uses to define circuit-level instructions.

### Methods to add general operations

These are the base methods that handle adding any object, including user-defined ones, onto circuits.

| Method                                                                                        | When to use it                                                                                                                                                       |
| --------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`append()`](#qiskit.circuit.QuantumCircuit.append "qiskit.circuit.QuantumCircuit.append")    | Add an instruction as a single object onto a circuit.                                                                                                                |
| [`_append()`](#qiskit.circuit.QuantumCircuit._append "qiskit.circuit.QuantumCircuit._append") | Same as [`append()`](#qiskit.circuit.QuantumCircuit.append "qiskit.circuit.QuantumCircuit.append"), but a low-level interface that elides almost all error checking. |
| [`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose") | Inline the instructions from one circuit onto another.                                                                                                               |
| [`tensor()`](#qiskit.circuit.QuantumCircuit.tensor "qiskit.circuit.QuantumCircuit.tensor")    | Like [`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose"), but strictly for joining circuits that act on disjoint qubits.   |

[`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") has two main ways that you will add more operations onto a circuit. Which to use depends on whether you want to add your object as a single “instruction” ([`append()`](#qiskit.circuit.QuantumCircuit.append "qiskit.circuit.QuantumCircuit.append")), or whether you want to join the instructions from two circuits together ([`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose")).

A single instruction or operation appears as a single entry in the [`data`](#qiskit.circuit.QuantumCircuit.data "qiskit.circuit.QuantumCircuit.data") of the circuit, and as a single box when drawn in the circuit visualizers (see [`draw()`](#qiskit.circuit.QuantumCircuit.draw "qiskit.circuit.QuantumCircuit.draw")). A single instruction is the “unit” that a hardware backend might be defined in terms of (see [`Target`](/docs/api/qiskit/qiskit.transpiler.Target "qiskit.transpiler.Target")). An [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction") can come with a [`definition`](/docs/api/qiskit/qiskit.circuit.Instruction#definition "qiskit.circuit.Instruction.definition"), which is one rule the transpiler (see [`qiskit.transpiler`](/docs/api/qiskit/transpiler#module-qiskit.transpiler "qiskit.transpiler")) will be able to fall back on to decompose it for hardware, if needed. An [`Operation`](/docs/api/qiskit/qiskit.circuit.Operation "qiskit.circuit.Operation") that is not also an [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction") can only be decomposed if it has some associated high-level synthesis method registered for it (see [`qiskit.transpiler.passes.synthesis.plugin`](/docs/api/qiskit/transpiler_synthesis_plugins#module-qiskit.transpiler.passes.synthesis.plugin "qiskit.transpiler.passes.synthesis.plugin")).

A [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") alone is not a single [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction"); it is rather more complicated, since it can, in general, represent a complete program with typed classical memory inputs and outputs, and control flow. Qiskit’s (and most hardware’s) data model does not yet have the concept of re-usable callable subroutines with virtual quantum operands. You can convert simple circuits that act only on qubits with unitary operations into a [`Gate`](/docs/api/qiskit/qiskit.circuit.Gate "qiskit.circuit.Gate") using [`to_gate()`](#qiskit.circuit.QuantumCircuit.to_gate "qiskit.circuit.QuantumCircuit.to_gate"), and simple circuits acting only on qubits and clbits into a [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction") with [`to_instruction()`](#qiskit.circuit.QuantumCircuit.to_instruction "qiskit.circuit.QuantumCircuit.to_instruction").

When you have an [`Operation`](/docs/api/qiskit/qiskit.circuit.Operation "qiskit.circuit.Operation"), [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction"), or [`Gate`](/docs/api/qiskit/qiskit.circuit.Gate "qiskit.circuit.Gate"), add it to the circuit, specifying the qubit and clbit arguments with [`append()`](#qiskit.circuit.QuantumCircuit.append "qiskit.circuit.QuantumCircuit.append").

#### append

`append(instruction, qargs=None, cargs=None, *, copy=True)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L2832-L2943)

Append one or more instructions to the end of the circuit, modifying the circuit in place.

The `qargs` and `cargs` will be expanded and broadcast according to the rules of the given [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction"), and any non-[`Bit`](/docs/api/qiskit/circuit#qiskit.circuit.Bit "qiskit.circuit.Bit") specifiers (such as integer indices) will be resolved into the relevant instances.

If a [`CircuitInstruction`](/docs/api/qiskit/qiskit.circuit.CircuitInstruction "qiskit.circuit.CircuitInstruction") is given, it will be unwrapped, verified in the context of this circuit, and a new object will be appended to the circuit. In this case, you may not pass `qargs` or `cargs` separately.

**Parameters**

- **instruction** ([*Operation*](/docs/api/qiskit/qiskit.circuit.Operation "qiskit.circuit.operation.Operation")  *|*[*CircuitInstruction*](/docs/api/qiskit/qiskit.circuit.CircuitInstruction "qiskit._accelerate.circuit.CircuitInstruction")) – [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction") instance to append, or a [`CircuitInstruction`](/docs/api/qiskit/qiskit.circuit.CircuitInstruction "qiskit.circuit.CircuitInstruction") with all its context. Objects implementing `to_instruction` are also supported, but passing an [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction") directly is generally preferred, since that avoids the repeated conversion cost.
- **qargs** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]] | None*) – specifiers of the [`Qubit`](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")s to attach instruction to.
- **cargs** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Clbit*](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")  *|*[*ClassicalRegister*](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Clbit*](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]] | None*) – specifiers of the [`Clbit`](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")s to attach instruction to.
- **copy** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – if `True` (the default), then the incoming `instruction` is copied before adding it to the circuit if it contains symbolic parameters, so it can be safely mutated without affecting other circuits the same instruction might be in. If you are sure this instruction will not be in other circuits, you can set this `False` for a small speedup.

**Returns**

a handle to the [`CircuitInstruction`](/docs/api/qiskit/qiskit.circuit.CircuitInstruction "qiskit.circuit.CircuitInstruction")s that were actually added to the circuit.

**Return type**

[qiskit.circuit.InstructionSet](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.InstructionSet")

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if the operation passed is not an instance of [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction"), or cannot be converted to one by calling `to_instruction` on it.

[`append()`](#qiskit.circuit.QuantumCircuit.append "qiskit.circuit.QuantumCircuit.append") does quite substantial error checking to ensure that you cannot accidentally break the data model of [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit"). If you are programmatically generating a circuit from known-good data, you can elide much of this error checking by using the fast-path appender [`_append()`](#qiskit.circuit.QuantumCircuit._append "qiskit.circuit.QuantumCircuit._append"), but at the risk that the caller is responsible for ensuring they are passing only valid data.

#### \_append

`_append(instruction: CircuitInstruction, *, _standard_gate: bool) → CircuitInstruction`

`_append(instruction: Operation, qargs: Sequence[Qubit], cargs: Sequence[Clbit]) → Operation`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L2960-L3028)

Append an instruction to the end of the circuit, modifying the circuit in place.

> **Warning**
>
> This is an internal fast-path function, and it is the responsibility of the caller to ensure that all the arguments are valid; there is no error checking here. In particular:
>
> - all the qubits and clbits must already exist in the circuit and there can be no duplicates in the list.
> - any control-flow operations instructions must act only on variables present in the circuit.
> - the circuit must not be within a control-flow builder context.

> **Note**
>
> This function may be used by callers other than [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") when the caller is sure that all error-checking, broadcasting and scoping has already been performed, and the only reference to the circuit the instructions are being appended to is within that same function. In particular, it is not safe to call [`QuantumCircuit._append()`](#qiskit.circuit.QuantumCircuit._append "qiskit.circuit.QuantumCircuit._append") on a circuit that is received by a function argument. This is because [`QuantumCircuit._append()`](#qiskit.circuit.QuantumCircuit._append "qiskit.circuit.QuantumCircuit._append") will not recognize the scoping constructs of the control-flow builder interface.

**Parameters**

- **instruction** –

  A complete well-formed [`CircuitInstruction`](/docs/api/qiskit/qiskit.circuit.CircuitInstruction "qiskit.circuit.CircuitInstruction") of the operation and its context to be added.

  In the legacy compatibility form, this can be a bare [`Operation`](/docs/api/qiskit/qiskit.circuit.Operation "qiskit.circuit.Operation"), in which case `qargs` and `cargs` must be explicitly given.

- **qargs** – Legacy argument for qubits to attach the bare [`Operation`](/docs/api/qiskit/qiskit.circuit.Operation "qiskit.circuit.Operation") to. Ignored if the first argument is in the preferential [`CircuitInstruction`](/docs/api/qiskit/qiskit.circuit.CircuitInstruction "qiskit.circuit.CircuitInstruction") form.

- **cargs** – Legacy argument for clbits to attach the bare [`Operation`](/docs/api/qiskit/qiskit.circuit.Operation "qiskit.circuit.Operation") to. Ignored if the first argument is in the preferential [`CircuitInstruction`](/docs/api/qiskit/qiskit.circuit.CircuitInstruction "qiskit.circuit.CircuitInstruction") form.

- **\_standard\_gate** ([*bool*](https://docs.python.org/3/library/functions.html#bool))

**Returns**

a handle to the instruction that was just added.

**Return type**

[CircuitInstruction](/docs/api/qiskit/qiskit.circuit.CircuitInstruction "qiskit.circuit.CircuitInstruction")

In other cases, you may want to join two circuits together, applying the instructions from one circuit onto specified qubits and clbits on another circuit. This “inlining” operation is called [`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose") in Qiskit. [`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose") is, in general, more powerful than a [`to_instruction()`](#qiskit.circuit.QuantumCircuit.to_instruction "qiskit.circuit.QuantumCircuit.to_instruction")-plus-[`append()`](#qiskit.circuit.QuantumCircuit.append "qiskit.circuit.QuantumCircuit.append") combination for joining two circuits, because it can also link typed classical data together, and allows for circuit control-flow operations to be joined onto another circuit.

The downsides to [`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose") are that it is a more complex operation that can involve more rewriting of the operand, and that it necessarily must move data from one circuit object to another. If you are building up a circuit for yourself and raw performance is a core goal, consider passing around your base circuit and having different parts of your algorithm write directly to the base circuit, rather than building a temporary layer circuit.

#### compose

`compose(other: QuantumCircuit | Instruction, qubits: Qubit | QuantumRegister | int | slice | Sequence[Qubit | int] | Sequence[Qubit | QuantumRegister | int | slice | Sequence[Qubit | int]] | None = None, clbits: Clbit | ClassicalRegister | int | slice | Sequence[Clbit | int] | Sequence[Clbit | ClassicalRegister | int | slice | Sequence[Clbit | int]] | None = None, front: bool = False, inplace: Literal[True] = True, wrap: bool = False, *, copy: bool = True, var_remap: Mapping[str | Var | Stretch, str | Var | Stretch] | None = None, inline_captures: bool = False) → None`

`compose(other: QuantumCircuit | Instruction, qubits: Qubit | QuantumRegister | int | slice | Sequence[Qubit | int] | Sequence[Qubit | QuantumRegister | int | slice | Sequence[Qubit | int]] | None = None, clbits: Clbit | ClassicalRegister | int | slice | Sequence[Clbit | int] | Sequence[Clbit | ClassicalRegister | int | slice | Sequence[Clbit | int]] | None = None, front: bool = False, inplace: Literal[False] = False, wrap: bool = False, *, copy: bool = True, var_remap: Mapping[str | Var | Stretch, str | Var | Stretch] | None = None, inline_captures: bool = False) → QuantumCircuit`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L2071-L2424)

Apply the instructions from one circuit onto specified qubits and/or clbits on another.

> **Note**
>
> By default, this creates a new circuit object, leaving `self` untouched. For most uses of this function, it is far more efficient to set `inplace=True` and modify the base circuit in-place.

When dealing with realtime variables ([`expr.Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") and [`expr.Stretch`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch") instances), there are two principal strategies for using [`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose"):

1. The `other` circuit is treated as entirely additive, including its variables. The variables in `other` must be entirely distinct from those in `self` (use `var_remap` to help with this), and all variables in `other` will be declared anew in the output with matching input/capture/local scoping to how they are in `other`. This is generally what you want if you’re joining two unrelated circuits.
2. The `other` circuit was created as an exact extension to `self` to be inlined onto it, including acting on the existing variables in their states at the end of `self`. In this case, `other` should be created with all these variables to be inlined declared as “captures”, and then you can use `inline_captures=True` in this method to link them. This is generally what you want if you’re building up a circuit by defining layers on-the-fly, or rebuilding a circuit using layers taken from itself. You might find the `vars_mode="captures"` argument to [`copy_empty_like()`](#qiskit.circuit.QuantumCircuit.copy_empty_like "qiskit.circuit.QuantumCircuit.copy_empty_like") useful to create each layer’s base, in this case.

**Parameters**

- **other** ([*qiskit.circuit.Instruction*](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction")  *or*[*QuantumCircuit*](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")) – (sub)circuit or instruction to compose onto self. If not a [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit"), this can be anything that [`append`](#qiskit.circuit.QuantumCircuit.append "qiskit.circuit.QuantumCircuit.append") will accept.

- **qubits** ([*list*](https://docs.python.org/3/library/stdtypes.html#list)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")*|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – qubits of self to compose onto.

- **clbits** ([*list*](https://docs.python.org/3/library/stdtypes.html#list)*\[*[*Clbit*](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")*|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – clbits of self to compose onto.

- **front** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – If `True`, front composition will be performed. This is not possible within control-flow builder context managers.

- **inplace** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – If `True`, modify the object. Otherwise, return composed circuit.

- **copy** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – If `True` (the default), then the input is treated as shared, and any contained instructions will be copied, if they might need to be mutated in the future. You can set this to `False` if the input should be considered owned by the base circuit, in order to avoid unnecessary copies; in this case, it is not valid to use `other` afterward, and some instructions may have been mutated in place.

- **var\_remap** (*Mapping*) –

  mapping to use to rewrite [`expr.Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") and [`expr.Stretch`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch") nodes in `other` as they are inlined into `self`. This can be used to avoid naming conflicts.

  Both keys and values can be given as strings or direct identifier instances. If a key is a string, it matches any [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") or [`Stretch`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch") with the same name. If a value is a string, whenever a new key matches it, a new [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") or [`Stretch`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch") is created with the correct type. If a value is a [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var"), its `type` must exactly match that of the variable it is replacing.

- **inline\_captures** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) –

  if `True`, then all “captured” identifier nodes in the `other` [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") are assumed to refer to identifiers already declared in `self` (as any input/capture/local type), and the uses in `other` will apply to the existing identifiers. If you want to build up a layer for an existing circuit to use with [`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose"), you might find the `vars_mode="captures"` argument to [`copy_empty_like()`](#qiskit.circuit.QuantumCircuit.copy_empty_like "qiskit.circuit.QuantumCircuit.copy_empty_like") useful. Any remapping in `vars_remap` occurs before evaluating this variable inlining.

  If this is `False` (the default), then all identifiers in `other` will be required to be distinct from those in `self`, and new declarations will be made for them.

- **wrap** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – If True, wraps the other circuit into a gate (or instruction, depending on whether it contains only unitary instructions) before composing it onto self. Rather than using this option, it is almost always better to manually control this yourself by using [`to_instruction()`](#qiskit.circuit.QuantumCircuit.to_instruction "qiskit.circuit.QuantumCircuit.to_instruction") or [`to_gate()`](#qiskit.circuit.QuantumCircuit.to_gate "qiskit.circuit.QuantumCircuit.to_gate"), and then call [`append()`](#qiskit.circuit.QuantumCircuit.append "qiskit.circuit.QuantumCircuit.append").

**Returns**

the composed circuit (returns None if inplace==True).

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

**Raises**

- [**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if no correct wire mapping can be made between the two circuits, such as if `other` is wider than `self`.
- [**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if trying to emit a new circuit while `self` has a partially built control-flow context active, such as the context-manager forms of [`if_test()`](#qiskit.circuit.QuantumCircuit.if_test "qiskit.circuit.QuantumCircuit.if_test"), [`for_loop()`](#qiskit.circuit.QuantumCircuit.for_loop "qiskit.circuit.QuantumCircuit.for_loop") and [`while_loop()`](#qiskit.circuit.QuantumCircuit.while_loop "qiskit.circuit.QuantumCircuit.while_loop").
- [**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if trying to compose to the front of a circuit when a control-flow builder block is active; there is no clear meaning to this action.

**Examples**

```python
>>> lhs.compose(rhs, qubits=[3, 2], inplace=True)
```

```text
            ┌───┐                   ┌─────┐                ┌───┐
lqr_1_0: ───┤ H ├───    rqr_0: ──■──┤ Tdg ├    lqr_1_0: ───┤ H ├───────────────
            ├───┤              ┌─┴─┐└─────┘                ├───┤
lqr_1_1: ───┤ X ├───    rqr_1: ┤ X ├───────    lqr_1_1: ───┤ X ├───────────────
         ┌──┴───┴──┐           └───┘                    ┌──┴───┴──┐┌───┐
lqr_1_2: ┤ U1(0.1) ├  +                     =  lqr_1_2: ┤ U1(0.1) ├┤ X ├───────
         └─────────┘                                    └─────────┘└─┬─┘┌─────┐
lqr_2_0: ─────■─────                           lqr_2_0: ─────■───────■──┤ Tdg ├
            ┌─┴─┐                                          ┌─┴─┐        └─────┘
lqr_2_1: ───┤ X ├───                           lqr_2_1: ───┤ X ├───────────────
            └───┘                                          └───┘
lcr_0: 0 ═══════════                           lcr_0: 0 ═══════════════════════

lcr_1: 0 ═══════════                           lcr_1: 0 ═══════════════════════
```

If you are trying to join two circuits that will apply to completely disjoint qubits and clbits, [`tensor()`](#qiskit.circuit.QuantumCircuit.tensor "qiskit.circuit.QuantumCircuit.tensor") is a convenient wrapper around manually adding bit objects and calling [`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose").

#### tensor

`tensor(other, inplace=False)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L2426-L2515)

Tensor `self` with `other`.

Remember that in the little-endian convention the leftmost operation will be at the bottom of the circuit. See also [the docs](/docs/guides/construct-circuits) for more information.

```text
     ┌────────┐        ┌─────┐          ┌─────┐
q_0: ┤ bottom ├ ⊗ q_0: ┤ top ├  = q_0: ─┤ top ├──
     └────────┘        └─────┘         ┌┴─────┴─┐
                                  q_1: ┤ bottom ├
                                       └────────┘
```

**Parameters**

- **other** ([*QuantumCircuit*](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")) – The other circuit to tensor this circuit with.
- **inplace** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – If `True`, modify the object. Otherwise return composed circuit.

**Return type**

[*QuantumCircuit*](#qiskit.circuit.QuantumCircuit "qiskit.circuit.quantumcircuit.QuantumCircuit") | None

**Examples**

```python
from qiskit import QuantumCircuit
top = QuantumCircuit(1)
top.x(0);
bottom = QuantumCircuit(2)
bottom.cry(0.2, 0, 1);
tensored = bottom.tensor(top)
tensored.draw('mpl')
```

![Circuit diagram output by the previous code.](https://eu-de.quantum.cloud.ibm.com/docs/images/api/qiskit/qiskit-circuit-QuantumCircuit-17.avif)

**Returns**

The tensored circuit (returns `None` if `inplace=True`).

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

**Parameters**

- **other** ([*QuantumCircuit*](#qiskit.circuit.QuantumCircuit "qiskit.circuit.quantumcircuit.QuantumCircuit"))
- **inplace** ([*bool*](https://docs.python.org/3/library/functions.html#bool))

As some rules of thumb:

- If you have a single [`Operation`](/docs/api/qiskit/qiskit.circuit.Operation "qiskit.circuit.Operation"), [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction") or [`Gate`](/docs/api/qiskit/qiskit.circuit.Gate "qiskit.circuit.Gate"), you should definitely use [`append()`](#qiskit.circuit.QuantumCircuit.append "qiskit.circuit.QuantumCircuit.append") or [`_append()`](#qiskit.circuit.QuantumCircuit._append "qiskit.circuit.QuantumCircuit._append").
- If you have a [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") that represents a single atomic instruction for a larger circuit that you want to re-use, you probably want to call [`to_instruction()`](#qiskit.circuit.QuantumCircuit.to_instruction "qiskit.circuit.QuantumCircuit.to_instruction") or [`to_gate()`](#qiskit.circuit.QuantumCircuit.to_gate "qiskit.circuit.QuantumCircuit.to_gate"), and then apply the result of that to the circuit using [`append()`](#qiskit.circuit.QuantumCircuit.append "qiskit.circuit.QuantumCircuit.append").
- If you have a [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") that represents a larger “layer” of another circuit, or contains typed classical variables or control flow, you should use [`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose") to merge it onto another circuit.
- [`tensor()`](#qiskit.circuit.QuantumCircuit.tensor "qiskit.circuit.QuantumCircuit.tensor") is wanted far more rarely than either [`append()`](#qiskit.circuit.QuantumCircuit.append "qiskit.circuit.QuantumCircuit.append") or [`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose"). Internally, it is mostly a wrapper around [`add_bits()`](#qiskit.circuit.QuantumCircuit.add_bits "qiskit.circuit.QuantumCircuit.add_bits") and [`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose").

Some potential pitfalls to beware of:

- Even if you re-use a custom [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction") during circuit construction, the transpiler will generally have to “unroll” each invocation of it to its inner decomposition before beginning work on it. This should not prevent you from using the [`to_instruction()`](#qiskit.circuit.QuantumCircuit.to_instruction "qiskit.circuit.QuantumCircuit.to_instruction")-plus-[`append()`](#qiskit.circuit.QuantumCircuit.append "qiskit.circuit.QuantumCircuit.append") pattern, as the transpiler will improve in this regard over time.
- [`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose") will, by default, produce a new circuit for backwards compatibility. This is more expensive, and not usually what you want, so you should set `inplace=True`.
- Both [`append()`](#qiskit.circuit.QuantumCircuit.append "qiskit.circuit.QuantumCircuit.append") and [`compose()`](#qiskit.circuit.QuantumCircuit.compose "qiskit.circuit.QuantumCircuit.compose") (but not [`_append()`](#qiskit.circuit.QuantumCircuit._append "qiskit.circuit.QuantumCircuit._append")) have a `copy` keyword argument that defaults to `True`. In these cases, the incoming [`Operation`](/docs/api/qiskit/qiskit.circuit.Operation "qiskit.circuit.Operation") instances will be copied if Qiskit detects that the objects have mutability about them (such as taking gate parameters). If you are sure that you will not re-use the objects again in other places, you should set `copy=False` to prevent this copying, which can be a substantial speed-up for large objects.

### Methods to add standard instructions

The [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") class has helper methods to add many of the Qiskit standard-library instructions and gates onto a circuit. These are generally equivalent to manually constructing an instance of the relevant [`qiskit.circuit.library`](/docs/api/qiskit/circuit_library#module-qiskit.circuit.library "qiskit.circuit.library") object, then passing that to [`append()`](#qiskit.circuit.QuantumCircuit.append "qiskit.circuit.QuantumCircuit.append") with the remaining arguments placed into the `qargs` and `cargs` fields as appropriate.

The following methods apply special non-unitary [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction") operations to the circuit:

| [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") method              | [`qiskit.circuit`](/docs/api/qiskit/circuit#module-qiskit.circuit "qiskit.circuit") [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction") |
| ------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`barrier()`](#qiskit.circuit.QuantumCircuit.barrier "qiskit.circuit.QuantumCircuit.barrier")          | [`Barrier`](/docs/api/qiskit/circuit#qiskit.circuit.Barrier "qiskit.circuit.Barrier")                                                                                         |
| [`delay()`](#qiskit.circuit.QuantumCircuit.delay "qiskit.circuit.QuantumCircuit.delay")                | [`Delay`](/docs/api/qiskit/circuit#qiskit.circuit.Delay "qiskit.circuit.Delay")                                                                                               |
| [`initialize()`](#qiskit.circuit.QuantumCircuit.initialize "qiskit.circuit.QuantumCircuit.initialize") | [`Initialize`](/docs/api/qiskit/qiskit.circuit.library.Initialize "qiskit.circuit.library.Initialize")                                                                        |
| [`measure()`](#qiskit.circuit.QuantumCircuit.measure "qiskit.circuit.QuantumCircuit.measure")          | [`Measure`](/docs/api/qiskit/circuit#qiskit.circuit.Measure "qiskit.circuit.Measure")                                                                                         |
| [`reset()`](#qiskit.circuit.QuantumCircuit.reset "qiskit.circuit.QuantumCircuit.reset")                | [`Reset`](/docs/api/qiskit/circuit#qiskit.circuit.Reset "qiskit.circuit.Reset")                                                                                               |
| [`store()`](#qiskit.circuit.QuantumCircuit.store "qiskit.circuit.QuantumCircuit.store")                | [`Store`](/docs/api/qiskit/circuit#qiskit.circuit.Store "qiskit.circuit.Store")                                                                                               |

These methods apply uncontrolled unitary [`Gate`](/docs/api/qiskit/qiskit.circuit.Gate "qiskit.circuit.Gate") instances to the circuit:

| [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") method                       | [`qiskit.circuit.library`](/docs/api/qiskit/circuit_library#module-qiskit.circuit.library "qiskit.circuit.library") [`Gate`](/docs/api/qiskit/qiskit.circuit.Gate "qiskit.circuit.Gate") |
| --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`dcx()`](#qiskit.circuit.QuantumCircuit.dcx "qiskit.circuit.QuantumCircuit.dcx")                               | [`DCXGate`](/docs/api/qiskit/qiskit.circuit.library.DCXGate "qiskit.circuit.library.DCXGate")                                                                                            |
| [`ecr()`](#qiskit.circuit.QuantumCircuit.ecr "qiskit.circuit.QuantumCircuit.ecr")                               | [`ECRGate`](/docs/api/qiskit/qiskit.circuit.library.ECRGate "qiskit.circuit.library.ECRGate")                                                                                            |
| [`h()`](#qiskit.circuit.QuantumCircuit.h "qiskit.circuit.QuantumCircuit.h")                                     | [`HGate`](/docs/api/qiskit/qiskit.circuit.library.HGate "qiskit.circuit.library.HGate")                                                                                                  |
| [`id()`](#qiskit.circuit.QuantumCircuit.id "qiskit.circuit.QuantumCircuit.id")                                  | [`IGate`](/docs/api/qiskit/qiskit.circuit.library.IGate "qiskit.circuit.library.IGate")                                                                                                  |
| [`iswap()`](#qiskit.circuit.QuantumCircuit.iswap "qiskit.circuit.QuantumCircuit.iswap")                         | [`iSwapGate`](/docs/api/qiskit/qiskit.circuit.library.iSwapGate "qiskit.circuit.library.iSwapGate")                                                                                      |
| [`ms()`](#qiskit.circuit.QuantumCircuit.ms "qiskit.circuit.QuantumCircuit.ms")                                  | [`MSGate`](/docs/api/qiskit/qiskit.circuit.library.MSGate "qiskit.circuit.library.MSGate")                                                                                               |
| [`p()`](#qiskit.circuit.QuantumCircuit.p "qiskit.circuit.QuantumCircuit.p")                                     | [`PhaseGate`](/docs/api/qiskit/qiskit.circuit.library.PhaseGate "qiskit.circuit.library.PhaseGate")                                                                                      |
| [`pauli()`](#qiskit.circuit.QuantumCircuit.pauli "qiskit.circuit.QuantumCircuit.pauli")                         | [`PauliGate`](/docs/api/qiskit/qiskit.circuit.library.PauliGate "qiskit.circuit.library.PauliGate")                                                                                      |
| [`prepare_state()`](#qiskit.circuit.QuantumCircuit.prepare_state "qiskit.circuit.QuantumCircuit.prepare_state") | [`StatePreparation`](/docs/api/qiskit/qiskit.circuit.library.StatePreparation "qiskit.circuit.library.StatePreparation")                                                                 |
| [`r()`](#qiskit.circuit.QuantumCircuit.r "qiskit.circuit.QuantumCircuit.r")                                     | [`RGate`](/docs/api/qiskit/qiskit.circuit.library.RGate "qiskit.circuit.library.RGate")                                                                                                  |
| [`rcccx()`](#qiskit.circuit.QuantumCircuit.rcccx "qiskit.circuit.QuantumCircuit.rcccx")                         | [`RC3XGate`](/docs/api/qiskit/qiskit.circuit.library.RC3XGate "qiskit.circuit.library.RC3XGate")                                                                                         |
| [`rccx()`](#qiskit.circuit.QuantumCircuit.rccx "qiskit.circuit.QuantumCircuit.rccx")                            | [`RCCXGate`](/docs/api/qiskit/qiskit.circuit.library.RCCXGate "qiskit.circuit.library.RCCXGate")                                                                                         |
| [`rv()`](#qiskit.circuit.QuantumCircuit.rv "qiskit.circuit.QuantumCircuit.rv")                                  | [`RVGate`](/docs/api/qiskit/qiskit.circuit.library.RVGate "qiskit.circuit.library.RVGate")                                                                                               |
| [`rx()`](#qiskit.circuit.QuantumCircuit.rx "qiskit.circuit.QuantumCircuit.rx")                                  | [`RXGate`](/docs/api/qiskit/qiskit.circuit.library.RXGate "qiskit.circuit.library.RXGate")                                                                                               |
| [`rxx()`](#qiskit.circuit.QuantumCircuit.rxx "qiskit.circuit.QuantumCircuit.rxx")                               | [`RXXGate`](/docs/api/qiskit/qiskit.circuit.library.RXXGate "qiskit.circuit.library.RXXGate")                                                                                            |
| [`ry()`](#qiskit.circuit.QuantumCircuit.ry "qiskit.circuit.QuantumCircuit.ry")                                  | [`RYGate`](/docs/api/qiskit/qiskit.circuit.library.RYGate "qiskit.circuit.library.RYGate")                                                                                               |
| [`ryy()`](#qiskit.circuit.QuantumCircuit.ryy "qiskit.circuit.QuantumCircuit.ryy")                               | [`RYYGate`](/docs/api/qiskit/qiskit.circuit.library.RYYGate "qiskit.circuit.library.RYYGate")                                                                                            |
| [`rz()`](#qiskit.circuit.QuantumCircuit.rz "qiskit.circuit.QuantumCircuit.rz")                                  | [`RZGate`](/docs/api/qiskit/qiskit.circuit.library.RZGate "qiskit.circuit.library.RZGate")                                                                                               |
| [`rzx()`](#qiskit.circuit.QuantumCircuit.rzx "qiskit.circuit.QuantumCircuit.rzx")                               | [`RZXGate`](/docs/api/qiskit/qiskit.circuit.library.RZXGate "qiskit.circuit.library.RZXGate")                                                                                            |
| [`rzz()`](#qiskit.circuit.QuantumCircuit.rzz "qiskit.circuit.QuantumCircuit.rzz")                               | [`RZZGate`](/docs/api/qiskit/qiskit.circuit.library.RZZGate "qiskit.circuit.library.RZZGate")                                                                                            |
| [`s()`](#qiskit.circuit.QuantumCircuit.s "qiskit.circuit.QuantumCircuit.s")                                     | [`SGate`](/docs/api/qiskit/qiskit.circuit.library.SGate "qiskit.circuit.library.SGate")                                                                                                  |
| [`sdg()`](#qiskit.circuit.QuantumCircuit.sdg "qiskit.circuit.QuantumCircuit.sdg")                               | [`SdgGate`](/docs/api/qiskit/qiskit.circuit.library.SdgGate "qiskit.circuit.library.SdgGate")                                                                                            |
| [`swap()`](#qiskit.circuit.QuantumCircuit.swap "qiskit.circuit.QuantumCircuit.swap")                            | [`SwapGate`](/docs/api/qiskit/qiskit.circuit.library.SwapGate "qiskit.circuit.library.SwapGate")                                                                                         |
| [`sx()`](#qiskit.circuit.QuantumCircuit.sx "qiskit.circuit.QuantumCircuit.sx")                                  | [`SXGate`](/docs/api/qiskit/qiskit.circuit.library.SXGate "qiskit.circuit.library.SXGate")                                                                                               |
| [`sxdg()`](#qiskit.circuit.QuantumCircuit.sxdg "qiskit.circuit.QuantumCircuit.sxdg")                            | [`SXdgGate`](/docs/api/qiskit/qiskit.circuit.library.SXdgGate "qiskit.circuit.library.SXdgGate")                                                                                         |
| [`t()`](#qiskit.circuit.QuantumCircuit.t "qiskit.circuit.QuantumCircuit.t")                                     | [`TGate`](/docs/api/qiskit/qiskit.circuit.library.TGate "qiskit.circuit.library.TGate")                                                                                                  |
| [`tdg()`](#qiskit.circuit.QuantumCircuit.tdg "qiskit.circuit.QuantumCircuit.tdg")                               | [`TdgGate`](/docs/api/qiskit/qiskit.circuit.library.TdgGate "qiskit.circuit.library.TdgGate")                                                                                            |
| [`u()`](#qiskit.circuit.QuantumCircuit.u "qiskit.circuit.QuantumCircuit.u")                                     | [`UGate`](/docs/api/qiskit/qiskit.circuit.library.UGate "qiskit.circuit.library.UGate")                                                                                                  |
| [`unitary()`](#qiskit.circuit.QuantumCircuit.unitary "qiskit.circuit.QuantumCircuit.unitary")                   | [`UnitaryGate`](/docs/api/qiskit/qiskit.circuit.library.UnitaryGate "qiskit.circuit.library.UnitaryGate")                                                                                |
| [`x()`](#qiskit.circuit.QuantumCircuit.x "qiskit.circuit.QuantumCircuit.x")                                     | [`XGate`](/docs/api/qiskit/qiskit.circuit.library.XGate "qiskit.circuit.library.XGate")                                                                                                  |
| [`y()`](#qiskit.circuit.QuantumCircuit.y "qiskit.circuit.QuantumCircuit.y")                                     | [`YGate`](/docs/api/qiskit/qiskit.circuit.library.YGate "qiskit.circuit.library.YGate")                                                                                                  |
| [`z()`](#qiskit.circuit.QuantumCircuit.z "qiskit.circuit.QuantumCircuit.z")                                     | [`ZGate`](/docs/api/qiskit/qiskit.circuit.library.ZGate "qiskit.circuit.library.ZGate")                                                                                                  |

The following methods apply [`Gate`](/docs/api/qiskit/qiskit.circuit.Gate "qiskit.circuit.Gate") instances that are also controlled gates, so are direct subclasses of [`ControlledGate`](/docs/api/qiskit/qiskit.circuit.ControlledGate "qiskit.circuit.ControlledGate"):

| [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") method | [`qiskit.circuit.library`](/docs/api/qiskit/circuit_library#module-qiskit.circuit.library "qiskit.circuit.library") [`ControlledGate`](/docs/api/qiskit/qiskit.circuit.ControlledGate "qiskit.circuit.ControlledGate") |
| ----------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`ccx()`](#qiskit.circuit.QuantumCircuit.ccx "qiskit.circuit.QuantumCircuit.ccx")         | [`CCXGate`](/docs/api/qiskit/qiskit.circuit.library.CCXGate "qiskit.circuit.library.CCXGate")                                                                                                                          |
| [`ccz()`](#qiskit.circuit.QuantumCircuit.ccz "qiskit.circuit.QuantumCircuit.ccz")         | [`CCZGate`](/docs/api/qiskit/qiskit.circuit.library.CCZGate "qiskit.circuit.library.CCZGate")                                                                                                                          |
| [`ch()`](#qiskit.circuit.QuantumCircuit.ch "qiskit.circuit.QuantumCircuit.ch")            | [`CHGate`](/docs/api/qiskit/qiskit.circuit.library.CHGate "qiskit.circuit.library.CHGate")                                                                                                                             |
| [`cp()`](#qiskit.circuit.QuantumCircuit.cp "qiskit.circuit.QuantumCircuit.cp")            | [`CPhaseGate`](/docs/api/qiskit/qiskit.circuit.library.CPhaseGate "qiskit.circuit.library.CPhaseGate")                                                                                                                 |
| [`crx()`](#qiskit.circuit.QuantumCircuit.crx "qiskit.circuit.QuantumCircuit.crx")         | [`CRXGate`](/docs/api/qiskit/qiskit.circuit.library.CRXGate "qiskit.circuit.library.CRXGate")                                                                                                                          |
| [`cry()`](#qiskit.circuit.QuantumCircuit.cry "qiskit.circuit.QuantumCircuit.cry")         | [`CRYGate`](/docs/api/qiskit/qiskit.circuit.library.CRYGate "qiskit.circuit.library.CRYGate")                                                                                                                          |
| [`crz()`](#qiskit.circuit.QuantumCircuit.crz "qiskit.circuit.QuantumCircuit.crz")         | [`CRZGate`](/docs/api/qiskit/qiskit.circuit.library.CRZGate "qiskit.circuit.library.CRZGate")                                                                                                                          |
| [`cs()`](#qiskit.circuit.QuantumCircuit.cs "qiskit.circuit.QuantumCircuit.cs")            | [`CSGate`](/docs/api/qiskit/qiskit.circuit.library.CSGate "qiskit.circuit.library.CSGate")                                                                                                                             |
| [`csdg()`](#qiskit.circuit.QuantumCircuit.csdg "qiskit.circuit.QuantumCircuit.csdg")      | [`CSdgGate`](/docs/api/qiskit/qiskit.circuit.library.CSdgGate "qiskit.circuit.library.CSdgGate")                                                                                                                       |
| [`cswap()`](#qiskit.circuit.QuantumCircuit.cswap "qiskit.circuit.QuantumCircuit.cswap")   | [`CSwapGate`](/docs/api/qiskit/qiskit.circuit.library.CSwapGate "qiskit.circuit.library.CSwapGate")                                                                                                                    |
| [`csx()`](#qiskit.circuit.QuantumCircuit.csx "qiskit.circuit.QuantumCircuit.csx")         | [`CSXGate`](/docs/api/qiskit/qiskit.circuit.library.CSXGate "qiskit.circuit.library.CSXGate")                                                                                                                          |
| [`cu()`](#qiskit.circuit.QuantumCircuit.cu "qiskit.circuit.QuantumCircuit.cu")            | [`CUGate`](/docs/api/qiskit/qiskit.circuit.library.CUGate "qiskit.circuit.library.CUGate")                                                                                                                             |
| [`cx()`](#qiskit.circuit.QuantumCircuit.cx "qiskit.circuit.QuantumCircuit.cx")            | [`CXGate`](/docs/api/qiskit/qiskit.circuit.library.CXGate "qiskit.circuit.library.CXGate")                                                                                                                             |
| [`cy()`](#qiskit.circuit.QuantumCircuit.cy "qiskit.circuit.QuantumCircuit.cy")            | [`CYGate`](/docs/api/qiskit/qiskit.circuit.library.CYGate "qiskit.circuit.library.CYGate")                                                                                                                             |
| [`cz()`](#qiskit.circuit.QuantumCircuit.cz "qiskit.circuit.QuantumCircuit.cz")            | [`CZGate`](/docs/api/qiskit/qiskit.circuit.library.CZGate "qiskit.circuit.library.CZGate")                                                                                                                             |

Finally, these methods apply particular generalized multiply controlled gates to the circuit, often with eager syntheses. They are listed in terms of the *base* gate they are controlling, since their exact output is often a synthesized version of a gate.

| [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") method | Base [`qiskit.circuit.library`](/docs/api/qiskit/circuit_library#module-qiskit.circuit.library "qiskit.circuit.library") [`Gate`](/docs/api/qiskit/qiskit.circuit.Gate "qiskit.circuit.Gate") |
| ----------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`mcp()`](#qiskit.circuit.QuantumCircuit.mcp "qiskit.circuit.QuantumCircuit.mcp")         | [`PhaseGate`](/docs/api/qiskit/qiskit.circuit.library.PhaseGate "qiskit.circuit.library.PhaseGate")                                                                                           |
| [`mcrx()`](#qiskit.circuit.QuantumCircuit.mcrx "qiskit.circuit.QuantumCircuit.mcrx")      | [`RXGate`](/docs/api/qiskit/qiskit.circuit.library.RXGate "qiskit.circuit.library.RXGate")                                                                                                    |
| [`mcry()`](#qiskit.circuit.QuantumCircuit.mcry "qiskit.circuit.QuantumCircuit.mcry")      | [`RYGate`](/docs/api/qiskit/qiskit.circuit.library.RYGate "qiskit.circuit.library.RYGate")                                                                                                    |
| [`mcrz()`](#qiskit.circuit.QuantumCircuit.mcrz "qiskit.circuit.QuantumCircuit.mcrz")      | [`RZGate`](/docs/api/qiskit/qiskit.circuit.library.RZGate "qiskit.circuit.library.RZGate")                                                                                                    |
| [`mcx()`](#qiskit.circuit.QuantumCircuit.mcx "qiskit.circuit.QuantumCircuit.mcx")         | [`XGate`](/docs/api/qiskit/qiskit.circuit.library.XGate "qiskit.circuit.library.XGate")                                                                                                       |

The rest of this section is the API listing of all the individual methods; the tables above are summaries whose links will jump you to the correct place.

#### barrier

`barrier(*qargs, label=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5102-L5127)

Apply `Barrier`. If `qargs` is empty, applies to all qubits in the circuit.

**Parameters**

- **qargs** (*QubitSpecifier*) – Specification for one or more qubit arguments.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) – The string label of the barrier.

**Returns**

handle to the added instructions.

**Return type**

[qiskit.circuit.InstructionSet](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.InstructionSet")

#### ccx

`ccx(control_qubit1, control_qubit2, target_qubit, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6282-L6319)

Apply [`CCXGate`](/docs/api/qiskit/qiskit.circuit.library.CCXGate "qiskit.circuit.library.CCXGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **control\_qubit1** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the first control.
- **control\_qubit2** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the second control.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. ‘1’). Defaults to controlling on the ‘1’ state.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### ccz

`ccz(control_qubit1, control_qubit2, target_qubit, label=None, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6533-L6573)

Apply [`CCZGate`](/docs/api/qiskit/qiskit.circuit.library.CCZGate "qiskit.circuit.library.CCZGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **control\_qubit1** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the first control.
- **control\_qubit2** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the second control.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. ‘10’). Defaults to controlling on the ‘11’ state.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### ch

`ch(control_qubit, target_qubit, label=None, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5171-L5206)

Apply [`CHGate`](/docs/api/qiskit/qiskit.circuit.library.CHGate "qiskit.circuit.library.CHGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **control\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the control.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. ‘1’). Defaults to controlling on the ‘1’ state.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### cp

`cp(theta, control_qubit, target_qubit, label=None, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5252-L5289)

Apply [`CPhaseGate`](/docs/api/qiskit/qiskit.circuit.library.CPhaseGate "qiskit.circuit.library.CPhaseGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The angle of the rotation.
- **control\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the control.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. ‘1’). Defaults to controlling on the ‘1’ state.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### crx

`crx(theta, control_qubit, target_qubit, label=None, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5651-L5688)

Apply [`CRXGate`](/docs/api/qiskit/qiskit.circuit.library.CRXGate "qiskit.circuit.library.CRXGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The angle of the rotation.
- **control\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the control.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. ‘1’). Defaults to controlling on the ‘1’ state.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### cry

`cry(theta, control_qubit, target_qubit, label=None, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5724-L5761)

Apply [`CRYGate`](/docs/api/qiskit/qiskit.circuit.library.CRYGate "qiskit.circuit.library.CRYGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The angle of the rotation.
- **control\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the control.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. ‘1’). Defaults to controlling on the ‘1’ state.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### crz

`crz(theta, control_qubit, target_qubit, label=None, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5794-L5831)

Apply [`CRZGate`](/docs/api/qiskit/qiskit.circuit.library.CRZGate "qiskit.circuit.library.CRZGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The angle of the rotation.
- **control\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the control.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. ‘1’). Defaults to controlling on the ‘1’ state.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### cs

`cs(control_qubit, target_qubit, label=None, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5907-L5942)

Apply [`CSGate`](/docs/api/qiskit/qiskit.circuit.library.CSGate "qiskit.circuit.library.CSGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **control\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the control.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. ‘1’). Defaults to controlling on the ‘1’ state.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### csdg

`csdg(control_qubit, target_qubit, label=None, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5944-L5979)

Apply [`CSdgGate`](/docs/api/qiskit/qiskit.circuit.library.CSdgGate "qiskit.circuit.library.CSdgGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **control\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the control.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. ‘1’). Defaults to controlling on the ‘1’ state.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### cswap

`cswap(control_qubit, target_qubit1, target_qubit2, label=None, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6013-L6053)

Apply [`CSwapGate`](/docs/api/qiskit/qiskit.circuit.library.CSwapGate "qiskit.circuit.library.CSwapGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **control\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the control.
- **target\_qubit1** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **target\_qubit2** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. `'1'`). Defaults to controlling on the `'1'` state.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### csx

`csx(control_qubit, target_qubit, label=None, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6081-L6116)

Apply [`CSXGate`](/docs/api/qiskit/qiskit.circuit.library.CSXGate "qiskit.circuit.library.CSXGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **control\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the control.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. ‘1’). Defaults to controlling on the ‘1’ state.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### cu

`cu(theta, phi, lam, gamma, control_qubit, target_qubit, label=None, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6166-L6212)

Apply [`CUGate`](/docs/api/qiskit/qiskit.circuit.library.CUGate "qiskit.circuit.library.CUGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The $\theta$ rotation angle of the gate.
- **phi** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The $\phi$ rotation angle of the gate.
- **lam** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The $\lambda$ rotation angle of the gate.
- **gamma** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The global phase applied of the U gate, if applied.
- **control\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the control.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. ‘1’). Defaults to controlling on the ‘1’ state.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### cx

`cx(control_qubit, target_qubit, label=None, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6228-L6266)

Apply [`CXGate`](/docs/api/qiskit/qiskit.circuit.library.CXGate "qiskit.circuit.library.CXGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **control\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the control.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. ‘1’). Defaults to controlling on the ‘1’ state.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### cy

`cy(control_qubit, target_qubit, label=None, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6443-L6481)

Apply [`CYGate`](/docs/api/qiskit/qiskit.circuit.library.CYGate "qiskit.circuit.library.CYGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **control\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the controls.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. ‘1’). Defaults to controlling on the ‘1’ state.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### cz

`cz(control_qubit, target_qubit, label=None, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6496-L6531)

Apply [`CZGate`](/docs/api/qiskit/qiskit.circuit.library.CZGate "qiskit.circuit.library.CZGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **control\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the controls.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. ‘1’). Defaults to controlling on the ‘1’ state.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### dcx

`dcx(qubit1, qubit2)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6268-L6280)

Apply [`DCXGate`](/docs/api/qiskit/qiskit.circuit.library.DCXGate "qiskit.circuit.library.DCXGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **qubit1** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.
- **qubit2** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### delay

`delay(duration, qarg=None, unit=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5129-L5156)

Apply [`Delay`](/docs/api/qiskit/circuit#qiskit.circuit.Delay "qiskit.circuit.Delay"). If qarg is `None`, applies to all qubits. When applying to multiple qubits, delays with the same duration will be created.

**Parameters**

- **duration** (*Object*) – duration of the delay. If this is an [`Expr`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Expr "qiskit.circuit.classical.expr.Expr"), it must be a constant expression of type [`Duration`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.types.Duration "qiskit.circuit.classical.types.Duration").
- **qarg** (*Object*) – qubit argument to apply this delay.
- **unit** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – unit of the duration, unless `duration` is an [`Expr`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Expr "qiskit.circuit.classical.expr.Expr") in which case it must not be specified. Supported units: `'s'`, `'ms'`, `'us'`, `'ns'`, `'ps'`, and `'dt'`. Default is `'dt'`, i.e. integer time unit depending on the target backend.

**Returns**

handle to the added instructions.

**Return type**

[qiskit.circuit.InstructionSet](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.InstructionSet")

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if arguments have bad format.

#### ecr

`ecr(qubit1, qubit2)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5867-L5879)

Apply [`ECRGate`](/docs/api/qiskit/qiskit.circuit.library.ECRGate "qiskit.circuit.library.ECRGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **qubit1** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The first qubit to apply the gate to.
- **qubit2** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The second qubit to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### h

`h(qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5158-L5169)

Apply [`HGate`](/docs/api/qiskit/qiskit.circuit.library.HGate "qiskit.circuit.library.HGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

**qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### id

`id(qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5208-L5219)

Apply [`IGate`](/docs/api/qiskit/qiskit.circuit.library.IGate "qiskit.circuit.library.IGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

**qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### initialize

`initialize(params, qubits=None, normalize=False)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6714-L6829)

Initialize qubits in a specific state.

Qubit initialization is done by first resetting the qubits to $|0\rangle$ followed by calling [`StatePreparation`](/docs/api/qiskit/qiskit.circuit.library.StatePreparation "qiskit.circuit.library.StatePreparation") class to prepare the qubits in a specified state. Both these steps are included in the [`Initialize`](/docs/api/qiskit/qiskit.circuit.library.Initialize "qiskit.circuit.library.Initialize") instruction.

**Parameters**

- **params** ([*Statevector*](/docs/api/qiskit/qiskit.quantum_info.Statevector "qiskit.quantum_info.Statevector") *| Sequence\[*[*complex*](https://docs.python.org/3/library/functions.html#complex)*] |* [*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int)) –

  The state to initialize to, can be either of the following.

  - Statevector or vector of complex amplitudes to initialize to.
  - Labels of basis states of the Pauli eigenstates Z, X, Y. See [`Statevector.from_label()`](/docs/api/qiskit/qiskit.quantum_info.Statevector#from_label "qiskit.quantum_info.Statevector.from_label"). Notice the order of the labels is reversed with respect to the qubit index to be applied to. Example label `'01'` initializes the qubit zero to $|1\rangle$ and the qubit one to $|0\rangle$.
  - An integer that is used as a bitmap indicating which qubits to initialize to $|1\rangle$. Example: setting params to 5 would initialize qubit 0 and qubit 2 to $|1\rangle$ and qubit 1 to $|0\rangle$.

- **qubits** (*Sequence\[QubitSpecifier] | None*) – Qubits to initialize. If `None` the initialization is applied to all qubits in the circuit.

- **normalize** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – Whether to normalize an input array to a unit vector.

**Returns**

A handle to the instructions created.

**Examples**

Prepare a qubit in the state $(|0\rangle - |1\rangle) / \sqrt{2}$.

```python
import numpy as np
from qiskit import QuantumCircuit

circuit = QuantumCircuit(1)
circuit.initialize([1/np.sqrt(2), -1/np.sqrt(2)], 0)
circuit.draw()
```

output:

```text
     ┌──────────────────────────────┐
q_0: ┤ Initialize(0.70711,-0.70711) ├
     └──────────────────────────────┘
```

Initialize from a string two qubits in the state $|10\rangle$. The order of the labels is reversed with respect to qubit index. More information about labels for basis states are in [`Statevector.from_label()`](/docs/api/qiskit/qiskit.quantum_info.Statevector#from_label "qiskit.quantum_info.Statevector.from_label").

```python
import numpy as np
from qiskit import QuantumCircuit

circuit = QuantumCircuit(2)
circuit.initialize('01', circuit.qubits)
circuit.draw()
```

output:

```text
     ┌──────────────────┐
q_0: ┤0                 ├
     │  Initialize(0,1) │
q_1: ┤1                 ├
     └──────────────────┘
```

Initialize two qubits from an array of complex amplitudes.

```python
import numpy as np
from qiskit import QuantumCircuit

circuit = QuantumCircuit(2)
circuit.initialize([0, 1/np.sqrt(2), -1.j/np.sqrt(2), 0], circuit.qubits)
circuit.draw()
```

output:

```text
     ┌────────────────────────────────────┐
q_0: ┤0                                   ├
     │  Initialize(0,0.70711,-0.70711j,0) │
q_1: ┤1                                   ├
     └────────────────────────────────────┘
```

#### iswap

`iswap(qubit1, qubit2)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5999-L6011)

Apply [`iSwapGate`](/docs/api/qiskit/qiskit.circuit.library.iSwapGate "qiskit.circuit.library.iSwapGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **qubit1** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The first qubit to apply the gate to.
- **qubit2** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The second qubit to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### mcp

`mcp(lam, control_qubits, target_qubit, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5291-L5321)

Apply [`MCPhaseGate`](/docs/api/qiskit/qiskit.circuit.library.MCPhaseGate "qiskit.circuit.library.MCPhaseGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **lam** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The angle of the rotation.
- **control\_qubits** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]]*) – The qubits used as the controls.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. ‘1’). Defaults to controlling on the ‘1’ state.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### mcrx

`mcrx(theta, q_controls, q_target, use_basis_gates=False)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5323-L5385)

Apply Multiple-Controlled X rotation gate

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The angle of the rotation.
- **q\_controls** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]]*) – The qubits used as the controls.
- **q\_target** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit targeted by the gate.
- **use\_basis\_gates** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – use p, u, cx basis gates.

#### mcry

`mcry(theta, q_controls, q_target, q_ancillae=None, mode=None, use_basis_gates=False)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5387-L5489)

Apply Multiple-Controlled Y rotation gate

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The angle of the rotation.
- **q\_controls** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]]*) – The qubits used as the controls.
- **q\_target** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit targeted by the gate.
- **q\_ancillae** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*] |* [*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]] | None*) – The list of ancillary qubits.
- **mode** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The implementation mode to use.
- **use\_basis\_gates** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – use p, u, cx basis gates

#### mcrz

`mcrz(lam, q_controls, q_target, use_basis_gates=False)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5491-L5540)

Apply Multiple-Controlled Z rotation gate

**Parameters**

- **lam** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The angle of the rotation.
- **q\_controls** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]]*) – The qubits used as the controls.
- **q\_target** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit targeted by the gate.
- **use\_basis\_gates** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – use p, u, cx basis gates.

#### mcx

`mcx(control_qubits, target_qubit, ancilla_qubits=None, mode=None, ctrl_state=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6321-L6428)

Apply [`MCXGate`](/docs/api/qiskit/qiskit.circuit.library.MCXGate "qiskit.circuit.library.MCXGate").

The multi-cX gate can be implemented using different techniques, which use different numbers of ancilla qubits and have varying circuit depth. These modes are:

- `'noancilla'`: Requires 0 ancilla qubits.
- `'recursion'`: Requires 1 ancilla qubit if more than 4 controls are used, otherwise 0.
- `'v-chain'`: Requires 2 less ancillas than the number of control qubits.
- `'v-chain-dirty'`: Same as for the clean ancillas (but the circuit will be longer).

For the full matrix form of this gate, see the underlying gate documentation.

> **Deprecated since version 2.1**
>
> `qiskit.circuit.quantumcircuit.QuantumCircuit.mcx()`’s argument `mode` is deprecated as of Qiskit 2.1. It will be removed no earlier than 3 months after the release date. Instead, add a generic MCXGate to the circuit and specify the synthesis method via the `hls_config` in the transpilation. Alternatively, specific decompositions are available at [https://qisk.it/mcx](https://qisk.it/mcx).

**Parameters**

- **control\_qubits** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]]*) – The qubits used as the controls.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.
- **ancilla\_qubits** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*] |* [*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]] | None*) – The qubits used as the ancillae, if the mode requires them.
- **mode** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The choice of mode, explained further above.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state in decimal, or as a bitstring (e.g. ‘1’). Defaults to controlling on the ‘1’ state.

**Returns**

A handle to the instructions created.

**Raises**

- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – if the given mode is not known, or if too few ancilla qubits are passed.
- [**AttributeError**](https://docs.python.org/3/library/exceptions.html#AttributeError) – if no ancilla qubits are passed, but some are needed.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### measure

`measure(qubit, cbit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4493-L4584)

Measure a quantum bit (`qubit`) in the Z basis into a classical bit (`cbit`).

When a quantum state is measured, a qubit is projected in the computational (Pauli Z) basis to either $\lvert 0 \rangle$ or $\lvert 1 \rangle$. The classical bit `cbit` indicates the result of that projection as a `0` or a `1` respectively. This operation is non-reversible.

**Parameters**

- **qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – qubit(s) to measure.
- **cbit** ([*Clbit*](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")  *|*[*ClassicalRegister*](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Clbit*](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – classical bit(s) to place the measurement result(s) in, or a [`expr.Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") of [`types.Uint`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.types.Uint "qiskit.circuit.classical.types.Uint") type indexing the target clbit.

**Returns**

handle to the added instructions.

**Return type**

[qiskit.circuit.InstructionSet](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.InstructionSet")

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if arguments have bad format.

**Examples**

In this example, a qubit is measured and the result of that measurement is stored in the classical bit (usually expressed in diagrams as a double line):

```python
from qiskit import QuantumCircuit
circuit = QuantumCircuit(1, 1)
circuit.h(0)
circuit.measure(0, 0)
circuit.draw()
```

```text
     ┌───┐┌─┐
  q: ┤ H ├┤M├
     └───┘└╥┘
c: 1/══════╩═
           0
```

It is possible to call `measure` with lists of `qubits` and `cbits` as a shortcut for one-to-one measurement. These two forms produce identical results:

```python
circuit = QuantumCircuit(2, 2)
circuit.measure([0,1], [0,1])
```

```python
circuit = QuantumCircuit(2, 2)
circuit.measure(0, 0)
circuit.measure(1, 1)
```

Instead of lists, you can use [`QuantumRegister`](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister") and [`ClassicalRegister`](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister") under the same logic.

```python
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
qreg = QuantumRegister(2, "qreg")
creg = ClassicalRegister(2, "creg")
circuit = QuantumCircuit(qreg, creg)
circuit.measure(qreg, creg)
```

This is equivalent to:

```python
circuit = QuantumCircuit(qreg, creg)
circuit.measure(qreg[0], creg[0])
circuit.measure(qreg[1], creg[1])
```

#### ms

`ms(theta, qubits)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5221-L5236)

Apply [`MSGate`](/docs/api/qiskit/qiskit.circuit.library.MSGate "qiskit.circuit.library.MSGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The angle of the rotation.
- **qubits** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]]*) – The qubits to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### p

`p(theta, qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5238-L5250)

Apply [`PhaseGate`](/docs/api/qiskit/qiskit.circuit.library.PhaseGate "qiskit.circuit.library.PhaseGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The angle of the rotation.
- **qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### pauli

`pauli(pauli_string, qubits)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6575-L6591)

Apply [`PauliGate`](/docs/api/qiskit/qiskit.circuit.library.PauliGate "qiskit.circuit.library.PauliGate").

**Parameters**

- **pauli\_string** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) – A string representing the Pauli operator to apply, e.g. ‘XX’.
- **qubits** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]]*) – The qubits to apply this gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### prepare\_state

`prepare_state(state, qubits=None, label=None, normalize=False)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6593-L6712)

Prepare qubits in a specific state.

This class implements a state preparing unitary. Unlike [`initialize()`](#qiskit.circuit.QuantumCircuit.initialize "qiskit.circuit.QuantumCircuit.initialize") it does not reset the qubits first.

**Parameters**

- **state** ([*Statevector*](/docs/api/qiskit/qiskit.quantum_info.Statevector "qiskit.quantum_info.Statevector") *| Sequence\[*[*complex*](https://docs.python.org/3/library/functions.html#complex)*] |* [*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int)) –

  The state to initialize to, can be either of the following.

  - Statevector or vector of complex amplitudes to initialize to.
  - Labels of basis states of the Pauli eigenstates Z, X, Y. See [`Statevector.from_label()`](/docs/api/qiskit/qiskit.quantum_info.Statevector#from_label "qiskit.quantum_info.Statevector.from_label"). Notice the order of the labels is reversed with respect to the qubit index to be applied to. Example label ‘01’ initializes the qubit zero to $|1\rangle$ and the qubit one to $|0\rangle$.
  - An integer that is used as a bitmap indicating which qubits to initialize to $|1\rangle$. Example: setting params to 5 would initialize qubit 0 and qubit 2 to $|1\rangle$ and qubit 1 to $|0\rangle$.

- **qubits** (*Sequence\[QubitSpecifier] | None*) – Qubits to initialize. If `None` the initialization is applied to all qubits in the circuit.

- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – An optional label for the gate

- **normalize** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – Whether to normalize an input array to a unit vector.

**Returns**

A handle to the instruction that was just initialized

**Return type**

[InstructionSet](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.InstructionSet")

**Examples**

Prepare a qubit in the state $(|0\rangle - |1\rangle) / \sqrt{2}$.

```python
import numpy as np
from qiskit import QuantumCircuit

circuit = QuantumCircuit(1)
circuit.prepare_state([1/np.sqrt(2), -1/np.sqrt(2)], 0)
circuit.draw()
```

output:

```text
     ┌─────────────────────────────────────┐
q_0: ┤ State Preparation(0.70711,-0.70711) ├
     └─────────────────────────────────────┘
```

Prepare from a string two qubits in the state $|10\rangle$. The order of the labels is reversed with respect to qubit index. More information about labels for basis states are in [`Statevector.from_label()`](/docs/api/qiskit/qiskit.quantum_info.Statevector#from_label "qiskit.quantum_info.Statevector.from_label").

```python
import numpy as np
from qiskit import QuantumCircuit

circuit = QuantumCircuit(2)
circuit.prepare_state('01', circuit.qubits)
circuit.draw()
```

output:

```text
     ┌─────────────────────────┐
q_0: ┤0                        ├
     │  State Preparation(0,1) │
q_1: ┤1                        ├
     └─────────────────────────┘
```

Initialize two qubits from an array of complex amplitudes

```python
import numpy as np
from qiskit import QuantumCircuit

circuit = QuantumCircuit(2)
circuit.prepare_state([0, 1/np.sqrt(2), -1.j/np.sqrt(2), 0], circuit.qubits)
circuit.draw()
```

output:

```text
     ┌───────────────────────────────────────────┐
q_0: ┤0                                          ├
     │  State Preparation(0,0.70711,-0.70711j,0) │
q_1: ┤1                                          ├
     └───────────────────────────────────────────┘
```

#### r

`r(theta, phi, qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5542-L5557)

Apply [`RGate`](/docs/api/qiskit/qiskit.circuit.library.RGate "qiskit.circuit.library.RGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The angle of the rotation.
- **phi** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The angle of the axis of rotation in the x-y plane.
- **qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### rcccx

`rcccx(control_qubit1, control_qubit2, control_qubit3, target_qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5608-L5632)

Apply [`RC3XGate`](/docs/api/qiskit/qiskit.circuit.library.RC3XGate "qiskit.circuit.library.RC3XGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **control\_qubit1** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the first control.
- **control\_qubit2** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the second control.
- **control\_qubit3** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the third control.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### rccx

`rccx(control_qubit1, control_qubit2, target_qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5586-L5606)

Apply [`RCCXGate`](/docs/api/qiskit/qiskit.circuit.library.RCCXGate "qiskit.circuit.library.RCCXGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **control\_qubit1** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the first control.
- **control\_qubit2** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) used as the second control.
- **target\_qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) targeted by the gate.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### reset

`reset(qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4449-L4460)

Reset the quantum bit(s) to their default state.

**Parameters**

**qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – qubit(s) to reset.

**Returns**

handle to the added instruction.

**Return type**

[qiskit.circuit.InstructionSet](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.InstructionSet")

#### rv

`rv(vx, vy, vz, qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5559-L5584)

Apply [`RVGate`](/docs/api/qiskit/qiskit.circuit.library.RVGate "qiskit.circuit.library.RVGate").

For the full matrix form of this gate, see the underlying gate documentation.

Rotation around an arbitrary rotation axis $v$, where $|v|$ is the angle of rotation in radians.

**Parameters**

- **vx** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – x-component of the rotation axis.
- **vy** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – y-component of the rotation axis.
- **vz** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – z-component of the rotation axis.
- **qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### rx

`rx(theta, qubit, label=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5634-L5649)

Apply [`RXGate`](/docs/api/qiskit/qiskit.circuit.library.RXGate "qiskit.circuit.library.RXGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The rotation angle of the gate.
- **qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### rxx

`rxx(theta, qubit1, qubit2)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5690-L5705)

Apply [`RXXGate`](/docs/api/qiskit/qiskit.circuit.library.RXXGate "qiskit.circuit.library.RXXGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The angle of the rotation.
- **qubit1** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.
- **qubit2** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### ry

`ry(theta, qubit, label=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5707-L5722)

Apply [`RYGate`](/docs/api/qiskit/qiskit.circuit.library.RYGate "qiskit.circuit.library.RYGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The rotation angle of the gate.
- **qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### ryy

`ryy(theta, qubit1, qubit2)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5763-L5778)

Apply [`RYYGate`](/docs/api/qiskit/qiskit.circuit.library.RYYGate "qiskit.circuit.library.RYYGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The rotation angle of the gate.
- **qubit1** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.
- **qubit2** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### rz

`rz(phi, qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5780-L5792)

Apply [`RZGate`](/docs/api/qiskit/qiskit.circuit.library.RZGate "qiskit.circuit.library.RZGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **phi** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The rotation angle of the gate.
- **qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### rzx

`rzx(theta, qubit1, qubit2)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5833-L5848)

Apply [`RZXGate`](/docs/api/qiskit/qiskit.circuit.library.RZXGate "qiskit.circuit.library.RZXGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The rotation angle of the gate.
- **qubit1** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.
- **qubit2** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### rzz

`rzz(theta, qubit1, qubit2)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5850-L5865)

Apply [`RZZGate`](/docs/api/qiskit/qiskit.circuit.library.RZZGate "qiskit.circuit.library.RZZGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The rotation angle of the gate.
- **qubit1** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.
- **qubit2** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### s

`s(qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5881-L5892)

Apply [`SGate`](/docs/api/qiskit/qiskit.circuit.library.SGate "qiskit.circuit.library.SGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

**qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### sdg

`sdg(qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5894-L5905)

Apply [`SdgGate`](/docs/api/qiskit/qiskit.circuit.library.SdgGate "qiskit.circuit.library.SdgGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

**qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### store

`store(lvalue, rvalue, /)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4462-L4491)

Store the result of the given real-time classical expression `rvalue` in the memory location defined by `lvalue`.

Typically `lvalue` will be a [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") node and `rvalue` will be some [`Expr`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Expr "qiskit.circuit.classical.expr.Expr") to write into it, but anything that [`expr.lift()`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.lift "qiskit.circuit.classical.expr.lift") can raise to an [`Expr`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Expr "qiskit.circuit.classical.expr.Expr") is permissible in both places, and it will be called on them.

**Parameters**

- **lvalue** ([*Any*](https://docs.python.org/3/library/typing.html#typing.Any)) – a valid specifier for a memory location in the circuit. This will typically be a [`Var`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var") node, but you can also write to [`Clbit`](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit") or [`ClassicalRegister`](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister") memory locations if your hardware supports it. The memory location must already be present in the circuit.
- **rvalue** ([*Any*](https://docs.python.org/3/library/typing.html#typing.Any)) – a real-time classical expression whose result should be written into the given memory location.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

> **See also**
>
> **[`Store`](/docs/api/qiskit/circuit#qiskit.circuit.Store "qiskit.circuit.Store")**
>
> The backing [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction") class that represents this operation.
>
> **[`add_var()`](#qiskit.circuit.QuantumCircuit.add_var "qiskit.circuit.QuantumCircuit.add_var")**
>
> Create a new variable in the circuit that can be written to with this method.

#### swap

`swap(qubit1, qubit2)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5981-L5997)

Apply [`SwapGate`](/docs/api/qiskit/qiskit.circuit.library.SwapGate "qiskit.circuit.library.SwapGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **qubit1** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The first qubit to apply the gate to.
- **qubit2** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The second qubit to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### sx

`sx(qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6055-L6066)

Apply [`SXGate`](/docs/api/qiskit/qiskit.circuit.library.SXGate "qiskit.circuit.library.SXGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

**qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### sxdg

`sxdg(qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6068-L6079)

Apply [`SXdgGate`](/docs/api/qiskit/qiskit.circuit.library.SXdgGate "qiskit.circuit.library.SXdgGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

**qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### t

`t(qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6118-L6129)

Apply [`TGate`](/docs/api/qiskit/qiskit.circuit.library.TGate "qiskit.circuit.library.TGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

**qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### tdg

`tdg(qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6131-L6142)

Apply [`TdgGate`](/docs/api/qiskit/qiskit.circuit.library.TdgGate "qiskit.circuit.library.TdgGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

**qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### u

`u(theta, phi, lam, qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6144-L6164)

Apply [`UGate`](/docs/api/qiskit/qiskit.circuit.library.UGate "qiskit.circuit.library.UGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **theta** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The $\theta$ rotation angle of the gate.
- **phi** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The $\phi$ rotation angle of the gate.
- **lam** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)) – The $\lambda$ rotation angle of the gate.
- **qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### unitary

`unitary(obj, qubits, label=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6831-L6874)

Apply unitary gate specified by `obj` to `qubits`.

**Parameters**

- **obj** (*np.ndarray |* [*Gate*](/docs/api/qiskit/qiskit.circuit.Gate "qiskit.circuit.Gate") *| BaseOperator*) – Unitary operator.
- **qubits** (*Sequence\[QubitSpecifier]*) – The circuit qubits to apply the transformation to.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – Unitary name for backend \[Default: None].

**Returns**

The quantum circuit.

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

**Example**

Apply a gate specified by a unitary matrix to a quantum circuit

```python
from qiskit import QuantumCircuit
matrix = [[0, 0, 0, 1],
        [0, 0, 1, 0],
        [1, 0, 0, 0],
        [0, 1, 0, 0]]
circuit = QuantumCircuit(2)
circuit.unitary(matrix, [0, 1])
```

#### x

`x(qubit, label=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6214-L6226)

Apply [`XGate`](/docs/api/qiskit/qiskit.circuit.library.XGate "qiskit.circuit.library.XGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

- **qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the gate in the circuit.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### y

`y(qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6430-L6441)

Apply [`YGate`](/docs/api/qiskit/qiskit.circuit.library.YGate "qiskit.circuit.library.YGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

**qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### z

`z(qubit)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6483-L6494)

Apply [`ZGate`](/docs/api/qiskit/qiskit.circuit.library.ZGate "qiskit.circuit.library.ZGate").

For the full matrix form of this gate, see the underlying gate documentation.

**Parameters**

**qubit** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The qubit(s) to apply the gate to.

**Returns**

A handle to the instructions created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

### Adding control flow to circuits

> **See also**
>
> [Control flow in circuits](/docs/api/qiskit/circuit#circuit-control-flow-repr)
>
> Discussion of how control-flow operations are represented in the whole [`qiskit.circuit`](/docs/api/qiskit/circuit#module-qiskit.circuit "qiskit.circuit") context.

| [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") method                       | Control-flow instruction                                                                                             |
| --------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| [`if_test()`](#qiskit.circuit.QuantumCircuit.if_test "qiskit.circuit.QuantumCircuit.if_test")                   | [`IfElseOp`](/docs/api/qiskit/qiskit.circuit.IfElseOp "qiskit.circuit.IfElseOp") with only a `True` body             |
| [`if_else()`](#qiskit.circuit.QuantumCircuit.if_else "qiskit.circuit.QuantumCircuit.if_else")                   | [`IfElseOp`](/docs/api/qiskit/qiskit.circuit.IfElseOp "qiskit.circuit.IfElseOp") with both `True` and `False` bodies |
| [`while_loop()`](#qiskit.circuit.QuantumCircuit.while_loop "qiskit.circuit.QuantumCircuit.while_loop")          | [`WhileLoopOp`](/docs/api/qiskit/qiskit.circuit.WhileLoopOp "qiskit.circuit.WhileLoopOp")                            |
| [`switch()`](#qiskit.circuit.QuantumCircuit.switch "qiskit.circuit.QuantumCircuit.switch")                      | [`SwitchCaseOp`](/docs/api/qiskit/qiskit.circuit.SwitchCaseOp "qiskit.circuit.SwitchCaseOp")                         |
| [`for_loop()`](#qiskit.circuit.QuantumCircuit.for_loop "qiskit.circuit.QuantumCircuit.for_loop")                | [`ForLoopOp`](/docs/api/qiskit/qiskit.circuit.ForLoopOp "qiskit.circuit.ForLoopOp")                                  |
| [`box()`](#qiskit.circuit.QuantumCircuit.box "qiskit.circuit.QuantumCircuit.box")                               | [`BoxOp`](/docs/api/qiskit/qiskit.circuit.BoxOp "qiskit.circuit.BoxOp")                                              |
| [`break_loop()`](#qiskit.circuit.QuantumCircuit.break_loop "qiskit.circuit.QuantumCircuit.break_loop")          | [`BreakLoopOp`](/docs/api/qiskit/qiskit.circuit.BreakLoopOp "qiskit.circuit.BreakLoopOp")                            |
| [`continue_loop()`](#qiskit.circuit.QuantumCircuit.continue_loop "qiskit.circuit.QuantumCircuit.continue_loop") | [`ContinueLoopOp`](/docs/api/qiskit/qiskit.circuit.ContinueLoopOp "qiskit.circuit.ContinueLoopOp")                   |

[`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") has corresponding methods for all of the control-flow operations that are supported by Qiskit. These have two forms for calling them. The first is a very straightforward convenience wrapper that takes in the block bodies of the instructions as [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") arguments, and simply constructs and appends the corresponding [`ControlFlowOp`](/docs/api/qiskit/qiskit.circuit.ControlFlowOp "qiskit.circuit.ControlFlowOp").

The second form, which we strongly recommend you use for constructing control flow, is called *the builder interface*. Here, the methods take only the real-time discriminant of the operation, and return [context managers](https://docs.python.org/3/library/stdtypes.html#typecontextmanager) that you enter using `with`. You can then use regular [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") methods within those blocks to build up the control-flow bodies, and Qiskit will automatically track which of the data resources are needed for the inner blocks, building the complete [`ControlFlowOp`](/docs/api/qiskit/qiskit.circuit.ControlFlowOp "qiskit.circuit.ControlFlowOp") as you leave the `with` statement. It is far simpler and less error-prone to build control flow programmatically this way.

When using the control-flow builder interface, you may sometimes want a qubit to be included in a block, even though it has no operations defined. In this case, you can use the [`noop()`](#qiskit.circuit.QuantumCircuit.noop "qiskit.circuit.QuantumCircuit.noop") method.

To check whether a circuit contains a [`ControlFlowOp`](/docs/api/qiskit/qiskit.circuit.ControlFlowOp "qiskit.circuit.ControlFlowOp") you can use the helper method [`QuantumCircuit.has_control_flow_op()`](#qiskit.circuit.QuantumCircuit.has_control_flow_op "qiskit.circuit.QuantumCircuit.has_control_flow_op").

#### box

`box(body_or_annotations=Ellipsis, /, qubits=None, clbits=None, *, label=None, duration=None, unit=None, annotations=Ellipsis)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6990-L7106)

Create a `box` of operations on this circuit that are treated atomically in the greater context.

A “box” is a control-flow construct that is entered unconditionally. The contents of the box behave somewhat as if the start and end of the box were barriers (see [`barrier()`](#qiskit.circuit.QuantumCircuit.barrier "qiskit.circuit.QuantumCircuit.barrier")), except it is permissible to commute operations “all the way” through the box. The box is also an explicit scope for the purposes of variables, stretches and compiler passes.

There are two forms for calling this function:

- Pass a [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") positionally, and the `qubits` and `clbits` it acts on. In this form, a [`BoxOp`](/docs/api/qiskit/qiskit.circuit.BoxOp "qiskit.circuit.BoxOp") is immediately created and appended using the circuit as the body.
- Use in a `with` statement with no `body`, `qubits` or `clbits`. This is the “builder-interface form”, where you then use other [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") methods within the Python `with` scope to add instructions to the `box`. This is the preferred form, and much less error prone.

**Examples**

Using the builder interface to add two boxes in sequence. The two boxes in this circuit can execute concurrently, and the second explicitly inserts a data-flow dependency on qubit 8 for the duration of the box, even though the qubit is idle.

```python
from qiskit.circuit import QuantumCircuit, Annotation

class MyAnnotation(Annotation):
    namespace = "my.namespace"

qc = QuantumCircuit(9)
with qc.box():
    qc.cz(0, 1)
    qc.cz(2, 3)
with qc.box([MyAnnotation()]):
    qc.cz(4, 5)
    qc.cz(6, 7)
    qc.noop(8)
```

Using the explicit construction of box. This creates the same circuit as above, and should give an indication why the previous form is preferred for interactive use.

```python
from qiskit.circuit import QuantumCircuit, BoxOp

body_0 = QuantumCircuit(4)
body_0.cz(0, 1)
body_0.cz(2, 3)

# Note that the qubit indices inside a body related only to the body.  The
# association with qubits in the containing circuit is made by the ``qubits``
# argument to `QuantumCircuit.box`.
body_1 = QuantumCircuit(5)
body_1.cz(0, 1)
body_1.cz(2, 3)

qc = QuantumCircuit(9)
qc.box(body_0, [0, 1, 2, 3], [])
qc.box(body_1, [4, 5, 6, 7, 8], [])
```

**Parameters**

- **body\_or\_annotations** ([*QuantumCircuit*](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")  *|*[*Iterable*](https://docs.python.org/3/library/typing.html#typing.Iterable)*\[*[*Annotation*](/docs/api/qiskit/qiskit.circuit.Annotation "qiskit.circuit.Annotation")*]*) – the first positional argument is unnamed. If a [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") is passed positionally, it is immediately used as the body of the box, and `qubits` and `clbits` must also be specified. If not given, or if given an iterable of [`Annotation`](/docs/api/qiskit/qiskit.circuit.Annotation "qiskit.circuit.Annotation") objects, the context-manager form of this method is triggered.
- **qubits** (*Sequence\[QubitSpecifier] | None*) – the qubits to apply the [`BoxOp`](/docs/api/qiskit/qiskit.circuit.BoxOp "qiskit.circuit.BoxOp") to, in the explicit form.
- **clbits** (*Sequence\[ClbitSpecifier] | None*) – the clbits to apply the [`BoxOp`](/docs/api/qiskit/qiskit.circuit.BoxOp "qiskit.circuit.BoxOp") to, in the explicit form.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – an optional string label for the instruction.
- **duration** (*None*) – an optional explicit duration for the [`BoxOp`](/docs/api/qiskit/qiskit.circuit.BoxOp "qiskit.circuit.BoxOp"). Scheduling passes are constrained to schedule the contained scope to match a given duration, including delay insertion if required.
- **unit** (*Literal\['dt', 's', 'ms', 'us', 'ns', 'ps', 'expr'] | None*) – the unit of the `duration`.
- **annotations** ([*Iterable*](https://docs.python.org/3/library/typing.html#typing.Iterable)*\[*[*Annotation*](/docs/api/qiskit/qiskit.circuit.Annotation "qiskit.circuit.Annotation")*]*) – any [`Annotation`](/docs/api/qiskit/qiskit.circuit.Annotation "qiskit.circuit.Annotation") objects the box should have. When this method is used in context-manager form, this argument can instead be passed as the only positional argument.

#### break\_loop

`break_loop()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L7542-L7569)

Apply [`BreakLoopOp`](/docs/api/qiskit/qiskit.circuit.BreakLoopOp "qiskit.circuit.BreakLoopOp").

> **Warning**
>
> If you are using the context-manager “builder” forms of [`if_test()`](#qiskit.circuit.QuantumCircuit.if_test "qiskit.circuit.QuantumCircuit.if_test"), [`for_loop()`](#qiskit.circuit.QuantumCircuit.for_loop "qiskit.circuit.QuantumCircuit.for_loop") or [`while_loop()`](#qiskit.circuit.QuantumCircuit.while_loop "qiskit.circuit.QuantumCircuit.while_loop"), you can only call this method if you are within a loop context, because otherwise the “resource width” of the operation cannot be determined. This would quickly lead to invalid circuits, and so if you are trying to construct a reusable loop body (without the context managers), you must also use the non-context-manager form of [`if_test()`](#qiskit.circuit.QuantumCircuit.if_test "qiskit.circuit.QuantumCircuit.if_test") and [`if_else()`](#qiskit.circuit.QuantumCircuit.if_else "qiskit.circuit.QuantumCircuit.if_else"). Take care that the [`BreakLoopOp`](/docs/api/qiskit/qiskit.circuit.BreakLoopOp "qiskit.circuit.BreakLoopOp") instruction must span all the resources of its containing loop, not just the immediate scope.

**Returns**

A handle to the instruction created.

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if this method was called within a builder context, but not contained within a loop.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### continue\_loop

`continue_loop()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L7571-L7598)

Apply [`ContinueLoopOp`](/docs/api/qiskit/qiskit.circuit.ContinueLoopOp "qiskit.circuit.ContinueLoopOp").

> **Warning**
>
> If you are using the context-manager “builder” forms of [`if_test()`](#qiskit.circuit.QuantumCircuit.if_test "qiskit.circuit.QuantumCircuit.if_test"), [`for_loop()`](#qiskit.circuit.QuantumCircuit.for_loop "qiskit.circuit.QuantumCircuit.for_loop") or [`while_loop()`](#qiskit.circuit.QuantumCircuit.while_loop "qiskit.circuit.QuantumCircuit.while_loop"), you can only call this method if you are within a loop context, because otherwise the “resource width” of the operation cannot be determined. This would quickly lead to invalid circuits, and so if you are trying to construct a reusable loop body (without the context managers), you must also use the non-context-manager form of [`if_test()`](#qiskit.circuit.QuantumCircuit.if_test "qiskit.circuit.QuantumCircuit.if_test") and [`if_else()`](#qiskit.circuit.QuantumCircuit.if_else "qiskit.circuit.QuantumCircuit.if_else"). Take care that the [`ContinueLoopOp`](/docs/api/qiskit/qiskit.circuit.ContinueLoopOp "qiskit.circuit.ContinueLoopOp") instruction must span all the resources of its containing loop, not just the immediate scope.

**Returns**

A handle to the instruction created.

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if this method was called within a builder context, but not contained within a loop.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### for\_loop

`for_loop(indexset: Iterable[int], loop_parameter: Parameter | Var | None, body: None, qubits: None, clbits: None, *, label: str | None) → ForLoopContext`

`for_loop(indexset: Iterable[int], loop_parameter: Parameter | Var | None, body: QuantumCircuit, qubits: Sequence[Qubit | QuantumRegister | int | slice | Sequence[Qubit | int]], clbits: Sequence[Clbit | ClassicalRegister | int | slice | Sequence[Clbit | int]], *, label: str | None) → InstructionSet`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L7217-L7290)

Create a `for` loop on this circuit.

There are two forms for calling this function. If called with all its arguments (with the possible exception of `label`), it will create a [`ForLoopOp`](/docs/api/qiskit/qiskit.circuit.ForLoopOp "qiskit.circuit.ForLoopOp") with the given `body`. If `body` (and `qubits` and `clbits`) are *not* passed, then this acts as a context manager, which, when entered, provides a loop variable (unless one is given, in which case it will be reused) and will automatically build a [`ForLoopOp`](/docs/api/qiskit/qiskit.circuit.ForLoopOp "qiskit.circuit.ForLoopOp") when the scope finishes. In this form, you do not need to keep track of the qubits or clbits you are using, because the scope will handle it for you.

For example:

```python
from qiskit import QuantumCircuit
qc = QuantumCircuit(2, 1)

with qc.for_loop(range(5)) as i:
    qc.h(0)
    qc.cx(0, 1)
    qc.measure(0, 0)
    with qc.if_test((0, True)):
        qc.break_loop()
```

**Parameters**

- **indexset** (*Iterable\[*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – A collection of integers to loop over. Always necessary.

- **loop\_parameter** (*Optional\[*[*Parameter*](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit.circuit.Parameter")*|*[*expr.Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var")*]*) –

  The parameter used within `body` to which the values from `indexset` will be assigned. In the context-manager form, if this argument is not supplied, then a loop parameter will be allocated for you and returned as the value of the `with` statement. This will only be bound into the circuit if it is used within the body.

  If this argument is `None` in the manual form of this method, `body` will be repeated once for each of the items in `indexset` but their values will be ignored.

- **body** (*Optional\[*[*QuantumCircuit*](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")*]*) – The loop body to be repeatedly executed. Omit this to use the context-manager mode.

- **qubits** (*Optional\[Sequence\[QubitSpecifier]]*) – The circuit qubits over which the loop body should be run. Omit this to use the context-manager mode.

- **clbits** (*Optional\[Sequence\[ClbitSpecifier]]*) – The circuit clbits over which the loop body should be run. Omit this to use the context-manager mode.

- **label** (*Optional\[*[*str*](https://docs.python.org/3/library/stdtypes.html#str)*]*) – The string label of the instruction in the circuit.

**Returns**

depending on the call signature, either a context manager for creating the for loop (it will automatically be added to the circuit at the end of the block), or an [`InstructionSet`](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.InstructionSet") handle to the appended loop operation.

**Return type**

[InstructionSet](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.InstructionSet") or ForLoopContext

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if an incorrect calling convention is used.

#### if\_else

`if_else(condition, true_body, false_body, qubits, clbits, label=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L7394-L7449)

Apply [`IfElseOp`](/docs/api/qiskit/qiskit.circuit.IfElseOp "qiskit.circuit.IfElseOp").

> **Note**
>
> This method does not have an associated context-manager form, because it is already handled by the [`if_test()`](#qiskit.circuit.QuantumCircuit.if_test "qiskit.circuit.QuantumCircuit.if_test") method. You can use the `else` part of that with something such as:
>
> ```python
> from qiskit.circuit import QuantumCircuit, Qubit, Clbit
> bits = [Qubit(), Qubit(), Clbit()]
> qc = QuantumCircuit(bits)
> qc.h(0)
> qc.cx(0, 1)
> qc.measure(0, 0)
> with qc.if_test((bits[2], 0)) as else_:
>     qc.h(0)
> with else_:
>     qc.x(0)
> ```

**Parameters**

- **condition** ([*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)*\[*[*ClassicalRegister*](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister")*,* [*int*](https://docs.python.org/3/library/functions.html#int)*] |* [*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)*\[*[*Clbit*](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")*,* [*int*](https://docs.python.org/3/library/functions.html#int)*] |* [*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)*\[*[*Clbit*](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")*,* [*bool*](https://docs.python.org/3/library/functions.html#bool)*]*) – A condition to be evaluated in real time at circuit execution, which, if true, will trigger the evaluation of `true_body`. Can be specified as either a tuple of a `ClassicalRegister` to be tested for equality with a given `int`, or as a tuple of a `Clbit` to be compared to either a `bool` or an `int`.
- **true\_body** ([*QuantumCircuit*](#qiskit.circuit.QuantumCircuit "qiskit.circuit.quantumcircuit.QuantumCircuit")) – The circuit body to be run if `condition` is true.
- **false\_body** ([*QuantumCircuit*](#qiskit.circuit.QuantumCircuit "qiskit.circuit.quantumcircuit.QuantumCircuit")) – The circuit to be run if `condition` is false.
- **qubits** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]]*) – The circuit qubits over which the if/else should be run.
- **clbits** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Clbit*](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")  *|*[*ClassicalRegister*](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Clbit*](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]]*) – The circuit clbits over which the if/else should be run.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The string label of the instruction in the circuit.

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – If the provided condition references Clbits outside the enclosing circuit.

**Returns**

A handle to the instruction created.

**Return type**

[*InstructionSet*](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.instructionset.InstructionSet")

#### if\_test

`if_test(condition: tuple[ClassicalRegister | Clbit, int]) → IfContext`

`if_test(condition: tuple[ClassicalRegister | Clbit, int], true_body: QuantumCircuit, qubits: Sequence[Qubit | QuantumRegister | int | slice | Sequence[Qubit | int]], clbits: Sequence[Clbit | ClassicalRegister | int | slice | Sequence[Clbit | int]], *, label: str | None = None) → InstructionSet`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L7306-L7392)

Create an `if` statement on this circuit.

There are two forms for calling this function. If called with all its arguments (with the possible exception of `label`), it will create a [`IfElseOp`](/docs/api/qiskit/qiskit.circuit.IfElseOp "qiskit.circuit.IfElseOp") with the given `true_body`, and there will be no branch for the `false` condition (see also the [`if_else()`](#qiskit.circuit.QuantumCircuit.if_else "qiskit.circuit.QuantumCircuit.if_else") method). However, if `true_body` (and `qubits` and `clbits`) are *not* passed, then this acts as a context manager, which can be used to build `if` statements. The return value of the `with` statement is a chainable context manager, which can be used to create subsequent `else` blocks. In this form, you do not need to keep track of the qubits or clbits you are using, because the scope will handle it for you.

For example:

```python
from qiskit.circuit import QuantumCircuit, Qubit, Clbit
bits = [Qubit(), Qubit(), Qubit(), Clbit(), Clbit()]
qc = QuantumCircuit(bits)

qc.h(0)
qc.cx(0, 1)
qc.measure(0, 0)
qc.h(0)
qc.cx(0, 1)
qc.measure(0, 1)

with qc.if_test((bits[3], 0)) as else_:
    qc.x(2)
with else_:
    qc.h(2)
    qc.z(2)
```

**Parameters**

- **condition** (*Tuple\[Union\[*[*ClassicalRegister*](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister")*,* [*Clbit*](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")*],* [*int*](https://docs.python.org/3/library/functions.html#int)*]*) – A condition to be evaluated in real time during circuit execution, which, if true, will trigger the evaluation of `true_body`. Can be specified as either a tuple of a `ClassicalRegister` to be tested for equality with a given `int`, or as a tuple of a `Clbit` to be compared to either a `bool` or an `int`.
- **true\_body** (*Optional\[*[*QuantumCircuit*](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")*]*) – The circuit body to be run if `condition` is true.
- **qubits** (*Optional\[Sequence\[QubitSpecifier]]*) – The circuit qubits over which the if/else should be run.
- **clbits** (*Optional\[Sequence\[ClbitSpecifier]]*) – The circuit clbits over which the if/else should be run.
- **label** (*Optional\[*[*str*](https://docs.python.org/3/library/stdtypes.html#str)*]*) – The string label of the instruction in the circuit.

**Returns**

depending on the call signature, either a context manager for creating the `if` block (it will automatically be added to the circuit at the end of the block), or an [`InstructionSet`](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.InstructionSet") handle to the appended conditional operation.

**Return type**

[InstructionSet](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.InstructionSet") or IfContext

**Raises**

- [**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – If the provided condition references Clbits outside the enclosing circuit.
- [**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if an incorrect calling convention is used.

**Returns**

A handle to the instruction created.

#### switch

`switch(target: Clbit | ClassicalRegister | int | slice | Sequence[Clbit | int], cases: None, qubits: None, clbits: None, *, label: str | None) → SwitchContext`

`switch(target: Clbit | ClassicalRegister | int | slice | Sequence[Clbit | int], cases: Iterable[tuple[Any, QuantumCircuit]], qubits: Sequence[Qubit | QuantumRegister | int | slice | Sequence[Qubit | int]], clbits: Sequence[Clbit | ClassicalRegister | int | slice | Sequence[Clbit | int]], *, label: str | None) → InstructionSet`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L7473-L7540)

Create a `switch`/`case` structure on this circuit.

There are two forms for calling this function. If called with all its arguments (with the possible exception of `label`), it will create a [`SwitchCaseOp`](/docs/api/qiskit/qiskit.circuit.SwitchCaseOp "qiskit.circuit.SwitchCaseOp") with the given case structure. If `cases` (and `qubits` and `clbits`) are *not* passed, then this acts as a context manager, which will automatically build a [`SwitchCaseOp`](/docs/api/qiskit/qiskit.circuit.SwitchCaseOp "qiskit.circuit.SwitchCaseOp") when the scope finishes. In this form, you do not need to keep track of the qubits or clbits you are using, because the scope will handle it for you.

Example usage:

```python
from qiskit.circuit import QuantumCircuit, ClassicalRegister, QuantumRegister
qreg = QuantumRegister(3)
creg = ClassicalRegister(3)
qc = QuantumCircuit(qreg, creg)
qc.h([0, 1, 2])
qc.measure([0, 1, 2], [0, 1, 2])

with qc.switch(creg) as case:
    with case(0):
        qc.x(0)
    with case(1, 2):
        qc.z(1)
    with case(case.DEFAULT):
        qc.cx(0, 1)
```

**Parameters**

- **target** (*Union\[*[*ClassicalRegister*](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister")*,* [*Clbit*](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")*]*) – The classical value to switch one. This must be integer-like.
- **cases** (*Iterable\[Tuple\[*[*Any*](https://docs.python.org/3/library/typing.html#typing.Any)*,* [*QuantumCircuit*](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")*]]*) – A sequence of case specifiers. Each tuple defines one case body (the second item). The first item of the tuple can be either a single integer value, the special value [`CASE_DEFAULT`](/docs/api/qiskit/circuit#qiskit.circuit.CASE_DEFAULT "qiskit.circuit.CASE_DEFAULT"), or a tuple of several integer values. Each of the integer values will be tried in turn; control will then pass to the body corresponding to the first match. [`CASE_DEFAULT`](/docs/api/qiskit/circuit#qiskit.circuit.CASE_DEFAULT "qiskit.circuit.CASE_DEFAULT") matches all possible values. Omit in context-manager form.
- **qubits** (*Sequence\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")*]*) – The circuit qubits over which all case bodies execute. Omit in context-manager form.
- **clbits** (*Sequence\[*[*Clbit*](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")*]*) – The circuit clbits over which all case bodies execute. Omit in context-manager form.
- **label** (*Optional\[*[*str*](https://docs.python.org/3/library/stdtypes.html#str)*]*) – The string label of the instruction in the circuit.

**Returns**

If used in context-manager mode, then this should be used as a `with` resource, which will return an object that can be repeatedly entered to produce cases for the switch statement. If the full form is used, then this returns a handle to the instructions created.

**Return type**

[InstructionSet](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.InstructionSet") or SwitchCaseContext

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if an incorrect calling convention is used.

#### while\_loop

`while_loop(condition: tuple[ClassicalRegister | Clbit, int] | Expr, body: None, qubits: None, clbits: None, *, label: str | None) → WhileLoopContext`

`while_loop(condition: tuple[ClassicalRegister | Clbit, int] | Expr, body: QuantumCircuit, qubits: Sequence[Qubit | QuantumRegister | int | slice | Sequence[Qubit | int]], clbits: Sequence[Clbit | ClassicalRegister | int | slice | Sequence[Clbit | int]], *, label: str | None) → InstructionSet`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L7130-L7191)

Create a `while` loop on this circuit.

There are two forms for calling this function. If called with all its arguments (with the possible exception of `label`), it will create a `WhileLoopOp` with the given `body`. If `body` (and `qubits` and `clbits`) are *not* passed, then this acts as a context manager, which will automatically build a `WhileLoopOp` when the scope finishes. In this form, you do not need to keep track of the qubits or clbits you are using, because the scope will handle it for you.

Example usage:

```python
from qiskit.circuit import QuantumCircuit, Clbit, Qubit
bits = [Qubit(), Qubit(), Clbit()]
qc = QuantumCircuit(bits)

with qc.while_loop((bits[2], 0)):
    qc.h(0)
    qc.cx(0, 1)
    qc.measure(0, 0)
```

**Parameters**

- **condition** (*Tuple\[Union\[*[*ClassicalRegister*](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister")*,* [*Clbit*](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")*],* [*int*](https://docs.python.org/3/library/functions.html#int)*]*) – An equality condition to be checked prior to executing `body`. The left-hand side of the condition must be a [`ClassicalRegister`](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister") or a [`Clbit`](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit"), and the right-hand side must be an integer or boolean.
- **body** (*Optional\[*[*QuantumCircuit*](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")*]*) – The loop body to be repeatedly executed. Omit this to use the context-manager mode.
- **qubits** (*Optional\[Sequence\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")*]]*) – The circuit qubits over which the loop body should be run. Omit this to use the context-manager mode.
- **clbits** (*Optional\[Sequence\[*[*Clbit*](/docs/api/qiskit/circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")*]]*) – The circuit clbits over which the loop body should be run. Omit this to use the context-manager mode.
- **label** (*Optional\[*[*str*](https://docs.python.org/3/library/stdtypes.html#str)*]*) – The string label of the instruction in the circuit.

**Returns**

If used in context-manager mode, then this should be used as a `with` resource, which will infer the block content and operands on exit. If the full form is used, then this returns a handle to the instructions created.

**Return type**

[InstructionSet](/docs/api/qiskit/qiskit.circuit.InstructionSet "qiskit.circuit.InstructionSet") or WhileLoopContext

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if an incorrect calling convention is used.

#### noop

`noop(*qargs)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L6876-L6910)

Mark the given qubit(s) as used within the current scope, without adding an operation.

This has no effect (other than raising an exception on invalid input) when called in the top scope of a [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit"). Within a control-flow builder, this causes the qubit to be “used” by the control-flow block, if it wouldn’t already be used, without adding any additional operations on it.

For example:

```python
from qiskit.circuit import QuantumCircuit

qc = QuantumCircuit(3)
with qc.box():
    # This control-flow block will only use qubits 0 and 1.
    qc.cx(0, 1)
with qc.box():
    # This control-flow block will contain only the same operation as the previous
    # block, but it will also mark qubit 2 as "used" by the box.
    qc.cx(0, 1)
    qc.noop(2)
```

**Parameters**

**\*qargs** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*QuantumRegister*](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*slice*](https://docs.python.org/3/library/functions.html#slice)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – variadic list of valid qubit specifiers. Anything that can be passed as a qubit or collection of qubits is valid for each argument here.

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if any requested qubit is not valid for the circuit.

#### has\_control\_flow\_op

`has_control_flow_op()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L5076-L5079)

Checks whether the circuit has an instance of [`ControlFlowOp`](/docs/api/qiskit/qiskit.circuit.ControlFlowOp "qiskit.circuit.ControlFlowOp") present amongst its operations.

**Return type**

[bool](https://docs.python.org/3/library/functions.html#bool)

### Converting circuits to other objects

As discussed in [Methods to add general operations](#circuit-append-compose), you can convert a circuit to either an [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction") or a [`Gate`](/docs/api/qiskit/qiskit.circuit.Gate "qiskit.circuit.Gate") using two helper methods.

#### to\_instruction

`to_instruction(parameter_map=None, label=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3773-L3798)

Create an [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction") out of this circuit.

> **See also**
>
> **`circuit_to_instruction()`**
>
> The underlying driver of this method.

**Parameters**

- **parameter\_map** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\[*[*Parameter*](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit._accelerate.circuit.Parameter")*,* [*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)*] | None*) – For parameterized circuits, a mapping from parameters in the circuit to parameters to be used in the instruction. If None, existing circuit parameters will also parameterize the instruction.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – Optional gate label.

**Returns**

**a composite instruction encapsulating this circuit (can be**

decomposed back).

**Return type**

[qiskit.circuit.Instruction](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction")

#### to\_gate

`to_gate(parameter_map=None, label=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3800-L3824)

Create a [`Gate`](/docs/api/qiskit/qiskit.circuit.Gate "qiskit.circuit.Gate") out of this circuit. The circuit must act only on qubits and contain only unitary operations.

> **See also**
>
> **`circuit_to_gate()`**
>
> The underlying driver of this method.

**Parameters**

- **parameter\_map** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\[*[*Parameter*](/docs/api/qiskit/qiskit.circuit.Parameter "qiskit._accelerate.circuit.Parameter")*,* [*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float)*] | None*) – For parameterized circuits, a mapping from parameters in the circuit to parameters to be used in the gate. If `None`, existing circuit parameters will also parameterize the gate.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – Optional gate label.

**Returns**

a composite gate encapsulating this circuit (can be decomposed back).

**Return type**

[Gate](/docs/api/qiskit/qiskit.circuit.Gate "qiskit.circuit.Gate")

In addition, you can convert the entire circuit into the [`DAGCircuit`](/docs/api/qiskit/qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit") representation:

#### to\_dag

`to_dag(*, copy_operations=True)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3861-L3877)

Convert this circuit to a [`DAGCircuit`](/docs/api/qiskit/qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit").

This is a simple wrapper around [`circuit_to_dag()`](/docs/api/qiskit/converters#qiskit.converters.circuit_to_dag "qiskit.converters.circuit_to_dag").

**Parameters**

**copy\_operations** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – whether to deep copy the individual instructions. If set to `False`, the operation is cheaper but mutations to the instructions in the DAG will affect the original circuit.

**Returns**

a DAG representing this same circuit.

**Return type**

[qiskit.dagcircuit.DAGCircuit](/docs/api/qiskit/qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit")

### Helper mutation methods

There are two higher-level methods on [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") for appending measurements to the end of a circuit. Note that by default, these also add an extra register.

#### measure\_active

`measure_active(inplace=True)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4586-L4615)

Adds measurement to all non-idle qubits. Creates a new ClassicalRegister with a size equal to the number of non-idle qubits being measured.

Returns a new circuit with measurements if inplace=False.

**Parameters**

**inplace** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – All measurements inplace or return new circuit.

**Returns**

Returns circuit with measurements when `inplace = False`.

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

#### measure\_all

`measure_all(inplace=True, add_bits=True)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4617-L4658)

Adds measurement to all qubits.

By default, adds new classical bits in a [`ClassicalRegister`](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister") to store these measurements. If `add_bits=False`, the results of the measurements will instead be stored in the already existing classical bits, with qubit `n` being measured into classical bit `n`.

Returns a new circuit with measurements if `inplace=False`.

**Parameters**

- **inplace** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – All measurements inplace or return new circuit.
- **add\_bits** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – Whether to add new bits to store the results.

**Returns**

Returns circuit with measurements when `inplace=False`.

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if `add_bits=False` but there are not enough classical bits.

There are two “subtractive” methods on [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") as well. This is not a use-case that [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") is designed for; typically you should just look to use [`copy_empty_like()`](#qiskit.circuit.QuantumCircuit.copy_empty_like "qiskit.circuit.QuantumCircuit.copy_empty_like") in place of [`clear()`](#qiskit.circuit.QuantumCircuit.clear "qiskit.circuit.QuantumCircuit.clear"), and run [`remove_final_measurements()`](#qiskit.circuit.QuantumCircuit.remove_final_measurements "qiskit.circuit.QuantumCircuit.remove_final_measurements") as its transpiler-pass form [`RemoveFinalMeasurements`](/docs/api/qiskit/qiskit.transpiler.passes.RemoveFinalMeasurements "qiskit.transpiler.passes.RemoveFinalMeasurements").

#### clear

`clear()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4419-L4431)

Clear all instructions in self.

Clearing the circuits will keep the metadata.

> **See also**
>
> **[`copy_empty_like()`](#qiskit.circuit.QuantumCircuit.copy_empty_like "qiskit.circuit.QuantumCircuit.copy_empty_like")**
>
> A method to produce a new circuit with no instructions and all the same tracking of quantum and classical typed data, but without mutating the original circuit.

**Return type**

None

#### remove\_final\_measurements

`remove_final_measurements(inplace=True)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4660-L4747)

Removes final measurements and barriers on all qubits if they are present. Deletes the classical registers that were used to store the values from these measurements that become idle as a result of this operation, and deletes classical bits that are referenced only by removed registers, or that aren’t referenced at all but have become idle as a result of this operation.

Measurements and barriers are considered final if they are followed by no other operations (aside from other measurements or barriers.)

> **Note**
>
> This method has rather complex behavior, particularly around the removal of newly idle classical bits and registers. It is much more efficient to avoid adding unnecessary classical data in the first place, rather than trying to remove it later.

> **See also**
>
> **[`RemoveFinalMeasurements`](/docs/api/qiskit/qiskit.transpiler.passes.RemoveFinalMeasurements "qiskit.transpiler.passes.RemoveFinalMeasurements")**
>
> A transpiler pass that removes final measurements and barriers. This does not remove the classical data. If this is your goal, you can call that with:
>
> ```python
> from qiskit.circuit import QuantumCircuit
> from qiskit.transpiler.passes import RemoveFinalMeasurements
>
> qc = QuantumCircuit(2, 2)
> qc.h(0)
> qc.cx(0, 1)
> qc.barrier()
> qc.measure([0, 1], [0, 1])
>
> pass_ = RemoveFinalMeasurements()
> just_bell = pass_(qc)
> ```

**Parameters**

**inplace** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – All measurements removed inplace or return new circuit.

**Returns**

Returns the resulting circuit when `inplace=False`, else None.

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

## Circuit properties

### Simple circuit metrics

When constructing quantum circuits, there are several properties that help quantify the “size” of the circuits, and their ability to be run on a noisy quantum device. Some of these, like number of qubits, are straightforward to understand, while others like depth and number of tensor components require a bit more explanation. Here we will explain all of these properties, and, in preparation for understanding how circuits change when run on actual devices, highlight the conditions under which they change.

Consider the following circuit:

```python
from qiskit import QuantumCircuit
qc = QuantumCircuit(12)
for idx in range(5):
   qc.h(idx)
   qc.cx(idx, idx+5)

qc.cx(1, 7)
qc.x(8)
qc.cx(1, 9)
qc.x(7)
qc.cx(1, 11)
qc.swap(6, 11)
qc.swap(6, 9)
qc.swap(6, 10)
qc.x(6)
qc.draw('mpl')
```

![Circuit diagram output by the previous code.](https://eu-de.quantum.cloud.ibm.com/docs/images/api/qiskit/qiskit-circuit-QuantumCircuit-30.avif)

From the plot, it is easy to see that this circuit has 12 qubits, and a collection of Hadamard, CNOT, X, and SWAP gates. But how to quantify this programmatically? Because we can do single-qubit gates on all the qubits simultaneously, the number of qubits in this circuit is equal to the [`width()`](#qiskit.circuit.QuantumCircuit.width "qiskit.circuit.QuantumCircuit.width") of the circuit:

```python
assert qc.width() == 12
```

We can also just get the number of qubits directly using [`num_qubits`](#qiskit.circuit.QuantumCircuit.num_qubits "qiskit.circuit.QuantumCircuit.num_qubits"):

```python
assert qc.num_qubits == 12
```

> **Important**
>
> For a quantum circuit composed from just qubits, the circuit width is equal to the number of qubits. This is the definition used in quantum computing. However, for more complicated circuits with classical registers, and classically controlled gates, this equivalence breaks down. As such, from now on we will not refer to the number of qubits in a quantum circuit as the width.

It is also straightforward to get the number and type of the gates in a circuit using [`count_ops()`](#qiskit.circuit.QuantumCircuit.count_ops "qiskit.circuit.QuantumCircuit.count_ops"):

```python
qc.count_ops()
```

```text
OrderedDict([('cx', 8), ('h', 5), ('x', 3), ('swap', 3)])
```

We can also get just the raw count of operations by computing the circuits [`size()`](#qiskit.circuit.QuantumCircuit.size "qiskit.circuit.QuantumCircuit.size"):

```python
assert qc.size() == 19
```

#### count\_ops

`count_ops()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4234-L4241)

Count each operation kind in the circuit.

**Returns**

A breakdown of how many operations of each kind, sorted by amount.

**Return type**

[*OrderedDict*](https://docs.python.org/3/library/collections.html#collections.OrderedDict)\[[str](https://docs.python.org/3/library/stdtypes.html#str), [int](https://docs.python.org/3/library/functions.html#int)]

#### depth

`depth(filter_function=<function QuantumCircuit.<lambda>>)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4089-L4166)

Return circuit depth (i.e., length of critical path).

The depth of a quantum circuit is a measure of how many “layers” of quantum gates, executed in parallel, it takes to complete the computation defined by the circuit. Because quantum gates take time to implement, the depth of a circuit roughly corresponds to the amount of time it takes the quantum computer to execute the circuit.

> **Warning**
>
> This operation is not well defined if the circuit contains control-flow operations.

**Parameters**

**filter\_function** ([*Callable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)*\[\[*[*CircuitInstruction*](/docs/api/qiskit/qiskit.circuit.CircuitInstruction "qiskit._accelerate.circuit.CircuitInstruction")*],* [*bool*](https://docs.python.org/3/library/functions.html#bool)*]*) – A function to decide which instructions count to increase depth. Should take as a single positional input a [`CircuitInstruction`](/docs/api/qiskit/qiskit.circuit.CircuitInstruction "qiskit.circuit.CircuitInstruction"). Instructions for which the function returns `False` are ignored in the computation of the circuit depth. By default, filters out “directives”, such as [`Barrier`](/docs/api/qiskit/circuit#qiskit.circuit.Barrier "qiskit.circuit.Barrier").

**Returns**

Depth of circuit.

**Return type**

[int](https://docs.python.org/3/library/functions.html#int)

**Examples**

Simple calculation of total circuit depth:

```python
from qiskit.circuit import QuantumCircuit
qc = QuantumCircuit(4)
qc.h(0)
qc.cx(0, 1)
qc.h(2)
qc.cx(2, 3)
assert qc.depth() == 2
```

Modifying the previous example to only calculate the depth of multi-qubit gates:

```python
assert qc.depth(lambda instr: len(instr.qubits) > 1) == 1
```

#### get\_instructions

`get_instructions(name)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4250-L4259)

Get instructions matching name.

**Parameters**

**name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) – The name of instruction to get.

**Returns**

list of (instruction, qargs, cargs).

**Return type**

[list](https://docs.python.org/3/library/stdtypes.html#list)([tuple](https://docs.python.org/3/library/stdtypes.html#tuple))

#### num\_connected\_components

`num_connected_components(unitary_only=False)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4261-L4322)

How many non-entangled subcircuits can the circuit be factored to.

**Parameters**

**unitary\_only** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – Compute only unitary part of graph.

**Returns**

Number of connected components in circuit.

**Return type**

[int](https://docs.python.org/3/library/functions.html#int)

#### num\_nonlocal\_gates

`num_nonlocal_gates()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4243-L4248)

Return number of non-local gates (i.e. involving 2+ qubits).

Conditional nonlocal gates are also included.

**Return type**

[int](https://docs.python.org/3/library/functions.html#int)

#### num\_tensor\_factors

`num_tensor_factors()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4330-L4339)

Computes the number of tensor factors in the unitary (quantum) part of the circuit only.

**Notes**

This is here for backwards compatibility, and will be removed in a future release of Qiskit. You should call num\_unitary\_factors instead.

**Return type**

[int](https://docs.python.org/3/library/functions.html#int)

#### num\_unitary\_factors

`num_unitary_factors()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4324-L4328)

Computes the number of tensor factors in the unitary (quantum) part of the circuit only.

**Return type**

[int](https://docs.python.org/3/library/functions.html#int)

#### size

`size(filter_function=<function QuantumCircuit.<lambda>>)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4071-L4087)

Returns total number of instructions in circuit.

**Parameters**

**filter\_function** (*callable*) – a function to filter out some instructions. Should take as input a tuple of (Instruction, list(Qubit), list(Clbit)). By default, filters out “directives”, such as barrier or snapshot.

**Returns**

Total number of gate operations.

**Return type**

[int](https://docs.python.org/3/library/functions.html#int)

#### width

`width()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L4168-L4175)

Return number of qubits plus clbits in circuit.

**Returns**

Width of circuit.

**Return type**

[int](https://docs.python.org/3/library/functions.html#int)

### Accessing scheduling information

If a [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") has been scheduled as part of a transpilation pipeline, the timing information for individual qubits can be accessed. The whole-circuit timing information is available through the [`estimate_duration()`](#qiskit.circuit.QuantumCircuit.estimate_duration "qiskit.circuit.QuantumCircuit.estimate_duration") method and [`op_start_times`](#qiskit.circuit.QuantumCircuit.op_start_times "qiskit.circuit.QuantumCircuit.op_start_times") attribute.

#### estimate\_duration

`estimate_duration(target, unit='s')`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L7700-L7757)

Estimate the duration of a scheduled circuit

This method computes the estimate of the circuit duration by finding the longest duration path in the circuit based on the durations provided by a given target. This method only works for simple circuits that have no control flow or other classical feed-forward operations.

**Parameters**

- **target** ([*Target*](/docs/api/qiskit/qiskit.transpiler.Target "qiskit.transpiler.Target")) – The [`Target`](/docs/api/qiskit/qiskit.transpiler.Target "qiskit.transpiler.Target") instance that contains durations for the instructions if the target is missing duration data for any of the instructions in the circuit an [`QiskitError`](/docs/api/qiskit/exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") will be raised. This should be the same target object used as the target for transpilation.
- **unit** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) – The unit to return the duration in. This defaults to “s” for seconds but this can be a supported SI prefix for seconds returns. For example setting this to “n” will return in unit of nanoseconds. Supported values of this type are “f”, “p”, “n”, “u”, “µ”, “m”, “k”, “M”, “G”, “T”, and “P”. Additionally, a value of “dt” is also accepted to output an integer in units of “dt”. For this to function “dt” must be specified in the `target`.

**Returns**

The estimated duration for the execution of a single shot of the circuit in the specified unit.

**Raises**

[**QiskitError**](/docs/api/qiskit/exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – If the circuit is not scheduled or contains other details that prevent computing an estimated duration from (such as parameterized delay).

**Return type**

[int](https://docs.python.org/3/library/functions.html#int) | [float](https://docs.python.org/3/library/functions.html#float)

#### qubit\_duration

`qubit_duration(*qubits)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L7601-L7611)

Return the duration between the start and stop time of the first and last instructions, excluding delays, over the supplied qubits. Its time unit is `self.unit`.

**Parameters**

**\*qubits** ([*Qubit*](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit")  *|*[*int*](https://docs.python.org/3/library/functions.html#int)) – Qubits within `self` to include.

**Returns**

Return the duration between the first start and last stop time of non-delay instructions

**Return type**

[float](https://docs.python.org/3/library/functions.html#float)

#### qubit\_start\_time

`qubit_start_time(*qubits)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L7613-L7653)

Return the start time of the first instruction, excluding delays, over the supplied qubits. Its time unit is `self.unit`.

Return 0 if there are no instructions over qubits

**Parameters**

- **\*qubits** – Qubits within `self` to include. Integers are allowed for qubits, indicating
- **self.qubits.** (*indices of*)

**Returns**

Return the start time of the first instruction, excluding delays, over the qubits

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if `self` is a not-yet scheduled circuit.

**Return type**

[float](https://docs.python.org/3/library/functions.html#float)

#### qubit\_stop\_time

`qubit_stop_time(*qubits)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L7655-L7698)

Return the stop time of the last instruction, excluding delays, over the supplied qubits. Its time unit is `self.unit`.

Return 0 if there are no instructions over qubits

**Parameters**

- **\*qubits** – Qubits within `self` to include. Integers are allowed for qubits, indicating
- **self.qubits.** (*indices of*)

**Returns**

Return the stop time of the last instruction, excluding delays, over the qubits

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if `self` is a not-yet scheduled circuit.

**Return type**

[float](https://docs.python.org/3/library/functions.html#float)

## Abstract and physical circuits

Circuits are a fairly low-level abstraction of quantum algorithms. However, even within this, there are distinctions. Quantum programmers often want to use a wide array of gates and instructions, and work in a regime where all qubits and interact with all others. Quantum hardware, however, typically has a restrictive set of native gates, and only certain pairs of hardware qubits can interact. We term these two regimes “abstract circuits” and “physical circuits”, respectively.

Qiskit has two ways of distinguishing a circuit that is intended to be physical. This is a fuzzy check, for historical reasons; originally, Qiskit never made the distinction at all (which is why [`transpile()`](/docs/api/qiskit/compiler#qiskit.compiler.transpile "qiskit.compiler.transpile") is called that, and not called `compile`!). The most explicit way is through the [`layout`](#qiskit.circuit.QuantumCircuit.layout "qiskit.circuit.QuantumCircuit.layout") attribute of circuits; if this is set, the circuit is certainly intended to be physical. The older, more implicit, way is the metadata of the [`Qubit`](/docs/api/qiskit/circuit#qiskit.circuit.Qubit "qiskit.circuit.Qubit") objects and [`QuantumRegister`](/docs/api/qiskit/circuit#qiskit.circuit.QuantumRegister "qiskit.circuit.QuantumRegister") instances in the circuit. A circuit can only be considered (as judged by several transpiler passes) as physical if it contains exactly one quantum register, which is called `q` and owns all the circuit qubits in index order. Again for historical reasons, this is the default for the `QuantumCircuit(int [, int])` form of the default constructor.

Normally, you create a [`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") and build it in the abstract sense (regardless of the qubit metadata). You then call [`transpile()`](/docs/api/qiskit/compiler#qiskit.compiler.transpile "qiskit.compiler.transpile") to compile the circuit into a hardware-supported circuit. However, in cases where you want to write a hardware efficient circuit from the beginning, you can short-circuit the full compilation infrastructure using the [`ensure_physical()`](#qiskit.circuit.QuantumCircuit.ensure_physical "qiskit.circuit.QuantumCircuit.ensure_physical") method. This will ensure that, no matter how you defined the initial qubit metadata, all requirements for the circuit to be considered physical will be satisfied, with the qubit indices mapped to the hardware qubits.

For more complete control over choosing a virtual-to-physical mapping and routing, see [the layout](/docs/api/qiskit/transpiler#transpiler-preset-stage-layout) and routing \<transpiler-preset-stage-routing> stages of the preset compilation pipelines.

### ensure\_physical

`ensure_physical(num_qubits=None, *, apply_layout=True)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L1643-L1728)

Put this circuit into canonical physical form, with the given number of qubits, if it is not already.

Several Qiskit transpiler passes only make sense when applied to circuits defined in terms of physical qubits. If you have manually constructed a circuit where the qubit indices correspond to physical qubits, use this function to ensure that the metadata of the circuit matches the canonical physical form. This means replacing the qubit data with a single owning register called `"q"`, and (optionally) setting the [`layout`](#qiskit.circuit.QuantumCircuit.layout "qiskit.circuit.QuantumCircuit.layout") field of the circuit to link these physical qubits with the original virtual ones.

If the circuit does not already have a layout, this method (with `apply_layout=True`) is equivalent to applying the full [trivial layout method](/docs/api/qiskit/transpiler#transpiler-preset-stage-layout-trivial) of the preset compilation pipeline.

If the circuit is already canonically physical, nothing happens to it. This method cannot change the number of qubits in the circuit if it already has a [`layout`](#qiskit.circuit.QuantumCircuit.layout "qiskit.circuit.QuantumCircuit.layout") set.

**Parameters**

- **num\_qubits** ([*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – if given, expand the circuit with ancillas up to this size. The ancillas will always be the highest qubit indices of the circuit. If not given (the default), the circuit stays the same width. This option cannot be set if the circuit already as a [`layout`](#qiskit.circuit.QuantumCircuit.layout "qiskit.circuit.QuantumCircuit.layout").
- **apply\_layout** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – if true (the default), set the [`layout`](#qiskit.circuit.QuantumCircuit.layout "qiskit.circuit.QuantumCircuit.layout") attribute of the circuit appropriately so that the circuit appears to have been laid out with the “trivial” layout, including ancilla expansion, for a backend of width `num_qubits`. This has no effect if the circuit already had a [`layout`](#qiskit.circuit.QuantumCircuit.layout "qiskit.circuit.QuantumCircuit.layout").

**Returns**

whether the circuit was modified in order to make it physical.

**Raises**

- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – if `num_qubits` is too small for the circuit.
- [**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if `num_qubits` is set to attempt to expand the circuit, but the circuit already has a layout set.

**Return type**

[bool](https://docs.python.org/3/library/functions.html#bool)

### estimate\_fidelity

`estimate_fidelity(target)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L7759-L7794)

Estimate the fidelity of a physical circuit.

This function will compute the product of the error rates for each gate in the circuit to estimate the fidelity of the circuit:

**..math::**

**label**

estimated circuit fidelity

prod\_\{g in text\{gates}} bigl(1 - operatorname\{error}(g)bigr)

where $\operatorname{error}(g)$ is the error rate in the target for the instruction $g$ from the circuit in the target. If the circuit is not physical, meaning any instruction in the circuit (as in operation and qargs) is not found in the target, this will return `None`. This method is not intended to compute a realistic simulation of the fidelity of execution on real hardware. It is designed to provide an estimate of how the transpiler would work with the fidelity for various heuristics in its operation. It is typically only useful for comparing different compilation outputs against each other to estimate which one would produce a better quality execution on hardware.

**Parameters**

**target** ([*Target*](/docs/api/qiskit/qiskit.transpiler.Target "qiskit.transpiler.Target")) – The [`Target`](/docs/api/qiskit/qiskit.transpiler.Target "qiskit.transpiler.Target") instance that the circuit will be executed on and used to get the error rates for the instructions in the circuit.

**Returns**

The estimated fidelity of executing the circuit on the given target. If any instruction in the circuit is not present in target

**Raises**

[**QiskitError**](/docs/api/qiskit/exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – If the circuit contains any control flow operations.

**Return type**

[float](https://docs.python.org/3/library/functions.html#float) | None

## Instruction-like methods

[`QuantumCircuit`](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") also contains a small number of methods that are very [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction")-like in detail. You may well find better integration and more API support if you first convert your circuit to an [`Instruction`](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.Instruction") ([`to_instruction()`](#qiskit.circuit.QuantumCircuit.to_instruction "qiskit.circuit.QuantumCircuit.to_instruction")) or [`Gate`](/docs/api/qiskit/qiskit.circuit.Gate "qiskit.circuit.Gate") ([`to_gate()`](#qiskit.circuit.QuantumCircuit.to_gate "qiskit.circuit.QuantumCircuit.to_gate")) as appropriate, then call the corresponding method.

### control

`control(num_ctrl_qubits=1, label=None, ctrl_state=None, annotated=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L1973-L2035)

Return the controlled version of this circuit.

The original circuit is converted into a gate, and the resulting circuit contains the controlled version of this gate. This controlled gate is implemented as [`ControlledGate`](/docs/api/qiskit/qiskit.circuit.ControlledGate "qiskit.circuit.ControlledGate") when `annotated` is `False`, and as [`AnnotatedOperation`](/docs/api/qiskit/qiskit.circuit.AnnotatedOperation "qiskit.circuit.AnnotatedOperation") when `annotated` is `True`.

> **Deprecated since version 2.3**
>
> `qiskit.circuit.quantumcircuit.QuantumCircuit.control()`’s argument `annotated` is deprecated as of Qiskit 2.3. It will be removed in Qiskit 3.0. The method QuantumCircuit.control() no longer accepts annotated=None. The new default is annotated=True, which represents the controlled gate in the new quantum circuit as an AnnotatedOperation (unless a dedicated controlled-gate class already exists). You can explicitly set annotated=False to preserve the previous behavior. However, using annotated=True is recommended, as it defers construction of the controlled circuit to transpiler, and furthermore enables additional controlled-gate optimizations (typically leading to higher-quality circuits).

**Parameters**

- **num\_ctrl\_qubits** ([*int*](https://docs.python.org/3/library/functions.html#int)) – Number of controls to add. Defaults to `1`.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – An optional label to give the controlled gate for visualization. Defaults to `None`. Ignored if the controlled gate is implemented as an annotated operation.
- **ctrl\_state** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The control state of the gate, specified either as an integer or a bitstring (e.g. `"110"`). If `None`, defaults to the all-ones state `2**num_ctrl_qubits - 1`.
- **annotated** ([*bool*](https://docs.python.org/3/library/functions.html#bool) *| None*) – Indicates whether the controlled gate should be implemented as a controlled gate or as an annotated operation.

**Returns**

The controlled version of this circuit.

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – If the circuit contains a non-unitary operation and cannot be controlled.

### inverse

`inverse(annotated=False)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L1838-L1888)

Invert (take adjoint of) this circuit.

This is done by recursively inverting all gates.

**Parameters**

**annotated** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – indicates whether the inverse gate can be implemented as an annotated gate.

**Returns**

the inverted circuit

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – if the circuit cannot be inverted.

**Examples**

input:

```text
     ┌───┐
q_0: ┤ H ├─────■──────
     └───┘┌────┴─────┐
q_1: ─────┤ RX(1.57) ├
          └──────────┘
```

output:

```text
                  ┌───┐
q_0: ──────■──────┤ H ├
     ┌─────┴─────┐└───┘
q_1: ┤ RX(-1.57) ├─────
     └───────────┘
```

### power

`power(power, matrix_power=False, annotated=False)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L1918-L1971)

Raise this circuit to the power of `power`.

If `power` is a positive integer and both `matrix_power` and `annotated` are `False`, this implementation defaults to calling `repeat`. Otherwise, the circuit is converted into a gate, and a new circuit, containing this gate raised to the given power, is returned. The gate raised to the given power is implemented either as a unitary gate if `annotated` is `False` or as an annotated operation if `annotated` is `True`.

**Parameters**

- **power** ([*float*](https://docs.python.org/3/library/functions.html#float)) – The power to raise this circuit to.
- **matrix\_power** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – indicates whether the inner power gate can be implemented as a unitary gate.
- **annotated** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – indicates whether the inner power gate can be implemented as an annotated operation.

**Raises**

[**CircuitError**](/docs/api/qiskit/circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") – If the circuit needs to be converted to a unitary gate, but is not unitary.

**Returns**

A circuit implementing this circuit raised to the power of `power`.

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

### repeat

`repeat(reps, *, insert_barriers=False)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L1890-L1916)

Repeat this circuit `reps` times.

**Parameters**

- **reps** ([*int*](https://docs.python.org/3/library/functions.html#int)) – How often this circuit should be repeated.
- **insert\_barriers** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – Whether to include barriers between circuit repetitions.

**Returns**

A circuit containing `reps` repetitions of this circuit.

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

### reverse\_ops

`reverse_ops()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L1730-L1768)

Reverse the circuit by reversing the order of instructions.

This is done by recursively reversing all instructions. It does not invert (adjoint) any gate.

**Returns**

the reversed circuit.

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

**Examples**

input:

```text
     ┌───┐
q_0: ┤ H ├─────■──────
     └───┘┌────┴─────┐
q_1: ─────┤ RX(1.57) ├
          └──────────┘
```

output:

```text
                 ┌───┐
q_0: ─────■──────┤ H ├
     ┌────┴─────┐└───┘
q_1: ┤ RX(1.57) ├─────
     └──────────┘
```

## Visualization

Qiskit includes some drawing tools to give you a quick feel for what your circuit looks like. This tooling is primarily targeted at producing either a [Matplotlib](https://matplotlib.org/)- or text-based drawing. There is also a lesser-featured LaTeX backend for drawing, but this is only for simple circuits, and is not as actively maintained.

> **See also**
>
> **[`qiskit.visualization`](/docs/api/qiskit/visualization#module-qiskit.visualization "qiskit.visualization")**
>
> The primary documentation for all of Qiskit’s visualization tooling.

### draw

`draw(output=None, scale=None, filename=None, style=None, interactive=False, plot_barriers=True, reverse_bits=None, justify=None, vertical_compression='medium', idle_wires=None, with_layout=True, fold=None, ax=None, initial_state=False, cregbundle=None, wire_order=None, expr_len=30, measure_arrows=None, barrier_label_len=16)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3879-L4069)

Draw the quantum circuit. Use the output parameter to choose the drawing format:

**`text`**

ASCII art TextDrawing that can be printed in the console.

**`mpl`**

Images with color rendered purely in Python using matplotlib.

**`latex`**

High-quality images compiled via LaTeX.

> **Warning**
>
> This will call an installed system version of `pdflatex` on arbitrary user input by design (such as to render custom code in [`Instruction.label`](/docs/api/qiskit/qiskit.circuit.Instruction#label "qiskit.circuit.Instruction.label")), so should only be used on trusted input.

**`latex_source`**

Raw uncompiled LaTeX output. This is the source of what would be rendered by the `latex` drawer.

> **Warning**
>
> Support for [`Expr`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Expr "qiskit.circuit.classical.expr.Expr") nodes in conditions and `SwitchCaseOp.target` fields is preliminary and incomplete. The `text` and `mpl` drawers will make a best-effort attempt to show data dependencies, but the LaTeX-based drawers will skip these completely.

**Parameters**

- **output** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – Select the output method to use for drawing the circuit. Valid choices are `text`, `mpl`, `latex`, `latex_source`. By default, the `text` drawer is used unless the user config file (usually `~/.qiskit/settings.conf`) has an alternative backend set as the default. For example, `circuit_drawer = latex`. If the output kwarg is set, that backend will always be used over the default in the user config file.

- **scale** ([*float*](https://docs.python.org/3/library/functions.html#float) *| None*) – Scale of image to draw (shrink if `< 1.0`). Only used by the `mpl`, `latex` and `latex_source` outputs. Defaults to `1.0`.

- **filename** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – File path to save image to. Defaults to `None` (result not saved in a file).

- **style** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict)  *|*[*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) –

  Style name, file name of style JSON file, or a dictionary specifying the style.

  - The supported style names are `"iqp"` (default), `"iqp-dark"`, `"clifford"`, `"textbook"` and `"bw"`.
  - If given a JSON file, e.g. `my_style.json` or `my_style` (the `.json` extension may be omitted), this function attempts to load the style dictionary from that location. Note, that the JSON file must completely specify the visualization specifications. The file is searched for in `qiskit/visualization/circuit/styles`, the current working directory, and the location specified in `~/.qiskit/settings.conf`.
  - If a dictionary, every entry overrides the default configuration. If the `"name"` key is given, the default configuration is given by that style. For example, `{"name": "textbook", "subfontsize": 5}` loads the `"textbook"` style and sets the subfontsize (e.g. the gate angles) to `5`.
  - If `None` the default style `"iqp"` is used or, if given, the default style specified in `~/.qiskit/settings.conf`.

- **interactive** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – When set to `True`, show the circuit in a new window (for `mpl` this depends on the matplotlib backend being used supporting this). Note when used with either the text or the `latex_source` output type this has no effect and will be silently ignored. Defaults to `False`.

- **reverse\_bits** ([*bool*](https://docs.python.org/3/library/functions.html#bool) *| None*) – When set to `True`, reverse the bit order inside registers for the output visualization. Defaults to `False` unless the user config file (usually `~/.qiskit/settings.conf`) has an alternative value set. For example, `circuit_reverse_bits = True`.

- **plot\_barriers** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – Enable/disable drawing barriers in the output circuit. Defaults to `True`.

- **justify** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – Options are `"left"`, `"right"` or `"none"` (str). If anything else is supplied, left justified will be used instead. It refers to where gates should be placed in the output circuit if there is an option. `none` results in each gate being placed in its own column. Defaults to `left`.

- **vertical\_compression** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – `high`, `medium` or `low`. It merges the lines generated by the text output so the drawing will take less vertical room. Default is `medium`. Only used by the `text` output, will be silently ignored otherwise.

- **idle\_wires** ([*bool*](https://docs.python.org/3/library/functions.html#bool)  *|*[*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – Include (or not) idle wires (wires with no circuit elements) in output visualization. The string `"auto"` is also possible, in which case idle wires are shown except when the circuit has a layout attached. Default is `"auto"` unless the user config file (usually `~/.qiskit/settings.conf`) has an alternative value set. For example, `circuit_idle_wires = False`.

- **with\_layout** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – Include layout information, with labels on the physical layout. Default is `True`.

- **fold** ([*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – Sets pagination. It can be disabled using -1. In `text`, sets the length of the lines. This is useful when the drawing does not fit in the console. If None (default), it will try to guess the console width using `shutil.get_terminal_size()`. However, if running in jupyter, the default line length is set to 80 characters. In `mpl`, it is the number of (visual) layers before folding. Default is 25.

- **ax** ([*Any*](https://docs.python.org/3/library/typing.html#typing.Any) *| None*) – Only used by the mpl backend. An optional `matplotlib.axes.Axes` object to be used for the visualization output. If none is specified, a new matplotlib Figure will be created and used. Additionally, if specified there will be no returned Figure since it is redundant.

- **initial\_state** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – Adds $|0\rangle$ in the beginning of the qubit wires and $0$ to classical wires. Default is `False`.

- **cregbundle** ([*bool*](https://docs.python.org/3/library/functions.html#bool) *| None*) – If set to `True`, bundle classical registers. Default is `True`, except for when `output` is set to `"text"`.

- **wire\_order** ([*list*](https://docs.python.org/3/library/stdtypes.html#list)*\[*[*int*](https://docs.python.org/3/library/functions.html#int)*] | None*) – A list of integers used to reorder the display of the bits. The list must have an entry for every bit with the bits in the range 0 to (`num_qubits` + `num_clbits`).

- **expr\_len** ([*int*](https://docs.python.org/3/library/functions.html#int)) – The number of characters to display if an [`Expr`](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Expr "qiskit.circuit.classical.expr.Expr") is used for the condition in a [`ControlFlowOp`](/docs/api/qiskit/qiskit.circuit.ControlFlowOp "qiskit.circuit.ControlFlowOp"). If this number is exceeded, the string will be truncated at that number and ‘…’ added to the end.

- **measure\_arrows** ([*bool*](https://docs.python.org/3/library/functions.html#bool) *| None*) – If True, draw an arrow from each measure box down to the classical bit or register where the measure value is placed. If False, do not draw arrow, but instead place the name of the bit or register in the measure box. Default is `True` unless the user config file (usually `~/.qiskit/settings.conf`) has an alternative value set. For example, `circuit_measure_arrows = False`.

- **barrier\_label\_len** ([*int*](https://docs.python.org/3/library/functions.html#int)) – The number of characters to display for [`Barrier`](/docs/api/qiskit/circuit#qiskit.circuit.Barrier "qiskit.circuit.Barrier") labels in the output circuit. If this number is exceeded, the string will be truncated at that number and ‘…’ added to the end.

**Returns**

`TextDrawing` or `matplotlib.figure` or `PIL.Image` or [`str`](https://docs.python.org/3/library/stdtypes.html#str):

- **`TextDrawing` (if `output='text'`)**

  A drawing that can be printed as ascii art.

- **`matplotlib.figure.Figure` (if `output='mpl'`)**

  A matplotlib figure object for the circuit diagram.

- **`PIL.Image` (if `output='latex`’)**

  An in-memory representation of the image of the circuit diagram.

- **`str` (if `output='latex_source'`)**

  The LaTeX source code for visualizing the circuit diagram.

**Raises**

- [**VisualizationError**](/docs/api/qiskit/visualization#qiskit.visualization.VisualizationError "qiskit.visualization.VisualizationError") – when an invalid output method is selected
- [**ImportError**](https://docs.python.org/3/library/exceptions.html#ImportError) – when the output methods requires non-installed libraries.

**Example**

```python
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
qc = QuantumCircuit(1, 1)
qc.h(0)
qc.measure(0, 0)
qc.draw(output='mpl', style={'backgroundcolor': '#EEEEEE'})
```

![Circuit diagram output by the previous code.](https://eu-de.quantum.cloud.ibm.com/docs/images/api/qiskit/qiskit-circuit-QuantumCircuit-31.avif)

In addition to the core [`draw()`](#qiskit.circuit.QuantumCircuit.draw "qiskit.circuit.QuantumCircuit.draw") driver, there are two visualization-related helper methods, which are mostly useful for quickly unwrapping some inner instructions or reversing the [qubit-labelling conventions](/docs/api/qiskit/circuit#circuit-conventions) in the drawing. For more general mutation, including basis-gate rewriting, you should use the transpiler ([`qiskit.transpiler`](/docs/api/qiskit/transpiler#module-qiskit.transpiler "qiskit.transpiler")).

### decompose

`decompose(gates_to_decompose=None, reps=1)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L3826-L3859)

Call a decomposition pass on this circuit, to decompose one level (shallow decompose).

**Parameters**

- **gates\_to\_decompose** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*type*](/docs/api/qiskit/qiskit.dagcircuit.DAGDepNode#type "qiskit.dagcircuit.DAGDepNode.type")*\[*[*Instruction*](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.instruction.Instruction")*] |* [*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*type*](/docs/api/qiskit/qiskit.dagcircuit.DAGDepNode#type "qiskit.dagcircuit.DAGDepNode.type")*\[*[*Instruction*](/docs/api/qiskit/qiskit.circuit.Instruction "qiskit.circuit.instruction.Instruction")*]] | None*) – Optional subset of gates to decompose. Can be a gate type, such as `HGate`, or a gate name, such as “h”, or a gate label, such as “My H Gate”, or a list of any combination of these. If a gate name is entered, it will decompose all gates with that name, whether the gates have labels or not. Defaults to all gates in the circuit.
- **reps** ([*int*](https://docs.python.org/3/library/functions.html#int)) – Optional number of times the circuit should be decomposed. For instance, `reps=2` equals calling `circuit.decompose().decompose()`.

**Returns**

a circuit one level decomposed

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

### reverse\_bits

`reverse_bits()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/quantumcircuit.py#L1770-L1836)

Return a circuit with the opposite order of wires.

The circuit is “vertically” flipped. If a circuit is defined over multiple registers, the resulting circuit will have the same registers but with their order flipped.

This method is useful for converting a circuit written in little-endian convention to the big-endian equivalent, and vice versa.

**Returns**

the circuit with reversed bit order.

**Return type**

[QuantumCircuit](#qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")

**Examples**

input:

```text
     ┌───┐
a_0: ┤ H ├──■─────────────────
     └───┘┌─┴─┐
a_1: ─────┤ X ├──■────────────
          └───┘┌─┴─┐
a_2: ──────────┤ X ├──■───────
               └───┘┌─┴─┐
b_0: ───────────────┤ X ├──■──
                    └───┘┌─┴─┐
b_1: ────────────────────┤ X ├
                         └───┘
```

output:

```text
                         ┌───┐
b_0: ────────────────────┤ X ├
                    ┌───┐└─┬─┘
b_1: ───────────────┤ X ├──■──
               ┌───┐└─┬─┘
a_0: ──────────┤ X ├──■───────
          ┌───┐└─┬─┘
a_1: ─────┤ X ├──■────────────
     ┌───┐└─┬─┘
a_2: ┤ H ├──■─────────────────
     └───┘
```

**Parameters**

- **regs** ([*Register*](/docs/api/qiskit/circuit#qiskit.circuit.Register "qiskit.circuit.Register")  *|*[*int*](https://docs.python.org/3/library/functions.html#int) *| Sequence\[*[*Bit*](/docs/api/qiskit/circuit#qiskit.circuit.Bit "qiskit.circuit.Bit")*]*)
- **name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str))
- **global\_phase** (*ParameterValueType*)
- **metadata** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict) *| None*)
- **inputs** (*Iterable\[*[*expr.Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var")*]*)
- **captures** (*Iterable\[*[*expr.Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var")  *|*[*expr.Stretch*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Stretch "qiskit.circuit.classical.expr.Stretch")*]*)
- **declarations** (*Mapping\[*[*expr.Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var")*,* [*expr.Expr*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Expr "qiskit.circuit.classical.expr.Expr")*] | Iterable\[*[*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)*\[*[*expr.Var*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Var "qiskit.circuit.classical.expr.Var")*,* [*expr.Expr*](/docs/api/qiskit/circuit_classical#qiskit.circuit.classical.expr.Expr "qiskit.circuit.classical.expr.Expr")*]]*)
