---
title: QiskitGate (latest version)
description: API reference for qiskit_noise_learning.gate_sets.QiskitGate in the latest version of qiskit-noise-learning
source: https://quantum.cloud.ibm.com/docs/en/api/qiskit-noise-learning/generated/gate-sets-qiskit-gate
---

# qiskit\_noise\_learning.gate\_sets.QiskitGate

*class* `qiskit_noise_learning.gate_sets.QiskitGate(name: str, circuit: QuantumCircuit, qubit_idxs: Iterable[int], prep_idxs: Iterable[int] = (), annotations: Sequence[Annotation] | None = None, latex_str: str | None = None)`

[GitHub](https://github.com/Qiskit/qiskit-noise-learning/tree/stable/0.2/qiskit_noise_learning/gate_sets/qiskit_gate.py)

Bases: [`Gate`](/docs/api/qiskit-noise-learning/generated/gate-sets-gate "qiskit_noise_learning.gate_sets.gate.Gate")

Represents a single gate in a [`QiskitGateSet`](/docs/api/qiskit-noise-learning/generated/gate-sets-qiskit-gate-set "qiskit_noise_learning.gate_sets.QiskitGateSet").

It is assumed that the gate consists of a sequence of unitary operations, followed by measurements, and finally preparations or resets. The ordering of the operations is not currently validated, but every classical bit of `circuit` must be measured into exactly once, and no qubit may be measured more than once, since it is those measurements that define [`clbit_meas_idxs`](#qiskit_noise_learning.gate_sets.QiskitGate.clbit_meas_idxs "qiskit_noise_learning.gate_sets.QiskitGate.clbit_meas_idxs").

In many ways, this class is similar to a [`CircuitInstruction`](/docs/api/qiskit/qiskit.circuit.CircuitInstruction) containing a [`BoxOp`](/docs/api/qiskit/qiskit.circuit.BoxOp) in that it represents the action on some subset of qubits, and possibly with some of those qubits idling. It differs in that the physical qubits are represented as integers rather than [`Qubit`](/docs/api/qiskit/circuit#qiskit.circuit.Qubit) objects, and that we explicitly store which physical qubit indices perform preparation (or reset) operations.

This class also implements the equality operation, where two [`QiskitGate`](#qiskit_noise_learning.gate_sets.QiskitGate "qiskit_noise_learning.gate_sets.QiskitGate") instances are equal whenever their physical indices are equal, and their circuits are equal taking into account permutations of the lists `qubit_idxs` and `circuit.qubits`.

**Parameters**

- **name** – The name for the gate.
- **circuit** – The quantum circuit.
- **qubit\_idxs** – The physical qubit indices that `circuit.qubits` act on.
- **prep\_idxs** – The physical qubit indices that this gate prepares, or resets. This is included because explicitly using the `Reset` instruction is not common.
- **annotations** – The annotations that describe how to implement the gate. If `None`, this defaults to Pauli twirling. If no [`samplomatic.Tag`](/docs/api/samplomatic/auto/tag "(in samplomatic)") annotation is provided, then one is added automatically whose tag name is equal to `name`.
- **latex\_str** – An optional LaTeX string for this gate.

**Raises**

- [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If `qubit_idxs` does not have a length equal to `circuit.num_qubits`.
- [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If any classical bit of `circuit` is measured into more than once, or is never measured into.
- [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If any qubit of `circuit` is measured into more than one classical bit.
- [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If `annotations` does not include a [`samplomatic.Twirl`](/docs/api/samplomatic/auto/twirl "(in samplomatic)") annotation.

### \_\_init\_\_

`__init__(name: str, circuit: QuantumCircuit, qubit_idxs: Iterable[int], prep_idxs: Iterable[int] = (), annotations: Sequence[Annotation] | None = None, latex_str: str | None = None)`

## Methods

|                                                                                                                                                              |                                                                         |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------- |
| [`__init__`](#qiskit_noise_learning.gate_sets.QiskitGate.__init__ "qiskit_noise_learning.gate_sets.QiskitGate.__init__")(name, circuit, qubit\_idxs\[, ...]) |                                                                         |
| [`draw`](#qiskit_noise_learning.gate_sets.QiskitGate.draw "qiskit_noise_learning.gate_sets.QiskitGate.draw")(\*args, \*\*kwargs)                             | Draw this gate as a circuit diagram.                                    |
| [`iter_ops`](#qiskit_noise_learning.gate_sets.QiskitGate.iter_ops "qiskit_noise_learning.gate_sets.QiskitGate.iter_ops")()                                   | Iterate through the operations that compose this gate in circuit order. |
| [`to_instruction`](#qiskit_noise_learning.gate_sets.QiskitGate.to_instruction "qiskit_noise_learning.gate_sets.QiskitGate.to_instruction")()                 | Return this gate as a boxed instruction defined on `self.qubit_idxs`.   |

## Attributes

|                                                                                                                                                                 |                                                                                                                                                                                     |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`annotations`](#qiskit_noise_learning.gate_sets.QiskitGate.annotations "qiskit_noise_learning.gate_sets.QiskitGate.annotations")                               | The annotations to use with this gate.                                                                                                                                              |
| [`circuit`](#qiskit_noise_learning.gate_sets.QiskitGate.circuit "qiskit_noise_learning.gate_sets.QiskitGate.circuit")                                           | A circuit representation of this gate.                                                                                                                                              |
| [`clbit_meas_idxs`](#qiskit_noise_learning.gate_sets.QiskitGate.clbit_meas_idxs "qiskit_noise_learning.gate_sets.QiskitGate.clbit_meas_idxs")                   | The physical qubit index measured into each classical bit of [`circuit`](#qiskit_noise_learning.gate_sets.QiskitGate.circuit "qiskit_noise_learning.gate_sets.QiskitGate.circuit"). |
| [`constituent_gate_idxs`](#qiskit_noise_learning.gate_sets.QiskitGate.constituent_gate_idxs "qiskit_noise_learning.gate_sets.QiskitGate.constituent_gate_idxs") | Iterator over tuples of physical indices that specify where constituent gates act.                                                                                                  |
| `gate_idxs`                                                                                                                                                     | The physical indices where this gate undergoes unitary action.                                                                                                                      |
| `idling_idxs`                                                                                                                                                   | The physical qubit indices that this gate is idling on.                                                                                                                             |
| `label`                                                                                                                                                         | A string label for use in plotter legends.                                                                                                                                          |
| `latex_str`                                                                                                                                                     | A LaTeX string for this gate.                                                                                                                                                       |
| `math_label`                                                                                                                                                    | A string label for use within latex math mode.                                                                                                                                      |
| `meas_idxs`                                                                                                                                                     | The physical qubit indices that this gate measures.                                                                                                                                 |
| [`model_gate`](#qiskit_noise_learning.gate_sets.QiskitGate.model_gate "qiskit_noise_learning.gate_sets.QiskitGate.model_gate")                                  | The model for this gate.                                                                                                                                                            |
| `name`                                                                                                                                                          | The gate name.                                                                                                                                                                      |
| `num_qubits`                                                                                                                                                    | The number of qubits this gate acts on.                                                                                                                                             |
| `prep_idxs`                                                                                                                                                     | The physical qubit indices that this gate prepares (or resets).                                                                                                                     |
| `qubit_idxs`                                                                                                                                                    | The physical qubit indices this gate acts on.                                                                                                                                       |

### circuit

Type: [`QuantumCircuit`](/docs/api/qiskit/qiskit.circuit.QuantumCircuit)

A circuit representation of this gate.

> **Note**
>
> The `circuit.qubits` are completely irrelevant and do not, for example, represent physical qubits. Instead, the mappnig `dict(zip(circuit.qubits, qubit_idxs))` provides the recipe for which physical qubits each qubit in the circuit corresponds to. See also [`iter_ops()`](#qiskit_noise_learning.gate_sets.QiskitGate.iter_ops "qiskit_noise_learning.gate_sets.QiskitGate.iter_ops").

### clbit\_meas\_idxs

Type: [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)\[[`int`](https://docs.python.org/3/builtins/functions.html#int), ...]

The physical qubit index measured into each classical bit of [`circuit`](#qiskit_noise_learning.gate_sets.QiskitGate.circuit "qiskit_noise_learning.gate_sets.QiskitGate.circuit").

Entry `j` is the physical qubit whose measurement outcome is stored in classical bit `j`, which is the order in which a backend reports outcomes.

### annotations

Type: [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)\[[`Annotation`](/docs/api/qiskit/qiskit.circuit.Annotation)]

The annotations to use with this gate.

### constituent\_gate\_idxs

Type: [`Iterator`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterator)\[[`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)\[[`int`](https://docs.python.org/3/builtins/functions.html#int), ...]]

Iterator over tuples of physical indices that specify where constituent gates act.

Some subclasses may not have a meaningful notion of what a “constituent gate” is, because they don’t choose to represent unitary action by some seperable representation. The only contract they need to obey is that the union of all yielded integers is equal to [`gate_idxs`](/docs/api/qiskit-noise-learning/generated/gate-sets-gate#gate_idxs "qiskit_noise_learning.gate_sets.Gate.gate_idxs").

### iter\_ops

`iter_ops() → Iterable[tuple[tuple[int, ...], Operation]]`

Iterate through the operations that compose this gate in circuit order.

Instructions that carry no physical action, such as barriers, are skipped.

**Yields**

Tuples `(physical_qubits, operation)` for each instruction in [`circuit`](#qiskit_noise_learning.gate_sets.QiskitGate.circuit "qiskit_noise_learning.gate_sets.QiskitGate.circuit").

### to\_instruction

`to_instruction() → CircuitInstruction`

Return this gate as a boxed instruction defined on `self.qubit_idxs`.

### model\_gate

[GitHub](https://github.com/Qiskit/qiskit-noise-learning/tree/stable/0.2/qiskit_noise_learning/gate_sets/qiskit_gate.py)

Type: [`ModelGate`](/docs/api/qiskit-noise-learning/generated/gate-sets-model-gate "qiskit_noise_learning.gate_sets.model_gate.ModelGate")

The model for this gate.

### draw

`draw(*args, **kwargs)`

Draw this gate as a circuit diagram.

Wire labels display the mapping from virtual qubit indices (the circuit’s qubit ordering) to physical qubit indices, using the Qiskit `TranspileLayout` convention, e.g. `v_0 -> 5`.

**Parameters**

- **\*args** – Positional keyword arguments forwarded to [`draw()`](/docs/api/qiskit/qiskit.circuit.QuantumCircuit#draw).
- **\*\*kwargs** – Keyword arguments forwarded to [`draw()`](/docs/api/qiskit/qiskit.circuit.QuantumCircuit#draw).

**Returns**

Text, matplotlib figure, or latex depending on the `output` kwarg.
