Instructions
Circuits are composed of instructions applied to qubits. These instructions can be of several types, detailed below.
The class
An Instruction is the base element of circuit elements, containing methods common to all of them.
- class Instruction(targets, label=None)[source]
Bases:
SimpleClassReprABCAbstract class defining an instruction of a quantum circuit.
An Instruction is the elementary component of a
circuit. It consists of a manipulation of one (or several) qubit(s) of the quantum circuit. It may involve classical bits as well, for defining or retrieving the result of the instruction.It can be of type:
- Parameters:
targets (list[int]) – List of indices referring to the qubits to which the instruction will be applied.
label (Optional[str]) – Label used to identify the instruction.
- connections()[source]
Returns the indices of the qubits connected to the instruction.
- Returns:
The ordered qubits connected to instruction.
- Return type:
set[int]
Example
>>> CNOT(0,1).connections() {0, 1}
- subs(values)[source]
Substitutes the parameters of the instruction with complex values. Optionally, also removes all symbolic variables such as \(\pi\) (needed for circuit execution, for example).
Since we use
sympyfor gate parameters,valuescan in fact be anything thesubsmethod fromsympywould accept.- Parameters:
values (dict[Expr | str, Complex]) – Mapping between the variables and the replacing values.
- Returns:
The circuit with the replaced parameters.
- Return type:
Example
>>> theta = symbols("θ") >>> print(Rx(theta, 0).subs({theta: np.pi})) ┌───────┐ q: ┤ Rx(π) ├ └───────┘
- abstractmethod to_other_language(language=Language.QISKIT, qiskit_parameters=None)[source]
Transforms this instruction into the corresponding object in the language specified in the
languagearg.By default, the instruction is translated to the corresponding one in Qiskit, since it is the interface we use to generate the OpenQASM code.
In the future, we will generate the OpenQASM code on our own, and this method will be used only for complex objects that are not tractable by OpenQASM (like hybrid structures).
- Parameters:
language (Language) – Enum representing the target language.
qiskit_parameters (Optional[set['Parameter']]) – We need to keep track of the parameters passed to qiskit in order not to define twice the same parameter. Defaults to
set().
- Returns:
The corresponding instruction (gate or measure) in the target language.
- Return type:
Any
- label
See parameter description.
- property nb_cbits: int
Number of cbits of this instruction.
- property nb_qubits: int
Number of qubits of this instruction.
- targets
See parameter description.
Instruction types
Instructions can be of type:
Each of there are described on their respective page.