Skip to main contentIBM Quantum Documentation Mirror

CircuitInstruction

class qiskit.circuit.CircuitInstruction

Bases: object(opens in a new tab)

A single instruction in a QuantumCircuit, comprised of the operation and various operands.

Note

There is some possible confusion in the names of this class, Instruction, and Operation, and this class’s attribute operation. Our preferred terminology is by analogy to assembly languages, where an “instruction” is made up of an “operation” and its “operands”.

Historically, Instruction came first, and originally contained the qubits it operated on and any parameters, so it was a true “instruction”. Over time, QuantumCircuit became responsible for tracking qubits and clbits, and the class became better described as an “operation”. Changing the name of such a core object would be a very unpleasant API break for users, and so we have stuck with it.

This class was created to provide a formal “instruction” context object in QuantumCircuit.data, which had long been made of ad-hoc tuples. With this, and the advent of the Operation interface for adding more complex objects to circuits, we took the opportunity to correct the historical naming. For the time being, this leads to an awkward case where CircuitInstruction.operation is often an Instruction instance (Instruction implements the Operation interface), but as the Operation interface gains more use, this confusion will hopefully abate.

Warning

This is a lightweight internal class and there is minimal error checking; you must respect the type hints when using it. It is the user’s responsibility to ensure that direct mutations of the object do not invalidate the types, nor the restrictions placed on it by its context. Typically this will mean, for example, that qubits must be a sequence of distinct items, with no duplicates.


Attributes

clbits

A sequence of the classical bits that this operation reads from or writes to.

condition

duration

label

matrix

name

Returns the Instruction name corresponding to the op for this node

operation

The logical operation that this instruction represents an execution of.

params

qubits

A sequence of the qubits that the operation is applied to.

unit


Methods

copy

copy()

Returns a shallow copy.

Returns

The shallow copy.

Return type

CircuitInstruction

from_standard

static from_standard(standard, qubits, params, label=None)

is_control_flow

is_control_flow()

Is the Operation contained in this instruction a control-flow operation (i.e. an instance of ControlFlowOp)?

is_controlled_gate

is_controlled_gate()

Is the Operation contained in this instruction a subclass of ControlledGate?

is_directive

is_directive()

Is the Operation contained in this node a directive?

is_parameterized

is_parameterized()

Does this instruction contain any ParameterExpression parameters?

is_standard_gate

is_standard_gate()

Is the Operation contained in this instruction a Qiskit standard gate?

replace

replace(operation=None, qubits=None, clbits=None, params=None)

Creates a shallow copy with the given fields replaced.

Returns

A new instance with the given fields replaced.

Return type

CircuitInstruction