quairkit.database.matrix

Gate matrices.

quairkit.database.matrix.phase(dim)

Generate phase operator for qudit

Parameters:
dim : int

dimension of qudit

Returns:

Phase operator for qudit

Return type:

Tensor

quairkit.database.matrix.shift(dim)

Generate shift operator for qudit

Parameters:
dim : int

dimension of qudit

Returns:

Shift operator for qudit

Return type:

Tensor

quairkit.database.matrix.grover_matrix(oracle)

Construct the Grover operator based on oracle.

Parameters:
oracle : Tensor

the input oracle \(A\) to be rotated.

Returns:

Grover operator in form

Return type:

Tensor

\[G = A (2 |0^n \rangle\langle 0^n| - I^n) A^\dagger \cdot (I - 2|1 \rangle\langle 1|) \otimes I^{n-1}\]
quairkit.database.matrix.qft_matrix(num_qubits, dtype=torch.complex64)

Construct the quantum fourier transpose (QFT) gate.

Parameters:
num_qubits : int

number of qubits \(n\) st. \(N = 2^n\).

dtype : dtype

the data type you used, default type is torch.complex64

Returns:

a gate in below matrix form, here \(\omega_N = \text{exp}(\frac{2 \pi i}{N})\)

Return type:

Tensor

\[\begin{split}\begin{align} QFT = \frac{1}{\sqrt{N}} \begin{bmatrix} 1 & 1 & .. & 1 \\ 1 & \omega_N & .. & \omega_N^{N-1} \\ .. & .. & .. & .. \\ 1 & \omega_N^{N-1} & .. & \omega_N^{(N-1)^2} \end{bmatrix} \end{align}\end{split}\]
quairkit.database.matrix.h(dtype=None)

Generate the matrix

\[\begin{split}H = \frac{1}{\sqrt{2}} \begin{bmatrix} 1&1\\ 1&-1 \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of H gate.

Return type:

Tensor

quairkit.database.matrix.s(dtype=None)

Generate the matrix

\[\begin{split}S = \begin{bmatrix} 1&0\\ 0&i \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of S gate.

Return type:

Tensor

quairkit.database.matrix.sdg(dtype=None)

Generate the matrix

\[\begin{split}S^\dagger = \begin{bmatrix} 1&0\\ 0&-i \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of Sdg gate.

Return type:

Tensor

quairkit.database.matrix.t(dtype=None)

Generate the matrix

\[\begin{split}T = \begin{bmatrix} 1&0\\ 0&e^\frac{i\pi}{4} \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of T gate.

Return type:

Tensor

quairkit.database.matrix.tdg(dtype=None)

Generate the matrix

\[\begin{split}T^\dagger = \begin{bmatrix} 1&0\\ 0&e^{-\frac{i\pi}{4}} \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of Sdg gate.

Return type:

Tensor

quairkit.database.matrix.eye(dtype=None)

Generate the matrix

\[\begin{split}I = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of X gate.

Return type:

Tensor

quairkit.database.matrix.x(dtype=None)

Generate the matrix

\[\begin{split}X = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of X gate.

Return type:

Tensor

quairkit.database.matrix.y(dtype=None)

Generate the matrix

\[\begin{split}Y = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of Y gate.

Return type:

Tensor

quairkit.database.matrix.z(dtype=None)

Generate the matrix

\[\begin{split}Z = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of Z gate.

Return type:

Tensor

quairkit.database.matrix.p(theta)

Generate the matrix

\[\begin{split}P(\theta) = \begin{bmatrix} 1 & 0 \\ 0 & e^{i\theta} \end{bmatrix}\end{split}\]
Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of P gate.

Return type:

Tensor

quairkit.database.matrix.rx(theta)

Generate the matrix

\[\begin{split}R_X(\theta) = \begin{bmatrix} \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} \\ -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{bmatrix}\end{split}\]
Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of R_X gate.

Return type:

Tensor

quairkit.database.matrix.ry(theta)

Generate the matrix

\[\begin{split}R_Y(\theta) = \begin{bmatrix} \cos\frac{\theta}{2} & -\sin\frac{\theta}{2} \\ \sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{bmatrix}\end{split}\]
Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of R_Y gate.

Return type:

Tensor

quairkit.database.matrix.rz(theta)

Generate the matrix

\[\begin{split}R_Z(\theta) = \begin{bmatrix} e^{-i\frac{\theta}{2}} & 0 \\ 0 & e^{i\frac{\theta}{2}} \end{bmatrix}\end{split}\]
Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of R_Z gate.

Return type:

Tensor

quairkit.database.matrix.u3(theta)

Generate the matrix

\[\begin{split}\begin{align} U_3(\theta, \phi, \lambda) = \begin{bmatrix} \cos\frac\theta2&-e^{i\lambda}\sin\frac\theta2\\ e^{i\phi}\sin\frac\theta2&e^{i(\phi+\lambda)}\cos\frac\theta2 \end{bmatrix} \end{align}\end{split}\]
Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [3, 1]

Returns:

the matrix of U_3 gate.

Return type:

Tensor

quairkit.database.matrix.cnot(dtype=None)

Generate the matrix

\[\begin{split}\begin{align} \mathit{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:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of CNOT gate.

Return type:

Tensor

quairkit.database.matrix.cy(dtype=None)

Generate the matrix

\[\begin{split}\begin{align} \mathit{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 & -i \\ 0 & 0 & i & 0 \end{bmatrix} \end{align}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of CY gate.

Return type:

Tensor

quairkit.database.matrix.cz(dtype=None)

Generate the matrix

\[\begin{split}\begin{align} \mathit{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:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of CZ gate.

Return type:

Tensor

quairkit.database.matrix.swap(dtype=None)

Generate the matrix

\[\begin{split}\begin{align} \mathit{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:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of SWAP gate.

Return type:

Tensor

quairkit.database.matrix.cp(theta)

Generate the matrix

\[\begin{split}\begin{align} \mathit{CP}(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & e^{i\theta} \end{bmatrix} \end{align}\end{split}\]
Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of CP gate.

Return type:

Tensor

quairkit.database.matrix.crx(theta)

Generate the matrix

\[\begin{split}\begin{align} \mathit{CR_X} &=|0\rangle \langle 0|\otimes I + |1 \rangle \langle 1|\otimes R_X\\ &= \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:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of CR_X gate.

Return type:

Tensor

quairkit.database.matrix.cry(theta)

Generate the matrix

\[\begin{split}\begin{align} \mathit{CR_Y} &=|0\rangle \langle 0|\otimes I + |1 \rangle \langle 1|\otimes R_Y\\ &= \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:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of CR_Y gate.

Return type:

Tensor

quairkit.database.matrix.crz(theta)

Generate the matrix

\[\begin{split}\begin{align} \mathit{CR_Z} &= |0\rangle \langle 0|\otimes I + |1 \rangle \langle 1|\otimes R_Z\\ &= \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:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of CR_Z gate.

Return type:

Tensor

quairkit.database.matrix.cu(theta)

Generate the matrix

\[\begin{split}\begin{align} \mathit{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:
theta : Tensor

the parameter of this matrix. The shape of param is [3,1]

Returns:

the matrix of CU gate.

Return type:

Tensor

quairkit.database.matrix.rxx(theta)

Generate the matrix

\[\begin{split}\begin{align} \mathit{R_{XX}}(\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:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of RXX gate.

Return type:

Tensor

quairkit.database.matrix.ryy(theta)

Generate the matrix

\[\begin{split}\begin{align} \mathit{R_{YY}}(\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:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of RYY gate.

Return type:

Tensor

quairkit.database.matrix.rzz(theta)

Generate the matrix

\[\begin{split}\begin{align} \mathit{R_{ZZ}}(\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:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of RZZ gate.

Return type:

Tensor

quairkit.database.matrix.ms(dtype=None)

Generate the matrix

\[\begin{split}\begin{align} \mathit{MS} = \mathit{R_{XX}}(-\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:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of MS gate.

Return type:

Tensor

quairkit.database.matrix.cswap(dtype=None)

Generate the matrix

\[\begin{split}\begin{align} \mathit{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:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of CSWAP gate.

Return type:

Tensor

quairkit.database.matrix.toffoli(dtype=None)

Generate the matrix

\[\begin{split}\begin{align} \mathit{Toffoli} = \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:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of Toffoli gate.

Return type:

Tensor

quairkit.database.matrix.universal2(theta)

Generate the matrix

Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [15]

Returns:

the matrix of universal two qubits gate.

Return type:

Tensor

quairkit.database.matrix.universal3(theta)

Generate the matrix

Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [81]

Returns:

the matrix of universal three qubits gate.

Return type:

Tensor

quairkit.database.matrix.universal_qudit(theta, dimension)

Generalized GellMann matrix basis were used to construct the universal gate for qudits

Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [dimension**2 - 1]

dimension : int

the dimension of the qudit

Returns:

the matrix of d-dimensional unitary gate

Return type:

Tensor

References

[wolfram mathworld](https://mathworld.wolfram.com/GeneralizedGell-MannMatrix.html)

quairkit.database.matrix.Uf(f, n)

Construct the unitary matrix maps \(|x\rangle|y\rangle\) to \(|x\rangle|y\oplus f(x)\rangle\) based on a boolean function \(f\).

Parameters:
f : Callable[[Tensor], Tensor]

a boolean function \(f\) that maps \(\{ 0,1 \}^{n}\) to \(\{ 0,1 \}\);

n : int

the length of input \(\{ 0,1 \}^{n}\);

Returns:

Unitary matrix in form

Return type:

Tensor

\[U: U|x\rangle|y\rangle = |x\rangle|y\oplus f(x)\rangle\]
quairkit.database.matrix.Of(f, n)

Construct the unitary matrix maps \(|x\rangle\) to \((-1)^{f(x)}|x\rangle\) based on a boolean function \(f\).

Parameters:
f : Callable[[Tensor], Tensor]

a boolean function \(f\) that maps \(\{ 0,1 \}^{n}\) to \(\{ 0,1 \}\);

n : int

the length of input \(\{ 0,1 \}^{n}\);

Returns:

Unitary matrix in form

Return type:

Tensor

\[U: U|x\rangle = (-1)^{f(x)}|x\rangle\]
quairkit.database.matrix.reduce_gate()

reduce(function, iterable[, initial]) -> value

Apply a function of two arguments cumulatively to the items of a sequence or iterable, from left to right, so as to reduce the iterable to a single value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates ((((1+2)+3)+4)+5). If initial is present, it is placed before the items of the iterable in the calculation, and serves as a default when the iterable is empty.

quairkit.database.matrix.phase_gate(dim)

Generate phase operator for qudit

Parameters:
dim : int

dimension of qudit

Returns:

Phase operator for qudit

Return type:

Tensor

quairkit.database.matrix.shift_gate(dim)

Generate shift operator for qudit

Parameters:
dim : int

dimension of qudit

Returns:

Shift operator for qudit

Return type:

Tensor

quairkit.database.matrix.h_gate(dtype=None)

Generate the matrix

\[\begin{split}H = \frac{1}{\sqrt{2}} \begin{bmatrix} 1&1\\ 1&-1 \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of H gate.

Return type:

Tensor

quairkit.database.matrix.s_gate(dtype=None)

Generate the matrix

\[\begin{split}S = \begin{bmatrix} 1&0\\ 0&i \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of S gate.

Return type:

Tensor

quairkit.database.matrix.sdg_gate(dtype=None)

Generate the matrix

\[\begin{split}S^\dagger = \begin{bmatrix} 1&0\\ 0&-i \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of Sdg gate.

Return type:

Tensor

quairkit.database.matrix.t_gate(dtype=None)

Generate the matrix

\[\begin{split}T = \begin{bmatrix} 1&0\\ 0&e^\frac{i\pi}{4} \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of T gate.

Return type:

Tensor

quairkit.database.matrix.tdg_gate(dtype=None)

Generate the matrix

\[\begin{split}T^\dagger = \begin{bmatrix} 1&0\\ 0&e^{-\frac{i\pi}{4}} \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of Sdg gate.

Return type:

Tensor

quairkit.database.matrix.eye_gate(dtype=None)

Generate the matrix

\[\begin{split}I = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of X gate.

Return type:

Tensor

quairkit.database.matrix.x_gate(dtype=None)

Generate the matrix

\[\begin{split}X = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of X gate.

Return type:

Tensor

quairkit.database.matrix.y_gate(dtype=None)

Generate the matrix

\[\begin{split}Y = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of Y gate.

Return type:

Tensor

quairkit.database.matrix.z_gate(dtype=None)

Generate the matrix

\[\begin{split}Z = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of Z gate.

Return type:

Tensor

quairkit.database.matrix.p_gate(theta)

Generate the matrix

\[\begin{split}P(\theta) = \begin{bmatrix} 1 & 0 \\ 0 & e^{i\theta} \end{bmatrix}\end{split}\]
Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of P gate.

Return type:

Tensor

quairkit.database.matrix.rx_gate(theta)

Generate the matrix

\[\begin{split}R_X(\theta) = \begin{bmatrix} \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} \\ -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{bmatrix}\end{split}\]
Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of R_X gate.

Return type:

Tensor

quairkit.database.matrix.ry_gate(theta)

Generate the matrix

\[\begin{split}R_Y(\theta) = \begin{bmatrix} \cos\frac{\theta}{2} & -\sin\frac{\theta}{2} \\ \sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{bmatrix}\end{split}\]
Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of R_Y gate.

Return type:

Tensor

quairkit.database.matrix.rz_gate(theta)

Generate the matrix

\[\begin{split}R_Z(\theta) = \begin{bmatrix} e^{-i\frac{\theta}{2}} & 0 \\ 0 & e^{i\frac{\theta}{2}} \end{bmatrix}\end{split}\]
Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of R_Z gate.

Return type:

Tensor

quairkit.database.matrix.u3_gate(theta)

Generate the matrix

\[\begin{split}\begin{align} U_3(\theta, \phi, \lambda) = \begin{bmatrix} \cos\frac\theta2&-e^{i\lambda}\sin\frac\theta2\\ e^{i\phi}\sin\frac\theta2&e^{i(\phi+\lambda)}\cos\frac\theta2 \end{bmatrix} \end{align}\end{split}\]
Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [3, 1]

Returns:

the matrix of U_3 gate.

Return type:

Tensor

quairkit.database.matrix.cnot_gate(dtype=None)

Generate the matrix

\[\begin{split}\begin{align} \mathit{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:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of CNOT gate.

Return type:

Tensor

quairkit.database.matrix.cy_gate(dtype=None)

Generate the matrix

\[\begin{split}\begin{align} \mathit{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 & -i \\ 0 & 0 & i & 0 \end{bmatrix} \end{align}\end{split}\]
Parameters:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of CY gate.

Return type:

Tensor

quairkit.database.matrix.cz_gate(dtype=None)

Generate the matrix

\[\begin{split}\begin{align} \mathit{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:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of CZ gate.

Return type:

Tensor

quairkit.database.matrix.swap_gate(dtype=None)

Generate the matrix

\[\begin{split}\begin{align} \mathit{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:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of SWAP gate.

Return type:

Tensor

quairkit.database.matrix.cp_gate(theta)

Generate the matrix

\[\begin{split}\begin{align} \mathit{CP}(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & e^{i\theta} \end{bmatrix} \end{align}\end{split}\]
Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of CP gate.

Return type:

Tensor

quairkit.database.matrix.crx_gate(theta)

Generate the matrix

\[\begin{split}\begin{align} \mathit{CR_X} &=|0\rangle \langle 0|\otimes I + |1 \rangle \langle 1|\otimes R_X\\ &= \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:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of CR_X gate.

Return type:

Tensor

quairkit.database.matrix.cry_gate(theta)

Generate the matrix

\[\begin{split}\begin{align} \mathit{CR_Y} &=|0\rangle \langle 0|\otimes I + |1 \rangle \langle 1|\otimes R_Y\\ &= \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:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of CR_Y gate.

Return type:

Tensor

quairkit.database.matrix.crz_gate(theta)

Generate the matrix

\[\begin{split}\begin{align} \mathit{CR_Z} &= |0\rangle \langle 0|\otimes I + |1 \rangle \langle 1|\otimes R_Z\\ &= \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:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of CR_Z gate.

Return type:

Tensor

quairkit.database.matrix.cu_gate(theta)

Generate the matrix

\[\begin{split}\begin{align} \mathit{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:
theta : Tensor

the parameter of this matrix. The shape of param is [3,1]

Returns:

the matrix of CU gate.

Return type:

Tensor

quairkit.database.matrix.rxx_gate(theta)

Generate the matrix

\[\begin{split}\begin{align} \mathit{R_{XX}}(\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:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of RXX gate.

Return type:

Tensor

quairkit.database.matrix.ryy_gate(theta)

Generate the matrix

\[\begin{split}\begin{align} \mathit{R_{YY}}(\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:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of RYY gate.

Return type:

Tensor

quairkit.database.matrix.rzz_gate(theta)

Generate the matrix

\[\begin{split}\begin{align} \mathit{R_{ZZ}}(\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:
theta : Tensor

the parameter of this matrix. The shape of param is [1]

Returns:

the matrix of RZZ gate.

Return type:

Tensor

quairkit.database.matrix.ms_gate(dtype=None)

Generate the matrix

\[\begin{split}\begin{align} \mathit{MS} = \mathit{R_{XX}}(-\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:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of MS gate.

Return type:

Tensor

quairkit.database.matrix.cswap_gate(dtype=None)

Generate the matrix

\[\begin{split}\begin{align} \mathit{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:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of CSWAP gate.

Return type:

Tensor

quairkit.database.matrix.toffoli_gate(dtype=None)

Generate the matrix

\[\begin{split}\begin{align} \mathit{Toffoli} = \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:
dtype : dtype | None

the dtype of this matrix. Defaults to None.

Returns:

the matrix of Toffoli gate.

Return type:

Tensor

quairkit.database.matrix.universal2_gate(theta)

Generate the matrix

Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [15]

Returns:

the matrix of universal two qubits gate.

Return type:

Tensor

quairkit.database.matrix.universal3_gate(theta)

Generate the matrix

Parameters:
theta : Tensor

the parameter of this matrix. The shape of param is [81]

Returns:

the matrix of universal three qubits gate.

Return type:

Tensor

quairkit.database.matrix.Uf_gate(f, n)

Construct the unitary matrix maps \(|x\rangle|y\rangle\) to \(|x\rangle|y\oplus f(x)\rangle\) based on a boolean function \(f\).

Parameters:
f : Callable[[Tensor], Tensor]

a boolean function \(f\) that maps \(\{ 0,1 \}^{n}\) to \(\{ 0,1 \}\);

n : int

the length of input \(\{ 0,1 \}^{n}\);

Returns:

Unitary matrix in form

Return type:

Tensor

\[U: U|x\rangle|y\rangle = |x\rangle|y\oplus f(x)\rangle\]
quairkit.database.matrix.Of_gate(f, n)

Construct the unitary matrix maps \(|x\rangle\) to \((-1)^{f(x)}|x\rangle\) based on a boolean function \(f\).

Parameters:
f : Callable[[Tensor], Tensor]

a boolean function \(f\) that maps \(\{ 0,1 \}^{n}\) to \(\{ 0,1 \}\);

n : int

the length of input \(\{ 0,1 \}^{n}\);

Returns:

Unitary matrix in form

Return type:

Tensor

\[U: U|x\rangle = (-1)^{f(x)}|x\rangle\]