paddle_quantum.gate.matrix

The library of gate matrices.

paddle_quantum.gate.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 (str | None) – the dtype of this matrix. Defaults to None.

Returns:

the matrix of H gate.

Return type:

Tensor

paddle_quantum.gate.matrix.s_gate(dtype=None)

Generate the matrix

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

dtype (str | None) – the dtype of this matrix. Defaults to None.

Returns:

the matrix of S gate.

Return type:

Tensor

paddle_quantum.gate.matrix.sdg_gate(dtype=None)

Generate the matrix

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

dtype (str | None) – the dtype of this matrix. Defaults to None.

Returns:

the matrix of Sdg gate.

Return type:

Tensor

paddle_quantum.gate.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 (str | None) – the dtype of this matrix. Defaults to None.

Returns:

the matrix of T gate.

Return type:

Tensor

paddle_quantum.gate.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 (str | None) – the dtype of this matrix. Defaults to None.

Returns:

the matrix of Sdg gate.

Return type:

Tensor

paddle_quantum.gate.matrix.x_gate(dtype=None)

Generate the matrix

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

dtype (str | None) – the dtype of this matrix. Defaults to None.

Returns:

the matrix of X gate.

Return type:

Tensor

paddle_quantum.gate.matrix.y_gate(dtype=None)

Generate the matrix

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

dtype (str | None) – the dtype of this matrix. Defaults to None.

Returns:

the matrix of Y gate.

Return type:

Tensor

paddle_quantum.gate.matrix.z_gate(dtype=None)

Generate the matrix

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

dtype (str | None) – the dtype of this matrix. Defaults to None.

Returns:

the matrix of Z gate.

Return type:

Tensor

paddle_quantum.gate.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.

Returns:

the matrix of P gate.

Return type:

Tensor

paddle_quantum.gate.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.

Returns:

the matrix of R_X gate.

Return type:

Tensor

paddle_quantum.gate.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.

Returns:

the matrix of R_Y gate.

Return type:

Tensor

paddle_quantum.gate.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.

Returns:

the matrix of R_Z gate.

Return type:

Tensor

paddle_quantum.gate.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.

Returns:

the matrix of U_3 gate.

Return type:

Tensor

paddle_quantum.gate.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 (str | None) – the dtype of this matrix. Defaults to None.

Returns:

the matrix of CNOT gate.

Return type:

Tensor

paddle_quantum.gate.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 (str | None) – the dtype of this matrix. Defaults to None.

Returns:

the matrix of CY gate.

Return type:

Tensor

paddle_quantum.gate.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 (str | None) – the dtype of this matrix. Defaults to None.

Returns:

the matrix of CZ gate.

Return type:

Tensor

paddle_quantum.gate.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 (str | None) – the dtype of this matrix. Defaults to None.

Returns:

the matrix of SWAP gate.

Return type:

Tensor

paddle_quantum.gate.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.

Returns:

the matrix of CP gate.

Return type:

Tensor

paddle_quantum.gate.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.

Returns:

the matrix of CR_X gate.

Return type:

Tensor

paddle_quantum.gate.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.

Returns:

the matrix of CR_Y gate.

Return type:

Tensor

paddle_quantum.gate.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.

Returns:

the matrix of CR_Z gate.

Return type:

Tensor

paddle_quantum.gate.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 & \cos\frac\theta2 &-e^{i\lambda}\sin\frac\theta2 \\ 0 & 0 & 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.

Returns:

the matrix of CU gate.

Return type:

Tensor

paddle_quantum.gate.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.

Returns:

the matrix of RXX gate.

Return type:

Tensor

paddle_quantum.gate.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.

Returns:

the matrix of RYY gate.

Return type:

Tensor

paddle_quantum.gate.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.

Returns:

the matrix of RZZ gate.

Return type:

Tensor

paddle_quantum.gate.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 (str | None) – the dtype of this matrix. Defaults to None.

Returns:

the matrix of MS gate.

Return type:

Tensor

paddle_quantum.gate.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 (str | None) – the dtype of this matrix. Defaults to None.

Returns:

the matrix of CSWAP gate.

Return type:

Tensor

paddle_quantum.gate.matrix.toffoli_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 & 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 (str | None) – the dtype of this matrix. Defaults to None.

Returns:

the matrix of Toffoli gate.

Return type:

Tensor

paddle_quantum.gate.matrix.universal2_gate(theta)

Generate the matrix

Parameters:

theta (Tensor) – the parameter of this matrix.

Returns:

the matrix of universal two qubits gate.

Return type:

Tensor

paddle_quantum.gate.matrix.universal3_gate(theta)

Generate the matrix

Parameters:

theta (Tensor) – the parameter of this matrix.

Returns:

the matrix of universal three qubits gate.

Return type:

Tensor