QuantumCircuit module

class QuantumCircuit

Implements the QuantumCircuit class. Use this class to construct the quantum circuit using one of the three constructors provided.

Method 1

Example:

>>> qc = QuantumCircuit(5, 5) # constructs a quantum circuit of 5 qubits and 5 classical bits
Method 2

Example:

>>> qc = QuantumCircuit(5) # constructs a quantum circuit of 5 qubits
Method 3

Example:

>>> q = QuantumRegister(5)
>>> c = ClassicalRegister(5)
>>> a = AncillaRegister(1)
>>> qc = QuantumCircuit(q, c, a) # constructs a quantum circuit of 5 qubits, 5 classical bits, and 1 ancilla register
QuantumCircuit(*args, name=None, global_phase=0, metadata=<class 'dict'>)

The constructor of the QuantumCircuit class.

Args:
args (*args):

A list of QuantumRegister, ClassicalRegister, AncillaRegister objects to be used to construct the quantum circuit.(or)num_qubits (int), num_cbits (Optional [int]), The number of qubits and the number of classical bits to be used to construct the quantum circuit.

name (Optional[str]):

An optional name of the quantum circuit.

global_phase(Optional[float]):

An optional global phase of the quantum circuit.

metadata(Optional[dict]):

Unused.

Returns:

QuantumCircuit

Raises:

OutOfRangeError: If the number of qubits exceed system capacity or the account limits.

RunTimeError:

If there was an error allocating memory.

QuantumCircuit.num_qubits: int

The total number of qubits currently defined in the circuit.

QuantumCircuit.num_ancillas: int

The total number of ancillas currently defined in the circuit.

QuantumCircuit.num_clbits: int

The toal number of classical register bits defined in the circuit.

QuantumCircuit.header: str

Contains the string “OPENQASM 2.0;”

QuantumCircuit.instances: int

Total number of instances that can be supported. Currently this is set to 153.

QuantumCircuit.global_phase: float

This attribute maintains the global phase of the circuit.

QuantumCircuit.prefix: str

Contains the prefix string “circuit”.

QuantumCircuit.op_start_times: str

Returns the time when a quantum circuit can be executed the next.

QuantumCircuit.ancillas: [<class 'int'>]

Returns the list of ancilla registers.

QuantumCircuit.clbits: [<class 'int'>]

Returns the list of classical register bits.

QuantumCircuit.qubits: [<class 'int'>]

Returns the list of qubits.

QuantumCircuit.layout: None

Return circuit layout. This attribute is currently not used.

QuantumCircuit.num_parameters: int

Returns the number of circuit parameters. This attribute is currently not used.

QuantumCircuit.calibrations: [<class 'dict'>]

Return the calibration dictionary for the qubits. This attribute is currently not used.

h(self, qubit, label=None)

Inserts a Hadamard gate into the quantum circuit for the specified qubit. This gate implements a pi rotation about the X+Z axis.

Circuit symbol:

   ┌───┐
q: ┤ H ├
   └───┘

Matrix Representation:

\[\begin{split}H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}\end{split}\]
Args:
qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the HGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

x(self, qubit, label=None)

Inserts an X gate or the NOT gate into the quantum circuit for the specified qubit. This gate is equivalent to π rotation about the x-axis.

Circuit symbol:

   ┌───┐
q: ┤ X ├
   └───┘

Matrix Representation:

\[\begin{split}X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\end{split}\]
Args:
qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the XGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

i(self, qubit, label=None)

Inserts an I gate or the identity gate into the quantum circuit for the specified qubit.

Circuit symbol:

   ┌───┐
q: ┤ I ├
   └───┘

Matrix Representation:

\[\begin{split}I = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}\end{split}\]
See also:

QuantumCircuit.id()

Args:
qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the IGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

id(self, qubit, label=None)

Inserts an I gate or the identity gate into the quantum circuit for the specified qubit.

Circuit symbol:

   ┌───┐
q: ┤ I ├
   └───┘

Matrix Representation:

\[\begin{split}I = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}\end{split}\]
See also:

QuantumCircuit.i()

Args:
qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the IGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

t(self, qubit, label=None)

Inserts a T gate (Z**0.25) into the quantum circuit for the specified qubit.

This gate induces a π/4 phase, and it is also called the π/8 gate.

This is a non-Clifford gate and a fourth-root of Pauli-Z. It introduces a π/4 rotation about the z-axis.

Circuit symbol:

   ┌───┐
q: ┤ T ├
   └───┘

Matrix Representation:

\[\begin{split}T = \begin{pmatrix} 1 & 0 \\ 0 & 1+i \end{pmatrix}\end{split}\]
Args:
qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the TGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

s(self, qubit, label=None)

Inserts a S gate (Z*0.5) into the quantum circuit for the specified qubit.

It induces a π/2 phase, and is sometimes called the P gate (phase).

This is a Clifford gate and a square-root of Pauli-Z. This gate is equivalent to a π/2 rotation about the z-axis.

Circuit symbol:

   ┌───┐
q: ┤ S ├
   └───┘

Matrix Representation:

\[\begin{split}S = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix}\end{split}\]
Args:
qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

None

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

tdg(self, qubit, label=None)

Inserts a Tdg gate, which is the T-adjoint gate (~Z**0.25) into the quantum circuit for the specified qubit.

It induces a -π/4 phase.

This is a non-Clifford gate and a fourth-root of Pauli-Z. This gate introduces a -π/2 rotation about the z-axis.

Circuit symbol:

   ┌─────┐
q: ┤ Tdg ├
   └─────┘

Matrix Representation:

\[\begin{split}Tdg = \begin{pmatrix} 1 & 0 \\ 0 & 1-i \end{pmatrix}\end{split}\]
Args:
qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the TdgGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

sx(self, qubit, label=None)

Inserts an SX gate into the quantum circuit for the specified qubit.

It implements (\(\sqrt{X}\)) function .

Circuit symbol:

   ┌────┐
q: ┤ √X ├
   └────┘

Matrix Representation:

\[\begin{split}\sqrt{X} = \frac{1}{2} \begin{pmatrix} 1 + i & 1 - i \\ 1 - i & 1 + i \end{pmatrix}\end{split}\]
Args:
qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the SxGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

sxdg(self, qubit, label=None)

Inserts a SXdg gate into the quantum circuit for the specified qubit.

It implements the inverse of sqrt(X) function.

Circuit symbol:

   ┌────────┐
q: ┤ √(x)^† ├
   └────────┘

Matrix Representation:

\[\begin{split}\sqrt{X}^{\dagger} = \frac{1}{2} \begin{pmatrix} 1 - i & 1 + i \\ 1 + i & 1 - i \end{pmatrix}\end{split}\]

See also:

QuantumCircuits.phasegate()

Args:
qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the SxdgGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

p(theta, qubit, label=None)

Implements the Phase gate, that is a rotation about the z-axis.

Circuit symbol:

   ┌──────┐
q: ┤ P(θ) ├
   └──────┘

Matrix Representation:

\[\begin{split}P(\lambda) = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\theta} \end{pmatrix}\end{split}\]

Args:

theta (float):

The θ rotational angle.

qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the PGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

r(theta, phi, qubit, label=None)

The r gate is a rotation gate that rotates the qubit by θ degrees around the cos(φ)x + sin(φ)y axis.

Circuit symbol:

   ┌──────┐
q: ┤ R(ϴ) ├
   └──────┘

Matrix Representation:

\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}R(\theta, \phi) = e^{-i \th \left(\cos{\phi} x + \sin{\phi} y\right)} = \begin{pmatrix} \cos\left(\th\right) & -i e^{-i \phi} \sin\left(\th\right) \\ -i e^{i \phi} \sin\left(\th\right) & \cos\left(\th\right) \end{pmatrix}\end{split}\end{aligned}\end{align} \]

Args:

theta (float):

The θ rotational angle.

phi (float):

The φ rotational angle.

qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the RGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

rv(vx, vy, vz, qubit, label=None)

The rv gate is a rotation gate around arbitrary rotation axis \(v\) where \(|v|\) is angle of rotation in radians.

Circuit symbol:

   ┌─────────────────┐
q: ┤ RV(v_x,v_y,v_z) ├
   └─────────────────┘

Matrix Representation:

\[ \begin{align}\begin{aligned}\newcommand{\th}{|\vec{v}|}\\\newcommand{\sinc}{\text{sinc}}\\\begin{split}R(\vec{v}) = e^{-i \vec{v}\cdot\vec{\sigma}} = \begin{pmatrix} \cos\left(\th\right) -i v_z \sinc\left(\th\right) & -(i v_x + v_y) \sinc\left(\th\right) \\ -(i v_x - v_y) \sinc\left(\th\right) & \cos\left(\th\right) + i v_z \sinc\left(\th\right) \end{pmatrix}\end{split}\end{aligned}\end{align} \]

See also:

QuantumCircuits.u()

Args:

theta (float):

The θ rotational angle.

phi (float):

The φ rotational angle.

lambda (float):

The λ rotational angle.

qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the RVGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

rx(theta, qubit, label=None)

The RX gate is a rotation gate that rotates the qubit by θ radians about the x-axis.

Circuit symbol:

   ┌───────┐
q: ┤ RX(ϴ) ├
   └───────┘

Matrix Representation:

\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}RX(\theta) = \exp\left(-i \th X\right) = \begin{pmatrix} \cos\left(\th\right) & -i\sin\left(\th\right) \\ -i\sin\left(\th\right) & \cos\left(\th\right) \end{pmatrix}\end{split}\end{aligned}\end{align} \]

Args:

theta (float):

The θ rotational angle.

qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the RXGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

ry(theta, qubit, label=None)

The RY gate is a rotation gate that rotates the qubit by θ radians about the y-axis.

Circuit symbol:

   ┌───────┐
q: ┤ RY(ϴ) ├
   └───────┘

Matrix Representation:

\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}RY(\theta) = \exp\left(-i \th Y\right) = \begin{pmatrix} \cos\left(\th\right) & -\sin\left(\th\right) \\ \sin\left(\th\right) & \cos\left(\th\right) \end{pmatrix}\end{split}\end{aligned}\end{align} \]

Args:

theta (float):

The θ rotational angle.

qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the RYGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

rz(theta, qubit, label=None)

The RZ gate is a rotation gate that rotates the qubit by θ radians about the Z-axis.

Circuit symbol:

   ┌───────┐
q: ┤ RZ(θ) ├
   └───────┘

Matrix Representation:

\[\begin{split}RZ(\theta) = \exp\left(-i\frac{\theta}{2}Z\right) = \begin{pmatrix} e^{-i\frac{\theta}{2}} & 0 \\ 0 & e^{i\frac{\theta}{2}} \end{pmatrix}\end{split}\]

See also:

This gate is equivalent to QuantumCircuits.u1() up to a phase factor.

\[U1(\theta) = e^{i{\theta}/2}RZ(\theta)\]

Args:

theta (float):

The θ rotational angle.

qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the RZGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

u(theta, phi, lam, qubit, label=None)

The U gate is a rotation gate that rotates the qubit by the three Euler angles ϴ,φ,λ.

Circuit symbol:

   ┌───────────┐
q: ┤ U(ϴ,φ,λ)  ├
   └───────────┘

Matrix Representation:

\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}U(\theta, \phi, \lambda) = \begin{pmatrix} \cos\left(\th\right) & -e^{i\lambda}\sin\left(\th\right) \\ e^{i\phi}\sin\left(\th\right) & e^{i(\phi+\lambda)}\cos\left(\th\right) \end{pmatrix}\end{split}\end{aligned}\end{align} \]

See also:

QuantumCircuits.u3()

Args:

theta (float):

The θ rotational angle.

phi (float):

The φ rotational angle.

lam (float):

The λ rotational angle.

qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the UGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

y(qubit, label=None)

Inserts a Y gate into the quantum circuit for the specified qubit. This gate is equivalent to π rotation about the y-axis and equivalent to a bit and phase-flip. Also, this gate is a Pauli-Y gate (\(\sigma_y\)).

Circuit symbol:

   ┌───┐
q: ┤ Y ├
   └───┘

Matrix Representation:

\[\begin{split}Y = \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}\end{split}\]
Args:
qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the YGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

z(qubit, label=None)

Inserts a Z gate into the quantum circuit for the specified qubit. This gate is equivalent to π rotation about the z-axis and equivalent to a bit-flip. Also, this gate is a Pauli-Z gate (\(\sigma_z\)).

Circuit symbol:

   ┌───┐
q: ┤ Z ├
   └───┘

Matrix Representation:

\[\begin{split}Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}\end{split}\]
Args:
qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the ZGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

u1(lam, qubit, label=None)

The U1 gate is a rotation gate that rotates the qubit about the z-axis and equivalent to the RZ gate upto a phase factor.

Implementation:

\[U1(\lambda) = P(\lambda)= U(0,0,\lambda)\]

Circuit symbol:

   ┌───────────┐
q: ┤ U1(λ)     ├
   └───────────┘

Matrix Representation:

\[\begin{split}U1(\lambda) = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\lambda} \end{pmatrix}\end{split}\]

See also:

QuantumCircuits.rz() QuantumCircuits.p()

Args:

lam (float):

The λ rotational angle.

qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the U1Gate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

u2(phi, lam, qubit, label=None)

The U2 gate is a rotation gate that rotates the qubit about the X+Z axis.

Implementation:

\[U2(\phi, \lambda) = U\left(\frac{\pi}{2}, \phi, \lambda\right)\]

Circuit symbol:

   ┌──────────┐
q: ┤ U2(φ,λ)  ├
   └──────────┘

Matrix Representation:

\[\begin{split}U2(\phi, \lambda) = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & -e^{i\lambda} \\ e^{i\phi} & e^{i(\phi+\lambda)} \end{pmatrix}\end{split}\]

See also:

QuantumCircuits.u()

Args:

phi (float):

The φ rotational angle.

lam (float):

The λ rotational angle.

qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the U2Gate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

u3(theta, phi, lam, qubit, label=None)

The U3 gate is a rotation gate that rotates the qubit by the three Euler angles ϴ,φ,λ.

Implementation:

\[U3(\theta, \phi, \lambda) = RZ(\phi - \pi/2) RX(\pi/2) RZ(\pi - \theta) RX(\pi/2) RZ(\lambda - \pi/2)\]

Circuit symbol:

   ┌───────────┐
q: ┤ U3(ϴ,φ,λ) ├
   └───────────┘

Matrix Representation:

\[\begin{split}U3(\theta, \phi, \lambda) = \begin{pmatrix} \cos(\frac{\theta}{2}) & -e^{i\lambda}\sin(\frac{\theta}{2}) \\ e^{i\phi}\sin(\frac{\theta}{2}) & e^{i(\phi+\lambda)}\cos(\frac{\theta}{2}) \end{pmatrix}\end{split}\]

See also:

QuantumCircuits.u()

Args:

theta (float):

The θ rotational angle.

phi (float):

The φ rotational angle.

lam (float):

The λ rotational angle.

qubit (int, [int], QuantumRegister, or AncillaRegister):

The index number of the qubit. List of qubits. or, the QuantumRegister

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the U3Gate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

delay(duration, qubit, unit, label=None)

Delays the execution of the specified qubit by the time duration set by the instruction.

Args:

duration (int):

The duration by which the execution needs to be delayed in time units.

qubit (int, [int], QuantumRegister or AncillaRegister):

The index number of the qubit. List of qubits. QuantumRegister. or, the AncillaREgister

unit (str):

default - “dt” the default internal time unit, which is millseconds “s” - time unit in seconds “ms” - time unit in millseconds “us” - time unit in microseconds “ns” - time unit in nanoseconds “ps” - time unit in picoseconds

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the DelayGate if successful.

Raises:

OutOfRangeError: If the index of the qubit exceed declaration.

cx(control_qubit, target_qubit, label=None)

Two qubit Controlled-X gate.

Circuit symbol:

q[0]: ──■──
      ┌─┴─┐
q[1]: ┤ X ├
      └───┘

Matrix Representation:

\[\begin{split}CX\ q0, q1 = I \otimes |0\rangle\langle0| + X \otimes |1\rangle\langle1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \end{pmatrix}\end{split}\]

See also:

QuantumCircuits.cnot()

Args:

control_qubit (int):

The control qubit.

target_qubit (int):

The target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CXGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

cy(control_qubit, target_qubit, label=None)

Two qubit Controlled-Y gate.

Circuit symbol:

q[0]: ──■──
      ┌─┴─┐
q[1]: ┤ Y ├
      └───┘

Matrix Representation:

\[\begin{split}CY\ q[0], q[1] = I \otimes |0 \rangle\langle 0| + Y \otimes |1 \rangle\langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & -i \\ 0 & 0 & 1 & 0 \\ 0 & i & 0 & 0 \end{pmatrix}\end{split}\]

Args:

control_qubit (int):

The control qubit.

target_qubit (int):

The target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CYGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

cz(control_qubit, target_qubit, label=None)

Two qubit Controlled-z gate.

Circuit symbol:

q[0]: ─■─
       │
q[1]: ─■─

Matrix Representation:

\[\begin{split}CZ\ q[0], q[1] = I \otimes |0\rangle\langle 0| + Z \otimes |1\rangle\langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix}\end{split}\]

Args:

control_qubit (int):

The control qubit.

target_qubit (int):

The target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CZGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

ch(control_qubit, target_qubit, label=None)

Two qubit Controlled-Hadamard gate.

Circuit symbol:

q[0]: ──■──
      ┌─┴─┐
q[1]: ┤ H ├
      └───┘

Matrix Representation:

\[\begin{split}CH\ q0, q1 = I \otimes |0\rangle\langle 0| + H \otimes |1\rangle\langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & \frac{1}{\sqrt{2}} & 0 & \frac{1}{\sqrt{2}} \\ 0 & 0 & 1 & 0 \\ 0 & \frac{1}{\sqrt{2}} & 0 & -\frac{1}{\sqrt{2}} \end{pmatrix}\end{split}\]

Args:

control_qubit (int):

The control qubit.

target_qubit (int):

The target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CHGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

cnot(control_qubit, target_qubit, label=None)

Two qubit Controled - NOT gate.

Circuit symbol:

q[0]: ──■──
      ┌─┴─┐
q[1]: ┤ X ├
      └───┘

Matrix Representation:

\[\begin{split}CNOT\ q0, q1 = I \otimes |0\rangle\langle0| + X \otimes |1\rangle\langle1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \end{pmatrix}\end{split}\]

See also:

QuantumCircuits.cx()

Args:

control_qubit (int):

The control qubit.

target_qubit (int):

The target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CNOTGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

cp(theta, control_qubit, target_qubit, label=None)

Two qubit Controled - Phase gate. This gate induces a phase on the target qubit, if the control qubit is at \(|1\rangle\).

Circuit symbol:

q[0]: ─■──
       │λ
q[1]: ─■──

Matrix Representation:

\[\begin{split}CPhase = I \otimes |0\rangle\langle 0| + P \otimes |1\rangle\langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & e^{i\lambda} \end{pmatrix}\end{split}\]

Args:

theta (float):

The θ rotational angle.

control_qubit (int):

The control qubit.

target_qubit (int):

The target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CPGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

crx(theta, control_qubit, target_qubit, label=None)

Two qubit Controled - RX gate.

Circuit symbol:

q[0]: ────■────
      ┌───┴───┐
q[1]: ┤ RY(ϴ) ├
      └───────┘

Matrix Representation:

\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}CRX(\theta)\ q0, q1 = I \otimes |0\rangle\langle 0| + RX(\theta) \otimes |1\rangle\langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos\left(\th\right) & 0 & -i\sin\left(\th\right) \\ 0 & 0 & 1 & 0 \\ 0 & -i\sin\left(\th\right) & 0 & \cos\left(\th\right) \end{pmatrix}\end{split}\end{aligned}\end{align} \]

Args:

theta (float):

The θ rotational angle.

control_qubit (int):

The control qubit.

target_qubit (int):

The target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CRXGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

cry(theta, control_qubit, target_qubit, label=None)

Two qubit Controled - RY gate.

Circuit symbol:

q[0]: ────■────
      ┌───┴───┐
q[1]: ┤ RY(ϴ) ├
      └───────┘

Matrix Representation:

\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}CRY(\theta)\ q0, q1 = I \otimes |0\rangle\langle 0| + RY(\theta) \otimes |1\rangle\langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos\left(\th\right) & 0 & -\sin\left(\th\right) \\ 0 & 0 & 1 & 0 \\ 0 & \sin\left(\th\right) & 0 & \cos\left(\th\right) \end{pmatrix}\end{split}\end{aligned}\end{align} \]

Args:

theta (float):

The θ rotational angle.

control_qubit (int):

The control qubit.

target_qubit (int):

The target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CRYGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

crz(theta, control_qubit, target_qubit, label=None)

Two qubit Controled - RZ gate.

Circuit symbol:

q[0]: ────■────
      ┌───┴───┐
q[1]: ┤ RZ(ϴ) ├
      └───────┘

Matrix Representation:

\[\begin{split}CRZ(\lambda)\ q0, q1 = I \otimes |0\rangle\langle 0| + RZ(\lambda) \otimes |1\rangle\langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & e^{-i\frac{\lambda}{2}} & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & e^{i\frac{\lambda}{2}} \end{pmatrix}\end{split}\]

Args:

theta (float):

The θ rotational angle.

control_qubit (int):

The control qubit.

target_qubit (int):

The target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CRZGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

cs(control_qubit, target_qubit, label=None)

Two qubit Controled - S gate.

Circuit symbol:

q[0]: ────■────
      ┌───┴───┐
q[1]: ┤   S   ├
      └───────┘

Matrix Representation:

\[\begin{split}CS \ q0, q1 = I \otimes |0 \rangle\langle 0| + S \otimes |1 \rangle\langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & i \end{pmatrix}\end{split}\]

Args:

control_qubit (int):

The control qubit.

target_qubit (int):

The target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CSGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

csdg(control_qubit, target_qubit, label=None)

Two qubit Controled - Sdg gate.

Circuit symbol:

q[0]: ────■────
      ┌───┴───┐
q[1]: ┤  Sdg  ├
      └───────┘

Matrix Representation:

\[\begin{split}CS^\dagger \ q0, q1 = I \otimes |0 \rangle\langle 0| + S^\dagger \otimes |1 \rangle\langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -i \end{pmatrix}\end{split}\]

Args:

control_qubit (int):

The control qubit.

target_qubit (int):

The target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CSdgGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

csx(control_qubit, target_qubit, label=None)

Two qubit Controled - \(sqrt{X}\) gate.

Circuit symbol:

q[0]: ────■────
      ┌───┴───┐
q[1]: ┤  √X   ├
      └───────┘

Matrix Representation:

\[\begin{split}C\sqrt{X} \ q0, q1 = I \otimes |0 \rangle\langle 0| + \sqrt{X} \otimes |1 \rangle\langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & (1 + i) / 2 & 0 & (1 - i) / 2 \\ 0 & 0 & 1 & 0 \\ 0 & (1 - i) / 2 & 0 & (1 + i) / 2 \end{pmatrix}\end{split}\]

Args:

control_qubit (int):

The control qubit.

target_qubit (int):

The target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CSxGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

cu(theta, phi, lam, gamma, control_qubit, target_qubit, label=None)

Controlled - U gate. Also adds a global phase of \(e^{i\gamma}\) to the U gate.

Circuit symbol:

q[0]: ──────■──────
      ┌─────┴──────┐
q[1]: ┤ U(ϴ,φ,λ,γ) ├
      └────────────┘

Matrix Representation:

\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}CU(\theta, \phi, \lambda, \gamma)\ q0, q1 = I \otimes |0\rangle\langle 0| + e^{i\gamma} U(\theta,\phi,\lambda) \otimes |1\rangle\langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & e^{i\gamma}\cos(\th) & 0 & -e^{i(\gamma + \lambda)}\sin( h) \\ 0 & 0 & 1 & 0 \\ 0 & e^{i(\gamma+\phi)}\sin(\th) & 0 & e^{i(\gamma+\phi+\lambda)}\cos(\th) \end{pmatrix}\end{split}\end{aligned}\end{align} \]

Args:

theta (float):

The θ rotational angle.

phi (float):

The φ rotational angle.

lam (float):

The λ rotational angle.

gamma (float):

The γ rotation angle.

qubit (int):

The index number of the qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CUGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

dcx(qubit1, qubit2, label=None)

Implements a double C-NOT gate with back to back controls. This is a 2-qubit Clifford gate.

Circuit symbol:

           ┌───┐
q[0]: ──■──┤ X ├
      ┌─┴─┐└─┬─┘
q[1]: ┤ X ├──■──
      └───┘

Matrix Representation:

\[\begin{split}DCX\ q0, q1 = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \end{pmatrix}\end{split}\]

Args:

qubit1 (int):

The first qubit.

qubit2 (int):

The second qubite.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the DCXGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

ecr(qubit1, qubit2, label=None)

An echoed cross-resonance gate. This gate is maximally entangling and is equivalent to a CNOT up to single-qubit pre-rotations. The echoing procedure mitigates some unwanted terms (terms other than ZX) to cancel in an experiment. More specifically, this gate implements \(\frac{1}{\sqrt{2}}(IX-XY)\).

Circuit symbol:

      ┌─────────┐             ┌────────────┐┌────────┐┌─────────────┐
q[0]: ┤0        ├       q[0]: ┤0           ├┤ RX(pi) ├┤0            ├
      │   ECR   │   =         │  RZX(pi/4) │└────────┘│  RZX(-pi/4) │
q[1]: ┤1        ├       q[1]: ┤1           ├──────────┤1            ├
      └─────────┘             └────────────┘          └─────────────┘

Matrix Representation:

\[\begin{split}ECR\ q0, q1 = \frac{1}{\sqrt{2}} \begin{pmatrix} 0 & 0 & 1 & i \\ 0 & 0 & i & 1 \\ 1 & -i & 0 & 0 \\ -i & 1 & 0 & 0 \end{pmatrix}\end{split}\]

Args:

qubit1 (int):

The first qubit.

qubit2 (int):

The second qubite.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the ECRGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

iswap(qubit1, qubit2, label=None)

Implements the iSWAP gate. The iSWAP gate is a 2-qubit XX+YY interaction. This is a Clifford and symmetric gate. It swaps two qubit states and phase the \(|01\rangle\) and \(|10\rangle\) amplitudes by i.

Circuit symbol:

q[0]: ─⨂─
       │
q[1]: ─⨂─

Reference Implementation:

       ┌───┐┌───┐     ┌───┐
q[0]:  ┤ S ├┤ H ├──■──┤ X ├─────
       ├───┤└───┘┌─┴─┐└─┬─┘┌───┐
q[1]:  ┤ S ├─────┤ X ├──■──┤ H ├
       └───┘     └───┘     └───┘

Matrix Representation:

\[\begin{split}iSWAP = R_{XX+YY}\left(-\frac{\pi}{2}\right) = \exp\left(i \frac{\pi}{4} \left(X{\otimes}X+Y{\otimes}Y\right)\right) = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & i & 0 \\ 0 & i & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]

This gate is equivalent to a SWAP up to a diagonal.

\[\begin{split}iSWAP = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} . \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & i & 0 & 0 \\ 0 & 0 & i & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]

Args:

qubit1 (int):

The first qubit.

qubit2 (int):

The second qubite.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the ISwapGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

rxx(theta, qubit1, qubit2, label=None)

A parametric 2-qubit \(X \otimes X\) interaction gate (rotation about XX). This gate is symmetric, and is maximally entangling at \(\theta = \pi/2\).

Circuit symbol:

      ┌─────────┐
q[0]: ┤1        ├
      │  RXX(ϴ) │
q[1]: ┤0        ├
      └─────────┘

Matrix Representation:

\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}R_{XX}(\theta) = \exp\left(-i \th X{\otimes}X\right) = \begin{pmatrix} \cos\left(\th\right) & 0 & 0 & -i\sin\left(\th\right) \\ 0 & \cos\left(\th\right) & -i\sin\left(\th\right) & 0 \\ 0 & -i\sin\left(\th\right) & \cos\left(\th\right) & 0 \\ -i\sin\left(\th\right) & 0 & 0 & \cos\left(\th\right) \end{pmatrix}\end{split}\end{aligned}\end{align} \]

Args:

theta (float):

The θ rotational angle.

qubit1 (int):

The index number of the first qubit.

qubit2 (int):

The index number of the second qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the RxxGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

ryy(theta, qubit1, qubit2, label=None)

A parametric 2-qubit \(Y \otimes Y\) interaction gate (rotation about YY). This gate is symmetric, and is maximally entangling at \(\theta = \pi/2\).

Circuit symbol:

      ┌─────────┐
q[0]: ┤1        ├
      │  RYY(ϴ) │
q[1]: ┤0        ├
      └─────────┘

Matrix Representation:

\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}R_{YY}(\theta) = \exp\left(-i \th Y{\otimes}Y\right) = \begin{pmatrix} \cos\left(\th\right) & 0 & 0 & i\sin\left(\th\right) \\ 0 & \cos\left(\th\right) & -i\sin\left(\th\right) & 0 \\ 0 & -i\sin\left(\th\right) & \cos\left(\th\right) & 0 \\ i\sin\left(\th\right) & 0 & 0 & \cos\left(\th\right) \end{pmatrix}\end{split}\end{aligned}\end{align} \]

Args:

theta (float):

The θ rotational angle.

qubit1 (int):

The index number of the first qubit.

qubit2 (int):

The index number of the second qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the RyyGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

rzx(theta, qubit1, qubit2, label=None)

A parametric 2-qubit \(Z \otimes X\) interaction gate (rotation about ZX). This gate is symmetric, and is maximally entangling at \(\theta = \pi/2\). The cross-resonance gate (CR) for superconducting qubits implements a ZX interaction (however other terms are also present in an experiment).

Circuit symbol:

      ┌─────────┐
q[0]: ┤1        ├
      │  RZX(ϴ) │
q[1]: ┤0        ├
      └─────────┘

Matrix Representation:

\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}R_{ZX}(\theta)\ q0, q1 = \exp\left(-i \frac{\theta}{2} X{\otimes}Z\right) = \begin{pmatrix} \cos\left(\th\right) & 0 & -i\sin\left(\th\right) & 0 \\ 0 & \cos\left(\th\right) & 0 & i\sin\left(\th\right) \\ -i\sin\left(\th\right) & 0 & \cos\left(\th\right) & 0 \\ 0 & i\sin\left(\th\right) & 0 & \cos\left(\th\right) \end{pmatrix}\end{split}\end{aligned}\end{align} \]

Args:

theta (float):

The θ rotational angle.

qubit1 (int):

The index number of the first qubit.

qubit2 (int):

The index number of the second qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the RzxGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

rzz(theta, qubit1, qubit2, label=None)

A parametric 2-qubit \(Z \otimes Z\) interaction gate (rotation about ZZ). This gate is symmetric, and is maximally entangling at \(\theta = \pi/2\). The cross-resonance gate (CR) for superconducting qubits implements a ZX interaction (however other terms are also present in an experiment).

Circuit symbol:

q[0]: ───■────
         │zz(θ)
q[1]: ───■────

Matrix Representation:

\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}R_{ZZ}(\theta) = \exp\left(-i \th Z{\otimes}Z\right) = \begin{pmatrix} e^{-i \th} & 0 & 0 & 0 \\ 0 & e^{i \th} & 0 & 0 \\ 0 & 0 & e^{i \th} & 0 \\ 0 & 0 & 0 & e^{-i \th} \end{pmatrix}\end{split}\end{aligned}\end{align} \]

This gate is a direct sum of RZ rotations, so this gate is equivalent to a uniformly controlled (multiplexed) RZ gate:

\[\begin{split}R_{ZZ}(\theta) = \begin{pmatrix} RZ(\theta) & 0 \\ 0 & RZ(-\theta) \end{pmatrix}\end{split}\]

Args:

theta (float):

The θ rotational angle.

qubit1 (int):

The index number of the first qubit.

qubit2 (int):

The index number of the second qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the RzzGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

swap(qubit1, qubit2, label=None)

This Clifford gate is symmetric. Swaps the state and phase of the provided qubits.

\[|a, b\rangle \rightarrow |b, a\rangle\]

Circuit symbol:

q[0]: ─X─
       │
q[1]: ─X─

Matrix Representation:

\[\begin{split}SWAP = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]

Args:

qubit1 (int):

The index number of the first qubit.

qubit2 (int):

The index number of the second qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the SwapGate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

cu1(lam, control_qubit, target_qubit, label=None)

Controlled-U1 gate. This gate is diagonal and symmetric gate. It induces a phase on the state of the target qubit, depending on the control state.

Circuit symbol:

q[0]: ─■──
       │λ
q[1]: ─■──

Matrix Representation:

\[ \begin{align}\begin{aligned}\begin{split}CU1(\lambda) = I \otimes |0\rangle\langle 0| + U1 \otimes |1\rangle\langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & e^{i\lambda} \end{pmatrixambda} \\end{pmatrix}\end{split}\\ Args:\\lam (float): The `\λ` rotational angle.\\control_quit (int): The index number of the control qubit.\\target_quit (int): The index number of the target qubit.\\label (Optional[str]): A label text for the gate. If provided, it is used by the circuit visualizer.\end{aligned}\end{align} \]
Returns:

A handle to the CU1Gate if successful.

Raises:

OutOfRangeError: If the index of any of the qubits exceed declaration.

cu3(theta, phi, lam, control_qubit, target_qubit, label=None)

This is a controlled version of the three parameter U3 gate.

Circuit symbol:

q[0]: ──────■──────
      ┌─────┴─────┐
q[1]: ┤ U3(ϴ,φ,λ) ├
      └───────────┘

Matrix Representation:

\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}CU3(\theta, \phi, \lambda)\ q0, q1 = I \otimes |0 \rangle \langle 0| + U3(\theta,\phi,\lambda) \otimes |1 \rangle \langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos(\th) & 0 & -e^{i\lambda}\sin(\th) \\ 0 & 0 & 1 & 0 \\ 0 & e^{i\phi}\sin(\th) & 0 & e^{i(\phi+\lambda)}\cos(\th) \end{pmatrix}\end{split}\end{aligned}\end{align} \]

See also:

QuantumCircuits.cu()

Args:

theta (float):

The θ rotational angle.

phi (float):

The φ rotational angle.

lam (float):

The λ rotational angle.

control_quit (int):

The index number of the control qubit.

target_quit (int):

The index number of the target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CU3Gate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

ccx(control_qubit1, control_qubit2, target_qubit, label=None)

Implements the doubly controlled NOT gate. The CCX gate is also known as Toffoli gate.

Circuit symbol:

q[0]: ──■──
        │
q[1]: ──■──
      ┌─┴─┐
q[2]: ┤ X ├
      └───┘

Matrix Representation:

\[\begin{split}CCX q0, q1, q2 = I \otimes I \otimes |0 \rangle \langle 0| + CX \otimes |1 \rangle \langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \end{pmatrix}\end{split}\]

Args:

control_quit1 (int):

The index number of the first control qubit.

control_quit2 (int):

The index number of the second control qubit.

target_quit (int):

The index number of the target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CXXGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

ccz(control_qubit1, control_qubit2, target_qubit, label=None)

Implements the doubly controlled Z gate.

Circuit symbol:

q[0]: ─■─
       │
q[1]: ─■─
       │
q[2]: ─■─

Matrix Representation:

\[\begin{split}CCZ\ q[0], q[1], q[2] = I \otimes I \otimes |0\rangle\langle 0| + CZ \otimes |1\rangle\langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & -1 \end{pmatrix}\end{split}\]

Args:

control_quit1 (int):

The index number of the first control qubit.

control_quit2 (int):

The index number of the second control qubit.

target_quit (int):

The index number of the target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CCZGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

cswap(control_qubit, target_qubit1, target_qubit2, label=None)

Implements the controlled SWAP gate. The Controlled-SWAP gate is also known as the Fredkin gate. This gate swaps the states of the two target qubits if the control qubit is in the \(|1\rangle\) state.

\[\begin{split}|0, b, c\rangle \rightarrow |0, b, c\rangle \\ |1, b, c\rangle \rightarrow |1, c, b\rangle\end{split}\]

Circuit symbol:

q[0]: ─■─
       │
q[1]: ─X─
       │
q[2]: ─X─

Matrix Representation:

\[\begin{split}CSWAP\ q0, q1, q2 = I \otimes I \otimes |0 \rangle \langle 0| + SWAP \otimes |1 \rangle \langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{pmatrix}\end{split}\]

Args:

control_quit (int):

The index number of the control qubit.

target_quit1 (int):

The index number of the first target qubit.

target_quit2 (int):

The index number of the second target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CSwapGate if successful.

See also:

QuantumCircuit.fredkin()

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

fredkin(control_qubit, target_qubit1, target_qubit2, label=None)

Implements the controlled SWAP gate. This gate swaps the states of the two target qubits if the control qubit is in the \(|1\rangle\) state.

\[\begin{split}|0, b, c\rangle \rightarrow |0, b, c\rangle \\ |1, b, c\rangle \rightarrow |1, c, b\rangle\end{split}\]

Circuit symbol:

q[0]: ─■─
       │
q[1]: ─X─
       │
q[2]: ─X─

Matrix Representation:

\[\begin{split}CSWAP\ q0, q1, q2 = I \otimes I \otimes |0 \rangle \langle 0| + SWAP \otimes |1 \rangle \langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{pmatrix}\end{split}\]

Args:

control_quit (int):

The index number of the control qubit.

target_quit1 (int):

The index number of the first target qubit.

target_quit2 (int):

The index number of the second target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CSwapGate if successful.

See also:

QuantumCircuit.cswap()

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

toffoli(control_qubit1, control_qubit2, target_qubit, label=None)

Implements the doubly controlled NOT gate. The Toffoli gate is also known as the CCX gate

See also:

QuantumCircuit.ccx()

Circuit symbol:

q[0]: ──■──
        │
q[1]: ──■──
      ┌─┴─┐
q[2]: ┤ X ├
      └───┘

Matrix Representation:

\[\begin{split}CCX q0, q1, q2 = I \otimes I \otimes |0 \rangle \langle 0| + CX \otimes |1 \rangle \langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \end{pmatrix}\end{split}\]

Args:

control_quit1 (int):

The index number of the first control qubit.

control_quit2 (int):

The index number of the second control qubit.

target_quit (int):

The index number of the target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the CCXGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

rccx(control_qubit1, control_qubit2, target_qubit, label=None)

This gate implements the Toffoli gate up to relative phases.

Args:

control_quit1 (int):

The index number of the first control qubit.

control_quit2 (int):

The index number of the second control qubit.

target_quit (int):

The index number of the target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the RccxGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration or mismatched.

pauli(qubit_list, pauli_operator, label=None)

Implements multi-qubit Pauli gate. The provided list of pauli operators are applied to the list of qubits provided.

Example:

>>> qc.pauli([0, 1, 2], "XXI") # implements `X` gates on qubits `0` and `1`, and an `I` gate on qubit `2`.

Args:

qubit_list ([int]):

The list of qubits.

pauli_operator (str):

A string of characters corresponding to the Pauli operator for the specific qubit in the list.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the PauliGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration or if there is a mismatch of parameters.

reset(qubit, label=None)

Resets the qubit(s) to their default state.

Args:
qubit (int | [int]):

A qubit to be reset or the list of qubits to be reset.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the ResetGate if successful.

Raises:

OutOfRangeError:

If the index of any of the qubits exceed declaration.

depth()

Return circuit depth (that is, thelength of critical path).

Args:

None

Returns:

int

Raises:

None

width()

Return number of qubits and the classical bits in circuit..

Args:

None

Returns:

int

Raises:

None

size()

Returns total number of instructions in circuit.

Args:

None

Returns:

int

Raises:

None

clear()

Deletes all gates and operations in the quantum circuit.

Args:

None

Returns:

int

Raises:

None

barrier(qubit_list=None, label=None)

Inserts a new barrier instruction into the circuit.

A barrier is a visual indicator of the grouping of a circuit section. It also acts as a directive for circuit compilation to separate pieces of a circuit so that any optimizations or re-writes are constrained to only act between barriers.

Args:
qubit_list (Optional [int]):

The list of qubits.

label (str):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

None

Raises:

OutOfRangeError:

If the index of any of the qubits exceed declaration.

measure(qubit, classical_bit=None, label=None)

Measure a qubit in the Z basis into a classical bit.

When a quantum state is measured, a qubit is projected in the computational (Pauli Z) basis to either \(\lvert 0 \rangle\) or \(\lvert 1 \rangle\). The classical bit cbit indicates the result of that projection as a 0 or a 1 respectively. This operation is non-reversible.

Circuit symbol:

    ┌─┐
q:  ┤M├
    └╥┘
c:1/═╩═
     0
Args:
qubit (int):

The index number of the qubit to be measured.

classical_bit (Optional[int]):

The index number of the corresponding classical bit to which the measurement is projected.

label (str): A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the MeasureGate if successful.

Raises:

OutOfRangeError:

If the index of the qubit or the classical bit exceed declaration or if there is a mismatch of parameters.

measure_all(label=None)

Adds in-place measurement to all qubits. Projections are made to the corresponding classical bits. Classical bits are added, if required.

Args:

label (str):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the MeasureGate if successful.

Raises:

None

measure_active(label=None)

Adds in-place measurement to all non-idle qubits. Projections are made to the corresponding classical bits. Classical bits are added, if required.

Args:
label (str):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the MeasureGate if successful.

Raises:

None

qasm(formatted=False, filename='', encoding='')

Provides a translation of the circuit in to an equivalent QASM 2.0 code.

Args:

formatted (bool):

True - Prints the equivalent code on the console. False - no actions.

filename (str):

If provided, saves the equivalent QASM 2.0 code into the file.

encoding (str):

Parameter unused.

Returns:

str - Equivalent QASM 2.0 code.

Raises:

RunTimeError - if any of the circuit parameters are not in the range.

draw(output, scale, CString, style, interactive, plot_barriers, reverse_bits, justify, vertical_compression, idle_wires, with_layout, fold, initial_state, cregbundle, wire_order)

Draws the composed quantum circuit.

Args:

output (Optional[str]):

Selects the output method to use for drawing the circuit. Currently only “text” is supported.

scale (Optional[float]):

Unused.

filename (Optional[str]):

File name to save the image to. Defaults to None.

style (Optional[dict]):

Currently unused.

interactive (Optional[bool]):

Currently unused.

reverse_bits (Optional[bool]):

Currently unused.

plot_barriers (Optional[bool]):

True - Draws the barrier gate. (Default) False - Disables the drawing of the barrier gate.

justify (Optional[str]):

Currently unused.

vertical_compression (Optional[str]):

Currently unused.

idle_wires (Optional[bool]):

Currently unused.

with_layout (Optional[bool]):

Currently unused.

fold (Optional[int]):

Sets the column size for pagination. When set to -1, this feature is disabled. The default column size is 80. Note that, the column size is approximate.

initial_state (Optional[bool]):

True - Adds \(|0>\) in the beginning of the wire. False - Does not add. (Default)

cregbundle (Optional[bool]):

Currently unused.

wire_order (Optional[list]):

A list of integers used to reorder the display of the bits. Currently unused.

Returns:

None.

Raises:

RunTimeError - if any of the circuit parameters are not in the range.

mcp(lam, control_qubits, target_qubit, label=None)

Implements multi-controlled phase gate

Args:

lam (float):

The rotational angle.

control_qubits ([int]):

The list of control qubits.

target_quit (int):

The index number of the target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the MCPGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

RunTimeError:

If there is a problem with ordering of qubits.

mcrx(theta, control_qubits, target_qubit, use_basis_gates=False, label=None)

Implements multi-controlled X rotation gate

Args:

theta (float):

The rotational angle.

control_qubits ([int]):

The list of control qubits.

target_quit (int):

The index number of the target qubit.

use_basis_gates (bool):

Whether to decompose the circuit using basis gates. Unused currently.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the MCRXGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

RunTimeError:

If there is a problem with ordering of qubits.

mcry(theta, control_qubits, target_qubit, use_basis_gates=False, label=None)

Implements multi-controlled Y rotation gate

Args:

theta (float):

The rotational angle.

control_qubits ([int]):

The list of control qubits.

target_quit (int):

The index number of the target qubit.

use_basis_gates (bool):

Whether to decompose the circuit using basis gates. Unused currently.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the MCRYGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

RunTimeError:

If there is a problem with ordering of qubits.

mcrz(lam, control_qubits, target_qubit, use_basis_gates=False, label=None)

Implements multi-controlled Z rotation gate

Args:

lam (float):

The rotational angle.

control_qubits ([int]):

The list of control qubits.

target_quit (int):

The index number of the target qubit.

use_basis_gates (bool):

Whether to decompose the circuit using basis gates. Unused currently.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the MCRZGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

RunTimeError:

If there is a problem with ordering of qubits.

mct(control_qubits, target_qubit, ancilla_qubits=None, mode='noancilla', label=None)

Implements multi-controlled CX gate

See also:

QuantumCircuit.mcx()

Args:

control_qubits ([int]):

The list of control qubits.

target_quit (int):

The index number of the target qubit.

ancilla_qubits ([int]):

The list of ancilla qubits. Currently, unused.

mode (str):

The mode of decomposition to be used for this gate. Currently only “noancilla” is supported.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the MCXGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

RunTimeError:

If there is a problem with ordering of qubits.

mcx(control_qubits, target_qubit, ancilla_qubits=None, mode='noancilla', label=None)

Implements multi-controlled CX gate

See also:

QuantumCircuit.mct()

Args:

control_qubits ([int]):

The list of control qubits.

target_quit (int):

The index number of the target qubit.

ancilla_qubits ([int]):

The list of ancilla qubits. Currently, unused.

mode (str):

The mode of decomposition to be used for this gate. Currently only “noancilla” is supported.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the MCXGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

RunTimeError:

If there is a problem with ordering of qubits.

ms(theta, qubit_list, label=None)

Implements the Global Mølmer–Sørensen gate.

See also:

QuantumCircuit.gms()

Args:

theta (float):

The rotational angle.

qubit_list ([int]):

The list of qubits.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the GMSGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

RunTimeError:

If there is a problem with ordering of qubits.

gms(theta, qubit_list, label=None)

Implements the Global Mølmer–Sørensen gate.

See also:

QuantumCircuit.ms()

Args:

theta (float):

The rotational angle.

qubit_list ([int]):

The list of qubits.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the GMSGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

RunTimeError:

If there is a problem with ordering of qubits.

rcccx(control_qubit1, control_qubit2, control_qubit3, target_qubit, label=None)

Implements the relative phase, three controlled X gate.

See also:

QuantumCircuit.rc3x()

Args:

control_qubit1 (int):

Index to the first control qubit.

control_qubit2 (int):

Index to the first second qubit.

control_qubit3 (int):

Index to the third control qubit.

target_quit (int):

The index number of the target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the RcccxGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

RunTimeError:

If there is a problem with ordering of qubits.

rc3x(control_qubit1, control_qubit2, control_qubit3, target_qubit, label=None)

Implements the relative phase, three controlled X gate.

See also:

QuantumCircuit.rcccx()

Args:

control_qubit1 (int):

Index to the first control qubit.

control_qubit2 (int):

Index to the first second qubit.

control_qubit3 (int):

Index to the third control qubit.

target_quit (int):

The index number of the target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the Rc3xGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

RunTimeError:

If there is a problem with ordering of qubits.

c3sqrtx(control_qubit1, control_qubit2, control_qubit3, target_qubit, label=None)

Implements the three controlled square root of X gate.

Args:

control_qubit1 (int):

Index to the first control qubit.

control_qubit2 (int):

Index to the first second qubit.

control_qubit3 (int):

Index to the third control qubit.

target_quit (int):

The index number of the target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the C3sqrtxGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

RunTimeError:

If there is a problem with ordering of qubits.

c3x(control_qubit1, control_qubit2, control_qubit3, target_qubit, label=None)

Implements the three controlled X gate.

Args:

control_qubit1 (int):

Index to the first control qubit.

control_qubit2 (int):

Index to the first second qubit.

control_qubit3 (int):

Index to the third control qubit.

target_quit (int):

The index number of the target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the C3xGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

RunTimeError:

If there is a problem with ordering of qubits.

c4x(control_qubit1, control_qubit2, control_qubit3, control_qubit4, target_qubit, label=None)

Implements the four controlled X gate.

Args:

control_qubit1 (int):

Index to the first control qubit.

control_qubit2 (int):

Index to the first second qubit.

control_qubit3 (int):

Index to the third control qubit.

control_qubit4 (int):

Index to the forth control qubit.

target_quit (int):

The index number of the target qubit.

label (Optional[str]):

A label text for the gate. If provided, it is used by the circuit visualizer.

Returns:

A handle to the C4xGate if successful.

Raises:
OutOfRangeError:

If the index of any of the qubits exceed declaration.

RunTimeError:

If there is a problem with ordering of qubits.

append(qc, qubits_vector, cbits_vector)

Appends a quantum circuit to the current quantum circuit.

Args:

qc (QuantumCircuit or Gate):

QuantumCircuit or Gate to be appended.

qubits_vector ([int]):

The list of qubits in the order they are to be permuted.

cbits_vector ([int]):

The list of classical register bits in the order they are to be permuted.

Returns:

None

Raises:
RunTimeError:

If there is a problem with ordering of qubits.

compose(other, qubits=None, clbits=None, front=False, inplace=False, wrap=False)

Composes a quantum circuit by attaching the provided quantum circuit to the front or at the back.

Args:

other (QuantumCircuit or Gate):

QuantumCircuit or Gate to be added.

qubits (Optional[int]):

The list of qubits in the order they are to be permuted. If none provided, the default list is generated.

cbits (Optional[int]):

The list of classical register bits in the order they are to be permuted. If none provided, the default list is generated.

front (Optional(bool)):
default: False – Adds the new circuit to the end of the current circuit.

True – Adds the new circuit to the front of the current circuit.

inplace (Optional(bool)):
default: False – A new composed circuit is returned .

True – The composition is inplace.

wrap (Optional(bool)):

Currently unused.

Returns:

The composed quantum circuit, if in case the composition is not inplace.

Raises:
RunTimeError:

If there is a problem with ordering of qubits.

copy(name) QuantumCircuit

Creates a deep copy of the quantum circuit.

Args:
name (Optional(str)):

The name, if provided, to be used for the new circuit. Otherwise, the existing name is used.

Returns:

A copy of the quantum circuit.

Raises:
RunTimeError:

If there is a problem creating a copy of the quantum circuit.

copy_empty_like(name) QuantumCircuit

Return a copy of the quantum circuit, excepting for the quantum gates

Args:
name (Optional(str)):

The name, if provided, to be used for the new circuit. Otherwise, the existing name is used.

Returns:

A copy of the quantum circuit.

Raises:
RunTimeError:

If there is a problem creating a copy of the quantum circuit.

count_ops() dict

Returns a count of each type of instructions ( quantum gates ) in the quantum circuit.

Args:

None.

Returns:

A count of each type of instructions ( quantum gates ) in the quantum circuit.

Raises:

None.

cls_instances() int

Returns the total number of quantum circuit instances created so far.

Args:

None.

Returns:

Total number of quantum circuit instances created so far.

Raises:

None.

cls_prefix() str

Returns the prefix used for automatic naming of the quantum circuits.

Args:

None.

Returns:

Returns the prefix used for automatic naming of the quantum circuits.

Raises:

None.

from_qasm_file(path) QuantumCircuit

Composes a quantum circuit from the OPENQASM2.0 file provided.

Args:

path (str):

The full path of the OPENQASM2.0.

See also:

qasm2.load()

Returns:

The composed quantum circuit.

Raises:
RunTimeError:

If there is a problem with the instructions contained in the OPENQASM2.0 file.

from_qasm_str(qasm_str) QuantumCircuit

Composes a quantum circuit from the OPENQASM2.0 string provided.

Args:

qasm_str (str):

A string variable containing OPENQASM2.0 instructions as a string.

See also:

qasm2.load()

Returns:

The composed quantum circuit.

Raises:
RunTimeError:

If there is a problem with the instructions contained in the OPENQASM2.0 file.

has_register(args) bool

Checks whether the provided QuantumRegister, AncillaRegister or the ClassicalRegister is part of the QuantumCircuit

Args:

args(args):

A QuantumRegister, AncillaRegister or a ClassicalRegister.

Returns:

True - If the provided register is part of the QuantumCircuit. False - Otherwose

Raises:

None.

inverse(annotated=False) QuantumCircuit

Returns an inverse (adjoint) of the quantum circuit.

Args:

annotated (bool) :

Currently unused.

Returns:

The inverted quantum circuit.

Raises:
RunTimeError:

If there is a problem inverting the gates..

num_connected_components(unitary_only=False) int

Returns the total number of non-entangled subcircuits the circuit be factored to.

Args:

unitary_only (Optional(bool):

Currently unused.

Returns:

the total number of non-entangled subcircuits the circuit be factored to

Raises:

None.

num_nonlocal_gates() int

Returns the total number of gates using 2 or more qubits.

Args:

None.

Returns:

total number of gates using 2 or more qubits.

Raises:

None

num_unitary_factors() int

Returns the number of tensor factors in the circuit.

Args:

None.

Returns:

The number of tensor factors.

Raises:

None.

num_tensor_factors() int

Returns the number of tensor factors in the circuit.

Args:

None.

Returns:

Returns the number of tensor factors in the circuit.

Raises:

None.

qubit_duration(qubit) float

Finds the difference between the first and last instructions involving the qubit.

Args:
qubit (int):

The quit for which the time duration is to be calculated

Returns:

The duration of the qubit.

Raises:

None;

qubit_start_time(qubit) float

Returns the time pertaining to the start time of the first instruction involving the provided qubit. This function is typicaly called after the execution of the circuit

Args:
qubit (int):

The quit for which the start-time is to be obtained.

Returns:

The start time of the qubit.

Raises:

None.

qubit_end_time(qubit) float

Returns the time pertaining to the end time of the last instruction involving the provided qubit. This function is typicaly called after the execution of the circuit

Args:
qubit (int):

The quit for which the end-time is to be obtained.

Returns:

The end-time of the qubit.

Raises:

None.

remove_final_measurements(inplace=True) QuantumCircuit

Removes the barrier and measurement instructions at the end of the circuit.

Args:

inplace (bool):

default - True - The circuit is modified inplace. False - a copy of the circuit is created and the copy modified.

Returns:

The copy of the circuit after the barrier and measurement instructions at the end removed, if inplace is false. None if the parameter inplace is true.

Raises:
RunTimeError:

If there is a problem processing the request.

repeat(reps) QuantumCircuit

Composes a new quantum circuit by repeating the current quantum circuit reps times.

Args:

reps (int):

The number of times the circuit is to be repeated.

Returns:

The composed quantum circuit.

Raises:
RunTimeError:

If there is a problem processing the request.

reverse_bits() QuantumCircuit

Composes a new quantum circuit by flipping the order of the qubits.

Args:

None.

Returns:

Quantum circuit with the qubit order reversed.

Raises:
RunTimeError:

If there is a problem processing the request.

reverse_ops() QuantumCircuit

Composes a quantum circuit by reversing the order of the instructions.

Args:

None.

Returns:

Quantum circuit with the instructions reversed in order.

Raises:
RunTimeError:

If there is a problem processing the request.

to_gate(param_vector, label) Gate

Converts a quantum circuit into a gate.

Args:

param_vector ([float]) - An optional parameter vector. Currently not supported. label (str) - A name for the gate

Returns:

Quantum Gate composed of the quantum circuit provided.

Raises:
RunTimeError:

If there is a problem processing the request.

control(num_ctrl_qubits, label, ctrl_state, annotated) QuantumCircuit

Converts a quantum circuit into a controlled circuit with the specified number of control qubits. Note that the total number of qubits are increased by the specified number of control qubits.

Args:

num_ctrl_qubits (int) - Total number of control qubits to be added. label (str) - An optional name for the new quantum circuit. ctrl_state (str) - unused annotated - unused.

Returns:

Quantum Circuit with the controls added.

Raises:
RunTimeError:

If there is a problem processing the request.

assign_parameters(dict_parameters, inplace, flat_input, strict) QuantumCircuit

Assigns the parameters into a parameterized quantum circuit. Note that all the required parameters must be combined into one dictinary and passed to the API.

Args:

inplace (bool) - If set to True, the current quantum circuit is assigned with the parameters. flat_input (bool) - unused. strict (bool) - unused

Returns:

Quantum Circuit with the applied parameters, if in case inplace is False.

Raises:
RunTimeError:

If there is a problem processing the request.