quairkit.operator.gate.multi_qubit_gate

The source file of the classes for multi-qubit gates.

class quairkit.operator.gate.multi_qubit_gate.CNOT(qubits_idx=None, cnot_idx=None)

A collection of CNOT gates.

For a 2-qubit quantum circuit, when qubits_idx is [0, 1], the matrix form of such a gate is:

\[\begin{split}\begin{align} CNOT &=|0\rangle \langle 0|\otimes I + |1 \rangle \langle 1|\otimes X\\ &= \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{bmatrix} \end{align}\end{split}\]
Parameters:
qubits_idx : Iterable | int | str | None

Indices of the qubits on which the gates are applied. Defaults to the first two qubits.

cnot_idx : List[int] | None

CNOT gate index. Defaults to None.

quairkit.operator.gate.multi_qubit_gate.CX

alias of CNOT

class quairkit.operator.gate.multi_qubit_gate.CY(qubits_idx=None)

A collection of controlled Y gates.

For a 2-qubit quantum circuit, when qubits_idx is [0, 1], the matrix form of such a gate is:

\[\begin{split}\begin{align} CY &=|0\rangle \langle 0|\otimes I + |1 \rangle \langle 1|\otimes Y\\ &= \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & -1j \\ 0 & 0 & 1j & 0 \end{bmatrix} \end{align}\end{split}\]
Parameters:
qubits_idx : Iterable | int | str | None

Indices of the qubits on which the gates are applied. Defaults to the first two qubits.

class quairkit.operator.gate.multi_qubit_gate.CZ(qubits_idx=None)

A collection of controlled Z gates.

For a 2-qubit quantum circuit, when qubits_idx is [0, 1], the matrix form of such a gate is:

\[\begin{split}\begin{align} CZ &=|0\rangle \langle 0|\otimes I + |1 \rangle \langle 1|\otimes Z\\ &= \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{bmatrix} \end{align}\end{split}\]
Parameters:
qubits_idx : Iterable | int | str | None

Indices of the qubits on which the gates are applied. Defaults to the first two qubits.

class quairkit.operator.gate.multi_qubit_gate.SWAP(qubits_idx=None)

A collection of SWAP gates.

The matrix form of such a gate is:

\[\begin{split}\begin{align} SWAP = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \end{align}\end{split}\]
Parameters:
qubits_idx : Iterable | int | str | None

Indices of the qubits on which the gates are applied. Defaults to the first two qubits.

class quairkit.operator.gate.multi_qubit_gate.CP(qubits_idx=None, param=None, param_sharing=False)

A collection of controlled P gates.

For a 2-qubit quantum circuit, when qubits_idx is [0, 1], the matrix form of such a gate is:

\[\begin{split}\begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & e^{i\theta} \end{bmatrix}\end{split}\]
Parameters:
qubits_idx : Iterable | str | None

Indices of the qubits on which the gates are applied. Defaults to the first two qubits.

param : Tensor | float | None

Parameters of the gates. Defaults to None.

param_sharing : bool | None

Whether gates in the same layer share a parameter. Defaults to False.

Raises:

ValueError – The param must be torch.Tensor or float.

class quairkit.operator.gate.multi_qubit_gate.CRX(qubits_idx=None, param=None, param_sharing=False)

A collection of controlled rotation gates about the x-axis.

For a 2-qubit quantum circuit, when qubits_idx is [0, 1], the matrix form of such a gate is:

\[\begin{split}\begin{align} CRx &=|0\rangle \langle 0|\otimes I + |1 \rangle \langle 1|\otimes Rx\\ &= \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} \\ 0 & 0 & -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{bmatrix} \end{align}\end{split}\]
Parameters:
qubits_idx : Iterable | str | None

Indices of the qubits on which the gates are applied. Defaults to the first two qubits.

param : Tensor | float | None

Parameters of the gates. Defaults to None.

param_sharing : bool | None

Whether gates in the same layer share a parameter. Defaults to False.

Raises:

ValueError – The param must be torch.Tensor or float.

class quairkit.operator.gate.multi_qubit_gate.CRY(qubits_idx=None, param=None, param_sharing=False)

A collection of controlled rotation gates about the y-axis.

For a 2-qubit quantum circuit, when qubits_idx is [0, 1], the matrix form of such a gate is:

\[\begin{split}\begin{align} CRy &=|0\rangle \langle 0|\otimes I + |1 \rangle \langle 1|\otimes Ry\\ &= \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \cos\frac{\theta}{2} & -\sin\frac{\theta}{2} \\ 0 & 0 & \sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{bmatrix} \end{align}\end{split}\]
Parameters:
qubits_idx : Iterable | str | None

Indices of the qubits on which the gates are applied. Defaults to the first two qubits.

param : Tensor | float | None

Parameters of the gates. Defaults to None.

param_sharing : bool | None

Whether gates in the same layer share a parameter. Defaults to False.

Raises:

ValueError – The param must be torch.Tensor or float.

class quairkit.operator.gate.multi_qubit_gate.CRZ(qubits_idx=None, param=None, param_sharing=False)

A collection of controlled rotation gates about the z-axis.

For a 2-qubit quantum circuit, when qubits_idx is [0, 1], the matrix form of such a gate is:

\[\begin{split}\begin{align} CRz &=|0\rangle \langle 0|\otimes I + |1 \rangle \langle 1|\otimes Rz\\ &= \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & e^{-i\frac{\theta}{2}} & 0 \\ 0 & 0 & 0 & e^{i\frac{\theta}{2}} \end{bmatrix} \end{align}\end{split}\]
Parameters:
qubits_idx : Iterable | str | None

Indices of the qubits on which the gates are applied. Defaults to the first two qubits.

param : Tensor | float | None

Parameters of the gates. Defaults to None.

param_sharing : bool | None

Whether gates in the same layer share a parameter. Defaults to False.

Raises:

ValueError – The param must be torch.Tensor or float.

class quairkit.operator.gate.multi_qubit_gate.CU(qubits_idx=None, param=None, param_sharing=False)

A collection of controlled single-qubit rotation gates.

For a 2-qubit quantum circuit, when qubits_idx is [0, 1], the matrix form of such a gate is:

\[\begin{split}\begin{align} CU &= \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & e^{i\gamma}\cos\frac\theta2 &-e^{i(\lambda+\gamma)}\sin\frac\theta2 \\ 0 & 0 & e^{i(\phi+\gamma)}\sin\frac\theta2&e^{i(\phi+\lambda+\gamma)}\cos\frac\theta2 \end{bmatrix} \end{align}\end{split}\]
Parameters:
qubits_idx : Iterable | str | None

Indices of the qubits on which the gates are applied. Defaults to the first two qubits.

param : Tensor | float | None

Parameters of the gates. Defaults to None.

param_sharing : bool | None

Whether gates in the same layer share a parameter. Defaults to False.

Raises:

ValueError – The param must be torch.Tensor or float.

class quairkit.operator.gate.multi_qubit_gate.RXX(qubits_idx=None, param=None, param_sharing=False)

A collection of RXX gates.

The matrix form of such a gate is:

\[\begin{split}\begin{align} RXX(\theta) = \begin{bmatrix} \cos\frac{\theta}{2} & 0 & 0 & -i\sin\frac{\theta}{2} \\ 0 & \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} & 0 \\ 0 & -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} & 0 \\ -i\sin\frac{\theta}{2} & 0 & 0 & \cos\frac{\theta}{2} \end{bmatrix} \end{align}\end{split}\]
Parameters:
qubits_idx : Iterable | str | None

Indices of the qubits on which the gates are applied. Defaults to the first two qubits.

param : Tensor | float | None

Parameters of the gates. Defaults to None.

param_sharing : bool | None

Whether gates in the same layer share a parameter. Defaults to False.

Raises:

ValueError – The param must be torch.Tensor or float.

class quairkit.operator.gate.multi_qubit_gate.RYY(qubits_idx=None, param=None, param_sharing=False)

A collection of RYY gates.

The matrix form of such a gate is:

\[\begin{split}\begin{align} RYY(\theta) = \begin{bmatrix} \cos\frac{\theta}{2} & 0 & 0 & i\sin\frac{\theta}{2} \\ 0 & \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} & 0 \\ 0 & -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} & 0 \\ i\sin\frac{\theta}{2} & 0 & 0 & cos\frac{\theta}{2} \end{bmatrix} \end{align}\end{split}\]
Parameters:
qubits_idx : Iterable | str | None

Indices of the qubits on which the gates are applied. Defaults to the first two qubits.

param : Tensor | float | None

Parameters of the gates. Defaults to None.

param_sharing : bool | None

Whether gates in the same layer share a parameter. Defaults to False.

Raises:

ValueError – The param must be torch.Tensor or float.

class quairkit.operator.gate.multi_qubit_gate.RZZ(qubits_idx=None, param=None, param_sharing=False)

A collection of RZZ gates.

The matrix form of such a gate is:

\[\begin{split}\begin{align} RZZ(\theta) = \begin{bmatrix} e^{-i\frac{\theta}{2}} & 0 & 0 & 0 \\ 0 & e^{i\frac{\theta}{2}} & 0 & 0 \\ 0 & 0 & e^{i\frac{\theta}{2}} & 0 \\ 0 & 0 & 0 & e^{-i\frac{\theta}{2}} \end{bmatrix} \end{align}\end{split}\]
Parameters:
qubits_idx : Iterable | str | None

Indices of the qubits on which the gates are applied. Defaults to the first two qubits.

param : Tensor | float | None

Parameters of the gates. Defaults to None.

param_sharing : bool | None

Whether gates in the same layer share a parameter. Defaults to False.

Raises:

ValueError – The param must be torch.Tensor or float.

class quairkit.operator.gate.multi_qubit_gate.MS(qubits_idx=None)

A collection of Mølmer-Sørensen (MS) gates for trapped ion devices.

The matrix form of such a gate is:

\[\begin{split}\begin{align} MS = RXX(-\frac{\pi}{2}) = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 0 & 0 & i \\ 0 & 1 & i & 0 \\ 0 & i & 1 & 0 \\ i & 0 & 0 & 1 \end{bmatrix} \end{align}\end{split}\]
Parameters:
qubits_idx : Iterable | int | str | None

Indices of the qubits on which the gates are applied. Defaults to the first two qubits.

class quairkit.operator.gate.multi_qubit_gate.CSWAP(qubits_idx=None)

A collection of CSWAP (Fredkin) gates.

The matrix form of such a gate is:

\[\begin{split}\begin{align} CSWAP = \begin{bmatrix} 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 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \end{bmatrix} \end{align}\end{split}\]
Parameters:
qubits_idx : Iterable | int | str | None

Indices of the qubits on which the gates are applied. Defaults to the first three qubits.

class quairkit.operator.gate.multi_qubit_gate.CCX(qubits_idx=None)

A collection of CCX (Toffoli) gates.

The matrix form of such a gate is:

\[\begin{split}\begin{align} \begin{bmatrix} 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 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{bmatrix} \end{align}\end{split}\]
Parameters:
qubits_idx : Iterable | int | str | None

Indices of the qubits on which the gates are applied. Defaults to the first three qubits.

quairkit.operator.gate.multi_qubit_gate.Toffoli

alias of CCX

class quairkit.operator.gate.multi_qubit_gate.UniversalTwoQubits(qubits_idx=None, param=None, param_sharing=False)

A collection of universal two-qubit gates. One of such a gate requires 15 parameters.

Parameters:
qubits_idx : Iterable | str | None

Indices of the qubits on which the gates are applied. Defaults to the first two qubits.

param : Tensor | float | None

Parameters of the gates. Defaults to None.

param_sharing : bool | None

Whether gates in the same layer share a parameter. Defaults to False.

Raises:

ValueError – The param must be torch.Tensor or float.

class quairkit.operator.gate.multi_qubit_gate.UniversalThreeQubits(qubits_idx=None, param=None, param_sharing=False)

A collection of universal three-qubit gates. One of such a gate requires 81 parameters.

Parameters:
qubits_idx : Iterable | str | None

Indices of the qubits on which the gates are applied. Defaults to the first three qubits.

param : Tensor | float | None

Parameters of the gates. Defaults to None.

param_sharing : bool | None

Whether gates in the same layer share a parameter. Defaults to False.

Raises:

ValueError – The param must be torch.Tensor or float.