diff --git a/docs/mindquantum/docs/source_en/grover_search_algorithm.md b/docs/mindquantum/docs/source_en/grover_search_algorithm.md index 0c8bbc0d620dfa0d3da084bc8159d95cfde0df13..dcd384c1fe37d0942a2b4f8619f65aa2d05e5cf7 100644 --- a/docs/mindquantum/docs/source_en/grover_search_algorithm.md +++ b/docs/mindquantum/docs/source_en/grover_search_algorithm.md @@ -46,19 +46,19 @@ $$ |\psi_0\rangle=H^{\otimes n}|0\rangle^{\otimes n}=\frac{1}{\sqrt{N}}\sum_{i=0 Grover iteration can be further decomposed into four steps: 1. Execute the Oracle operator $U_{\omega}$​, and flip the phase of the target state $|\omega \rangle$​​​​​ - In order to distinguish the data to be found from other data, the easiest way is to flip the phase of the target state (add a negative sign). At this time, we need to construct an Oracle operator $U_{\omega}$, which works as follows: $$ \begin{equation} U_{\omega}|x\rangle=\begin{cases} &|x\rangle,x\neq \omega&\\\\ -&|x\rangle,x=\omega& \end{cases} \end{equation}. $$ - Since when $x=\omega$​, $f(\omega)=1$​, the effect of $U_{\omega}$ can also be expressed as: $$ U_{\omega}|x\rangle=(-1)^{f(x)}|x\rangle, $$ - Its matrix expression is $$\begin{equation}U_{\omega}=\left[\begin{array}{ccc} (-1)^{f(0)} & 0 & \dots & 0 \\\\ 0 & (-1)^{f(1)} & \dots & 0 \\\\ \vdots & \vdots & \ddots & \vdots \\\\ 0 & 0 & \dots & (-1)^{f(N-1)}\end{array}\right]\end{equation}.$$ + In order to distinguish the data to be found from other data, the easiest way is to flip the phase of the target state (add a negative sign). At this time, we need to construct an Oracle operator $U_{\omega}$, which works as follows: $ \begin{equation} U_{\omega}|x\rangle=\begin{cases} &|x\rangle,x\neq \omega&\\\\ -&|x\rangle,x=\omega& \end{cases} \end{equation}. $ + Since when $x=\omega$​, $f(\omega)=1$​, the effect of $U_{\omega}$ can also be expressed as: $ U_{\omega}|x\rangle=(-1)^{f(x)}|x\rangle, $ + Its matrix expression is $\begin{equation}U_{\omega}=\left[\begin{array}{ccc} (-1)^{f(0)} & 0 & \dots & 0 \\\\ 0 & (-1)^{f(1)} & \dots & 0 \\\\ \vdots & \vdots & \ddots & \vdots \\\\ 0 & 0 & \dots & (-1)^{f(N-1)}\end{array}\right]\end{equation}.$ 2. Perform $H^{\otimes n}$ operation Perform $H^{\otimes n}$ operation on $n$ qubits. 3. Execute conditional phase shift operator $P$ - The conditional phase shift operator $P$ can reverse the phase of each state except the $|0\rangle$ ​state, and its effect is as follows: $$\begin{equation}P|x\rangle=\begin{cases}&|0\rangle,x= 0&\\\\-&|x\rangle,x\neq0&\end{cases}\end{equation}.$$ - Its matrix expression is $$\begin{equation}P = 2(|0\rangle\langle0|)^{\otimes n} - I_n =\left[\begin{array}{ccc} 1 & 0 & \dots & 0 \\\\ 0 & -1 & \dots & 0 \\\\ \vdots & \vdots & \ddots & \vdots \\\\ 0 & 0 & \dots & -1\end{array}\right]\end{equation}.$$ + The conditional phase shift operator $P$ can reverse the phase of each state except the $|0\rangle$ ​state, and its effect is as follows: $\begin{equation}P|x\rangle=\begin{cases}&|0\rangle,x= 0&\\\\-&|x\rangle,x\neq0&\end{cases}\end{equation}.$ + Its matrix expression is $\begin{equation}P = 2(|0\rangle\langle0|)^{\otimes n} - I_n =\left[\begin{array}{ccc} 1 & 0 & \dots & 0 \\\\ 0 & -1 & \dots & 0 \\\\ \vdots & \vdots & \ddots & \vdots \\\\ 0 & 0 & \dots & -1\end{array}\right]\end{equation}.$ 4. Perform $H^{\otimes n}$ operation again - So far, the complete $G$ operator can be expressed as $$ G = H^{\otimes n} [2(|0\rangle\langle0|)^{\otimes n} - I_n] H^{\otimes n} U_{\omega}. $$ + So far, the complete $G$ operator can be expressed as $ G = H^{\otimes n} [2(|0\rangle\langle0|)^{\otimes n} - I_n] H^{\otimes n} U_{\omega}. $ Note: The number of iterations required for the $G$ operator is r = \left[ \frac{\pi}{4} \sqrt{\frac{N}{M}} \right] \sim O(\sqrt{N}), where, M represents the number of target states. @@ -529,7 +529,7 @@ It can be seen from the running results that we successfully search for the $|5\ So far, we have introduced the basic principles of Grover search algorithm, and shown how to use MindQuantum to implement the algorithm by two specific small examples! Hurry up and experience the fun of quantum programming! -To find out more about MindQuantum's API, please click: https://mindspore.cn/mindquantum/ +To find out more about MindQuantum's API, please click: ## References diff --git a/docs/mindquantum/docs/source_en/initial_experience_of_quantum_neural_network.md b/docs/mindquantum/docs/source_en/initial_experience_of_quantum_neural_network.md index 00bd155ad2c5b4cfeb1d40c35ffc00410b967b4c..cab38a3626679dc5c4ee7cbf7f005a918a2245ad 100644 --- a/docs/mindquantum/docs/source_en/initial_experience_of_quantum_neural_network.md +++ b/docs/mindquantum/docs/source_en/initial_experience_of_quantum_neural_network.md @@ -26,9 +26,9 @@ We build a quantum neural network as shown in the figure above, where the Encode Problem description: We regard the Encoder as the error effect of the system on the initial quantum state (the parameters $\alpha_0, \alpha_1$ and $\alpha_2$ are a fixed value obtained by preprocessing the original classical data (optional), that is, the known value, which is set to 0.2, 0.3 and 0.4 here respectively). We need to train an Ansatz to cancel out this error, so that the final quantum state is still in the $|0\rangle$ state. -Idea: Perform the Pauli `Z` operator measurement in the final state, and the measurement value at this time is the expected value of the quantum state at this time about the Pauli `Z` operator. Since $|0\rangle$ is the eigenstate of operator `Z`, and the eigenvalue is 1, it is easy to know $$ \langle 0|Z|0\rangle=1. $$ That is, the target expectation is 1. Whether the state at this time is $|0\rangle$ can be verified by measuring the expected value. +Idea: Perform the Pauli `Z` operator measurement in the final state, and the measurement value at this time is the expected value of the quantum state at this time about the Pauli `Z` operator. Since $|0\rangle$ is the eigenstate of operator `Z`, and the eigenvalue is 1, it is easy to know $ \langle 0|Z|0\rangle=1$. That is, the target expectation is 1. Whether the state at this time is $|0\rangle$ can be verified by measuring the expected value. -Solution: By training the parameters in the Ansatz, we hope that the measurement value is close to the target expected value. In other words, we only need to make the measurement value as close as possible to the expected value corresponding to the $|0\rangle$ state with respect to the Pauli `Z` operator, then the The state is $|0\rangle$, that is, the Ansatz cancels the error generated by the Encoder on the initial quantum state. +Solution: By training the parameters in the Ansatz, we hope that the measurement value is close to the target expected value. In other words, we only need to make the measurement value as close as possible to the expected value corresponding to the $|0\rangle$ state with respect to the Pauli `Z` operator, then the state is $|0\rangle$, that is, the Ansatz cancels the error generated by the Encoder on the initial quantum state. ## Environment Preparation diff --git a/docs/mindquantum/docs/source_en/quantum_phase_estimation.md b/docs/mindquantum/docs/source_en/quantum_phase_estimation.md index d667d9b8e64096cc8237a83b77ea9945e3063648..13bf9dd61cdec2fb8052c13c68bdd85830e12e44 100644 --- a/docs/mindquantum/docs/source_en/quantum_phase_estimation.md +++ b/docs/mindquantum/docs/source_en/quantum_phase_estimation.md @@ -14,9 +14,9 @@ Quantum Phase Estimation Algorithm, or QPE for short, is the key to many quantum The implementation of the quantum phase estimation algorithm requires two registers, the first register contains $t$ qubits initially at $|0\rangle$, the number of bits is related to the accuracy of the final phase estimation result and the success probability of the algorithm; the second register is initialized on the eigenstate $|u\rangle$ of the unitary operator $U$. The phase estimation algorithm is mainly divided into three steps: -1. Perform `Hadamard` gate operations on all qubits in the first register, and continuously perform `control U` gate operations on the second register, where the powers of $U$ gates are $2^0, 2^1,...,2^{t-1}$, and the control qubits are $q_{t-1}, q_{t-2},..., q_{1}, q_{0}$. Then the state in the first register will change to $$|\psi_1\rangle=\frac{1}{2^{t/2}}\left(|0\rangle+e^{i2\pi 2^{t-1}\varphi}|1\rangle\right)\left(|0\rangle+e^{i2\pi2^{t-2}\varphi}|1\rangle\right)...\left(|0\rangle+e^{i2\pi 2^{0}\varphi}|1\rangle\right) = \frac{1}{2^{t/2}}\sum_{k=0}^{2^t-1}e^{i2\pi\varphi k}|k\rangle$$ where $k$ is the decimal representation of the direct product state, for example, $k=0$ means that all t qubits in the first register are in the ground state $|00...00\rangle$, $k=2$ means $|00...10\rangle$, and so on. +1. Perform `Hadamard` gate operations on all qubits in the first register, and continuously perform `control U` gate operations on the second register, where the powers of $U$ gates are $2^0, 2^1,...,2^{t-1}$, and the control qubits are $q_{t-1}, q_{t-2},..., q_{1}, q_{0}$. Then the state in the first register will change to $|\psi_1\rangle=\frac{1}{2^{t/2}}\left(|0\rangle+e^{i2\pi 2^{t-1}\varphi}|1\rangle\right)\left(|0\rangle+e^{i2\pi2^{t-2}\varphi}|1\rangle\right)...\left(|0\rangle+e^{i2\pi 2^{0}\varphi}|1\rangle\right) = \frac{1}{2^{t/2}}\sum_{k=0}^{2^t-1}e^{i2\pi\varphi k}|k\rangle$ where $k$ is the decimal representation of the direct product state, for example, $k=0$ means that all t qubits in the first register are in the ground state $|00...00\rangle$, $k=2$ means $|00...10\rangle$, and so on. -2. Perform the inverse quantum Fourier transform on the first register, which is expressed as $QFT^\dagger$ in the circuit, and perform the inverse quantum Fourier transform on $|\psi_1\rangle$ to obtain $|\psi_2\rangle$ $$|\psi_2\rangle=QFT^\dagger|\psi_1\rangle =\frac{1}{2^t}\sum_{x=0}^{2^t-1}a_x|x\rangle$$ where $$a_x=\sum_{k=0}^{2^t-1}e^{2\pi i k(\varphi-x/2^t)}$$ is the probability amplitude corresponding to the eigenbasis vector $|x\rangle$ ($x=0.1,...,2^t$). It can be obtained from the above formula that when $2^t\varphi$ is an integer and $x=2^t\varphi$ is satisfied, the probability amplitude takes the maximum value of 1, at this time, the last state of the first register can accurately reflect $\varphi$; when $2^t\varphi$ is not an integer, $x$ is the estimate of $\varphi$, and the larger $t$, the higher the estimation accuracy. +2. Perform the inverse quantum Fourier transform on the first register, which is expressed as $QFT^\dagger$ in the circuit, and perform the inverse quantum Fourier transform on $|\psi_1\rangle$ to obtain $|\psi_2\rangle$ $|\psi_2\rangle=QFT^\dagger|\psi_1\rangle =\frac{1}{2^t}\sum_{x=0}^{2^t-1}a_x|x\rangle$ where $a_x=\sum_{k=0}^{2^t-1}e^{2\pi i k(\varphi-x/2^t)}$ is the probability amplitude corresponding to the eigenbasis vector $|x\rangle$ ($x=0.1,...,2^t$). It can be obtained from the above formula that when $2^t\varphi$ is an integer and $x=2^t\varphi$ is satisfied, the probability amplitude takes the maximum value of 1, at this time, the last state of the first register can accurately reflect $\varphi$; when $2^t\varphi$ is not an integer, $x$ is the estimate of $\varphi$, and the larger $t$, the higher the estimation accuracy. 3. Measure the qubits of the first register to obtain the final state of the first register $f=\sum_{x}^{2^t-1}a_x|x\rangle$, $x=0,1,...,2^t$, and find the maximum amplitude $a_{max}$ from it, then the $x$ in the corresponding eigenvector $|x\rangle$ divided by $2^t$ is the estimated value of phase.