Instructions

Circuits are composed of instructions, placed on qubits. These instructions can be of several types, detailed bellow.

The class

An Instruction is the base element for circuits elements, containing common methods to all of them.

class Instruction(targets, label=None)[source]

Bases: SimpleClassReprABC

Abstract class defining an instruction of a quantum circuit.

An Instruction is the elementary component of a QCircuit. It consists in 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 on 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 qubits ordered connected to instruction.

Return type

set[int]

Example

>>> CNOT(0,1).connections()
{0, 1}
subs(values, remove_symbolic=False)[source]

Substitutes the parameters of the instruction with complex values. Optionally also removes all symbolic variables such as \(\pi\) (needed for example for circuit execution).

Since we use sympy for gates’ parameters, values can in fact be anything the subs method from sympy would accept.

Parameters
  • values (dict[Expr | str, Complex]) – Mapping between the variables and the replacing values.

  • remove_symbolic (bool) – If symbolic values should be replaced by their numeric counterpart.

Returns

The circuit with the replaced parameters.

Return type

Instruction

Example

>>> theta = symbols("θ")
>>> print(Rx(theta, 0).subs({theta: np.pi}))
   ┌───────┐
q: ┤ Rx(π) ├
   └───────┘
to_other_language(language=Language.QISKIT, qiskit_parameters=None)[source]

Transforms this instruction into the corresponding object in the language specified in the language arg.

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.