mindquantum.core.gates#

量子门模块,提供不同的量子门。

基类#

接口名

概述

BasicGate(name, n_qubits)

BasicGate是所有门的基类。

NoneParameterGate(...)

非参数化的门。

ParameterGate(pr, ...)

参数化的门。

QuantumGate(name, ...)

非参数化的门。

NoiseGate(name, n_qubits)

噪声信道。

通用量子门#

接口名

概述

数学表示

CNOTGate()

控制X门。

FSim(theta, phi)

FSim 门表示费米子模拟门。FSim 门的矩阵形式为:

\[\begin{split}{\rm FSim}(\theta, \phi)=\begin{pmatrix}1&0&0&0\\0&\cos(\theta)&-i\sin(\theta)&0\\ 0&-i\sin(\theta)&\cos(\theta)&0\\0&0&0&e^{-i\phi}\end{pmatrix}\end{split}\]

GlobalPhase(pr)

全局相位门。更多用法,请参见 RX.

\[\begin{split}{\rm GlobalPhase}=\begin{pmatrix}\exp(-i\theta)&0\\ 0&\exp(-i\theta)\end{pmatrix}\end{split}\]

HGate()

Hadamard门。矩阵为:

\[\begin{split}{\rm H}=\frac{1}{\sqrt{2}}\begin{pmatrix}1&1\\1&-1\end{pmatrix}\end{split}\]

IGate()

Identity门。矩阵为:

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

ISWAPGate()

ISWAP门会交换两个不同的量子比特并且为 \(\left|01\right>\)\(\left|10\right>\) 的振幅增加相位 \(i\)

Measure([name, reset_to])

测量量子比特的测量门。

PhaseShift(pr)

相移门。更多用法,请参见 RX

\[\begin{split}{\rm PhaseShift}=\begin{pmatrix}1&0\\ 0&\exp(i\theta)\end{pmatrix}\end{split}\]

Rn(alpha, beta, gamma)

Rn 门表示绕布洛赫球中给定轴旋转的量子门。Rn 门的矩阵形式为:

\[\begin{split}\begin{aligned} {\rm Rn}(\alpha, \beta, \gamma) &= e^{-i(\alpha \sigma_x + \beta \sigma_y + \gamma \sigma_z)/2}\\ &= \cos(f/2)I-i\sin(f/2)(\alpha \sigma_x + \beta \sigma_y + \gamma \sigma_z)/f\\ &\text{where } f=\sqrt{\alpha^2 + \beta^2 + \gamma^2} \end{aligned}\end{split}\]

RX(pr)

围绕x轴的旋转门。

\[\begin{split}{\rm RX}=\begin{pmatrix}\cos(\theta/2)&-i\sin(\theta/2)\\ -i\sin(\theta/2)&\cos(\theta/2)\end{pmatrix}\end{split}\]

Rxx(pr)

Rxx 门。更多用法,请参见 RX

\[\begin{split}{\rm Rxx_\theta}=\exp{\left(-i\frac{\theta}{2} X\otimes X\right)} =\begin{pmatrix} \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{pmatrix}\end{split}\]

Rxy(pr)

Rxy 门。更多用法,请参见 RX

\[\begin{split}{\rm Rxy_\theta}=\exp{\left(-i\frac{\theta}{2} Y\otimes X\right)} =\begin{pmatrix} \cos{\frac{\theta}{2}} & 0 & 0 & -\sin{\frac{\theta}{2}}\\ 0 & \cos{\frac{\theta}{2}} & -\sin{\frac{\theta}{2}} & 0\\ 0 & \sin{\frac{\theta}{2}} & \cos{\frac{\theta}{2}} & 0\\ \sin{\frac{\theta}{2}} & 0 & 0 & \cos{\frac{\theta}{2}}\\ \end{pmatrix}\end{split}\]

Rxz(pr)

Rxz 门。更多用法,请参见 RX

\[\begin{split}{\rm Rxz_\theta}=\exp{\left(-i\frac{\theta}{2} Z\otimes X\right)} =\begin{pmatrix} \cos{\frac{\theta}{2}} & -i\sin{\frac{\theta}{2}} & 0 & 0\\ -i\sin{\frac{\theta}{2}} & \cos{\frac{\theta}{2}} & 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{pmatrix}\end{split}\]

RY(pr)

围绕y轴的旋转门。更多用法,请参见 RX

\[\begin{split}{\rm RY}=\begin{pmatrix}\cos(\theta/2)&-\sin(\theta/2)\\ \sin(\theta/2)&\cos(\theta/2)\end{pmatrix}\end{split}\]

Ryy(pr)

Ryy 门。更多用法,请参见 RX

\[\begin{split}{\rm Ryy_\theta}=\exp{\left(-i\frac{\theta}{2} Y\otimes Y\right)} =\begin{pmatrix} \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{pmatrix}\end{split}\]

Ryz(pr)

Ryz 门。更多用法,请参见 RX

\[\begin{split}{\rm Ryz_\theta}=\exp{\left(-i\frac{\theta}{2} Z\otimes Y\right)} =\begin{pmatrix} \cos{\frac{\theta}{2}} & -\sin{\frac{\theta}{2}} & 0 & 0\\ \sin{\frac{\theta}{2}} & \cos{\frac{\theta}{2}} & 0 & 0\\ 0 & 0 & \cos{\frac{\theta}{2}} & \sin{\frac{\theta}{2}}\\ 0 & 0 & -\sin{\frac{\theta}{2}} & \cos{\frac{\theta}{2}}\\ \end{pmatrix}\end{split}\]

RZ(pr)

围绕z轴的旋转门。更多用法,请参见 RX

\[\begin{split}{\rm RZ}=\begin{pmatrix}\exp(-i\theta/2)&0\\ 0&\exp(i\theta/2)\end{pmatrix}\end{split}\]

Rzz(pr)

Rzz 门。更多用法,请参见 RX

\[\begin{split}{\rm Rzz_\theta}=\exp{\left(-i\frac{\theta}{2} Z\otimes Z\right)} =\begin{pmatrix} 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{pmatrix}\end{split}\]

RotPauliString(...)

任意泡利串的旋转门。

\[U(\theta)=e^{-i\theta P/2}, P=\otimes_i\sigma_i, \text{where } \sigma \in \{X, Y, Z\}\]

SGate()

S门。矩阵为:

\[\begin{split}{\rm S}=\begin{pmatrix}1&0\\0&i\end{pmatrix}\end{split}\]

SWAPalpha(pr)

SWAPalpha 门。更多用法,请参见 RX

\[\begin{split}\text{SWAP}(\alpha) = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & \frac{1}{2}\left(1+e^{i\pi\alpha}\right) & \frac{1}{2}\left(1-e^{i\pi\alpha}\right) & 0\\ 0 & \frac{1}{2}\left(1-e^{i\pi\alpha}\right) & \frac{1}{2}\left(1+e^{i\pi\alpha}\right) & 0\\ 0 & 0 & 0 & 1\\ \end{pmatrix}\end{split}\]

SWAPGate()

SWAP门可以交换两个不同的量子比特。

SXGate()

SX门。矩阵为:

\[\begin{split}{\rm SX}=\frac{1}{2}\begin{pmatrix}1+i&1-i\\1-i&1+i\end{pmatrix}\end{split}\]

TGate()

T门。矩阵为:

\[\begin{split}{\rm T}=\begin{pmatrix}1&0\\0&(1+i)/\sqrt(2)\end{pmatrix}\end{split}\]

U3(theta, phi, lamda)

U3 门表示单比特的任意幺正门。U3 门的矩阵形式为:

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

XGate()

泡利X门。矩阵为:

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

YGate()

泡利Y门。矩阵为:

\[\begin{split}{\rm Y}=\begin{pmatrix}0&-i\\i&0\end{pmatrix}\end{split}\]

ZGate()

泡利Z门。矩阵为:

\[\begin{split}{\rm Z}=\begin{pmatrix}1&0\\0&-1\end{pmatrix}\end{split}\]

GroupedPauli(pauli_string)

多比特泡利串旋转门。

\[U =\otimes_i\sigma_i, \text{where } \sigma \in \{I, X, Y, Z\}\]

Givens(pr)

Givens 门。更多用法,请参见 RX

\[\begin{split}{\rm G}(\theta)=\exp{\left(-i\frac{\theta}{2} (Y\otimes X - X\otimes Y)\right)} = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & \cos{\theta} & -\sin{\theta} & 0\\ 0 & \sin{\theta} & \cos{\theta} & 0\\ 0 & 0 & 0 & 1\\ \end{pmatrix}\end{split}\]

功能量子门#

接口名

概述

UnivMathGate(name, ...)

通用数学门。

gene_univ_parameterized_gate(...)

基于单参数幺正矩阵生成自定义参数化门。

gene_univ_two_params_gate(...)

基于双参数幺正矩阵生成自定义参数化门。

BarrierGate([show])

栅栏门会将两个量子门分开在不同的层级上。

预实例化门#

如下量子门是预实例化的量子门,可直接作为对应量子门的实例来使用。

functional

gates

mindquantum.core.gates.CNOT

CNOTGate

mindquantum.core.gates.I

IGate

mindquantum.core.gates.ISWAP

ISWAPGate

mindquantum.core.gates.H

HGate

mindquantum.core.gates.S

PhaseShift (numpy.pi/2)

mindquantum.core.gates.SWAP

SWAPGate

mindquantum.core.gates.SX

SXGate

mindquantum.core.gates.T

PhaseShift (numpy.pi/4)

mindquantum.core.gates.X

XGate

mindquantum.core.gates.Y

YGate

mindquantum.core.gates.Z

ZGate

量子信道#

接口名

概述

数学表示

AmplitudeDampingChannel(...)

振幅阻尼信道。可以表示量子比特由于能量耗散导致的错误。

\[\begin{split}\begin{gather*} \epsilon(\rho) = E_0 \rho E_0^\dagger + E_1 \rho E_1^\dagger \\ \text{其中}\ {E_0}=\begin{bmatrix}1&0\\ 0&\sqrt{1-\gamma}\end{bmatrix}, \ {E_1}=\begin{bmatrix}0&\sqrt{\gamma}\\ 0&0\end{bmatrix} \end{gather*}\end{split}\]

BitFlipChannel(p, ...)

比特翻转信道。描述的噪声体现为:以 \(P\) 的概率翻转量子比特(作用 \(X\) 门),或以 \(1-P\) 的概率保持不变(作用 \(I\) 门)。

\[\epsilon(\rho) = (1 - P)\rho + P X \rho X\]

BitPhaseFlipChannel(p, ...)

比特相位翻转信道。描述的噪声体现为:以 \(P\) 的概率翻转比特的量子态和相位(作用 \(Y\) 门),或以 \(1-P\) 的概率保持不变(作用 \(I\) 门)。

\[\epsilon(\rho) = (1 - P)\rho + P Y \rho Y\]

DepolarizingChannel(p)

去极化信道。描述的噪声体现为:以 \(P\) 的概率将量子态转变为最大混态(随机作用泡利门(I、X、Y、Z)的其中一个,每个泡利门的概率都是 \(P/4\) ),或以 \(1-P\) 的概率保持不变。

\[\epsilon(\rho) = (1 - P)\rho + P/4( I \rho I + X \rho X + Y \rho Y + Z \rho Z)\]

KrausChannel(name, ...)

Kraus 信道接受两个或多个 2x2 矩阵作为 Kraus 算子,以在量子电路中构造自定义(单量子比特)噪声。

\[\epsilon(\rho) = \sum_{k=0}^{m-1} E_k \rho E_k^\dagger\]

PauliChannel(px, py, ...)

泡利信道。描述的噪声体现为:在量子比特上随机作用一个额外的泡利门,作用 \(X\)\(Y\)\(Z\) 门对应概率分别为 \(P_x\)\(P_y\)\(P_z\) ,或以概率 \(1-P_x-P_y-P_z\) 的概率保持不变(作用 \(I\) 门)。

\[\epsilon(\rho) = (1 - P_x - P_y - P_z)\rho + P_x X \rho X + P_y Y \rho Y + P_z Z \rho Z\]

GroupedPauliChannel(...)

组合泡利信道。

\[\epsilon(\rho) = \otimes_i \epsilon_\text{pauli}^i(\rho)\]

PhaseDampingChannel(...)

相位阻尼信道。表示的是量子比特在不跟外界产生能量交换时量子信息的损失。

\[\begin{split}\begin{gather*} \epsilon(\rho) = E_0 \rho E_0^\dagger + E_1 \rho E_1^\dagger \\ \text{其中}\ {E_0}=\begin{bmatrix}1&0\\ 0&\sqrt{1-\gamma}\end{bmatrix}, \ {E_1}=\begin{bmatrix}0&0\\ 0&\sqrt{\gamma}\end{bmatrix} \end{gather*}\end{split}\]

PhaseFlipChannel(p, ...)

相位翻转信道。描述的噪声体现为:以 \(P\) 的概率翻转量子比特的相位(应用Z门),或以 \(1-P\) 的概率保持不变(作用I门)。

\[\epsilon(\rho) = (1 - P)\rho + P Z \rho Z\]

ThermalRelaxationChannel(t1, ...)

热弛豫信道。

\[\begin{split}\begin{gather*} \epsilon(\rho) = \text{tr}_1 \left[ \Lambda \left( \rho^T \otimes I \right) \right], \Lambda=\begin{pmatrix} \epsilon_{T_1} & 0 & 0 & \epsilon_{T_2} \\ 0 & 1-\epsilon_{T_1} & 0 & 0 \\ 0 & 0 & 0 & 0 \\ \epsilon_{T_2} & 0 & 0 & 1 \end{pmatrix} \\ \text{其中}\ \epsilon_{T_1}=e^{-T_g/T_1}, \epsilon_{T_2}=e^{-T_g/T_2} \end{gather*}\end{split}\]

功能类#

接口名

概述

MeasureResult()

测量结果容器。

Power(gate[, exponent])

作用在非参数化门上的指数运算符。