- class CircuitInstruction(operation, qubits=(), clbits=())¶
There is some possible confusion in the names of this class,
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」.
Instructioncame first, and originally contained the qubits it operated on and any parameters, so it was a true 「instruction」. Over time,
QuantumCircuitbecame 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
Operationinterface 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.operationis often an
Operationinterface), but as the
Operationinterface gains more use, this confusion will hopefully abate.
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
qubitsmust be a sequence of distinct items, with no duplicates.
Return a shallow copy of the
Return a new
CircuitInstructionwith the given fields replaced.