Skip to content

Commit 9861b48

Browse files
committed
Update 4 tutorials
1 parent 318b324 commit 9861b48

File tree

5 files changed

+48
-80
lines changed

5 files changed

+48
-80
lines changed

docs/source/tutorials/classical_shadows.ipynb

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,19 @@
3232
"source": [
3333
"Let's first briefly review the classical shadows in Pauli basis. For an $n$-qubit quantum state $\\rho$, we randomly perform Pauli projection measurement on each qubit and obtain a snapshot like $\\{1,-1,-1,1,\\cdots,1,-1\\}$. This process is equivalent to apply a random unitary $U$ to $\\rho$ and measure in computational basis to obtain $|b\\rangle=|s_1\\cdots s_n\\rangle,\\ s_j\\in\\{0,1\\}$:\n",
3434
"$$\n",
35-
"\\begin{equation}\n",
36-
" \\rho\\rightarrow U\\rho U^{\\dagger}\\xrightarrow{measure}|b\\rangle\\langle b|,\n",
37-
"\\end{equation}\n",
35+
"\\rho\\rightarrow U\\rho U^{\\dagger}\\xrightarrow{measure}|b\\rangle\\langle b|,\n",
3836
"$$\n",
3937
"where $U=\\bigotimes_{j=1}^{n}u_j$, $u_i\\in\\{H, HS^{\\dagger}, \\mathbb{I}\\}$ correspond to the projection measurements of Pauli $X$, $Y$, $Z$ respectively. Then we reverse the operation to get the equivalent measurement result on $\\rho$:\n",
4038
"$$\n",
41-
"\\begin{equation}\n",
42-
" \\rho\\xrightarrow{measure}U^{\\dagger}|b\\rangle\\langle b| U.\n",
43-
"\\end{equation}\n",
39+
"\\rho\\xrightarrow{measure}U^{\\dagger}|b\\rangle\\langle b| U.\n",
4440
"$$\n",
4541
"Moreover, we perform $N$ random measurements and view their average as a quantum channel:\n",
4642
"$$\n",
47-
"\\begin{equation}\n",
48-
" \\mathbb{E}\\left[U^{\\dagger}|b\\rangle\\langle b|U\\right]=\\mathcal{M}(\\rho),\n",
49-
"\\end{equation}\n",
43+
"\\mathbb{E}\\left[U^{\\dagger}|b\\rangle\\langle b|U\\right]=\\mathcal{M}(\\rho),\n",
5044
"$$\n",
5145
"we can invert the channel to get the approximation of $\\rho$:\n",
5246
"$$\n",
53-
"\\begin{equation}\n",
54-
" \\rho=\\mathbb{E}\\left[\\mathcal{M}^{-1}(U^{\\dagger}|b\\rangle\\langle b|U)\\right].\n",
55-
"\\end{equation}\n",
47+
"\\rho=\\mathbb{E}\\left[\\mathcal{M}^{-1}(U^{\\dagger}|b\\rangle\\langle b|U)\\right].\n",
5648
"$$\n",
5749
"We call each $\\rho_i=\\mathcal{M}^{-1}(U_i^{\\dagger}|b_i\\rangle\\langle b_i|U_i)$ a shadow snapshot state and their ensemble $S(\\rho;N)=\\{\\rho_i|i=1,\\cdots,N\\}$ classical shadows."
5850
],
@@ -65,23 +57,21 @@
6557
"source": [
6658
"In Pauli basis, we have a simple expression of $\\mathcal{M}^{-1}$:\n",
6759
"$$\n",
68-
"\\begin{eqnarray}\n",
69-
" \\rho_i&=&\\mathcal{M}^{-1}(U_i^{\\dagger}|b_i\\rangle\\langle b_i|U_i)=\\bigotimes_{j=1}^{n}3u_{ij}^{\\dagger}|s_{ij}\\rangle\\langle s_{ij}|u_{ij}-\\mathbb{I},\\\\\n",
70-
" \\rho&=&\\frac{1}{N}\\sum_{i=1}^{N}\\rho_i\\ .\n",
71-
"\\end{eqnarray}\n",
60+
"\\begin{split}\n",
61+
" \\rho_i&=\\mathcal{M}^{-1}(U_i^{\\dagger}|b_i\\rangle\\langle b_i|U_i)=\\bigotimes_{j=1}^{n}3u_{ij}^{\\dagger}|s_{ij}\\rangle\\langle s_{ij}|u_{ij}-\\mathbb{I},\\\\\n",
62+
" \\rho&=\\frac{1}{N}\\sum_{i=1}^{N}\\rho_i\\ .\n",
63+
"\\end{split}\n",
7264
"$$\n",
7365
"For an observable Pauli string $O=\\bigotimes_{j=1}^{n}P_j,\\ P_j\\in\\{\\mathbb{I}, X, Y, Z\\}$, we can directly use $\\rho$ to calculate $\\langle O\\rangle=\\text{Tr}(O\\rho)$. In practice, we will divide the classical shadows into $K$ parts to calculate the expectation values independently and take the median to avoid the influence of outliers:\n",
7466
"$$\n",
75-
"\\begin{equation}\n",
76-
" \\langle O\\rangle=\\text{median}\\{\\langle O_{(1)}\\rangle\\cdots\\langle O_{(K)}\\rangle\\},\n",
77-
"\\end{equation}\n",
67+
"\\langle O\\rangle=\\text{median}\\{\\langle O_{(1)}\\rangle\\cdots\\langle O_{(K)}\\rangle\\},\n",
7868
"$$\n",
7969
"where\n",
8070
"$$\n",
81-
"\\begin{eqnarray}\n",
82-
" \\langle O_{(k)}\\rangle&=&\\frac{1}{\\lceil N/K\\rceil}\\sum_{i=(k-1)\\lceil N/K\\rceil+1}^{k\\lceil N/K\\rceil}\\text{Tr}\\left[\\bigotimes_{j=1}^{n}P_j(3u_{ij}^{\\dagger}|s_{ij}\\rangle\\langle s_{ij}|u_{ij}-\\mathbb{I})\\right]\\\\\n",
83-
" &=&\\frac{1}{\\lceil N/K\\rceil}\\sum_{i=(k-1)\\lceil N/K\\rceil+1}^{k\\lceil N/K\\rceil}\\prod_{j=1}^n\\text{Tr}\\left[3P_j u_{ij}^{\\dagger}|s_{ij}\\rangle\\langle s_{ij}|u_{ij}\\right].\n",
84-
"\\end{eqnarray}\n",
71+
"\\begin{split}\n",
72+
" \\langle O_{(k)}\\rangle&=\\frac{1}{\\lceil N/K\\rceil}\\sum_{i=(k-1)\\lceil N/K\\rceil+1}^{k\\lceil N/K\\rceil}\\text{Tr}\\left[\\bigotimes_{j=1}^{n}P_j(3u_{ij}^{\\dagger}|s_{ij}\\rangle\\langle s_{ij}|u_{ij}-\\mathbb{I})\\right]\\\\\n",
73+
" &=\\frac{1}{\\lceil N/K\\rceil}\\sum_{i=(k-1)\\lceil N/K\\rceil+1}^{k\\lceil N/K\\rceil}\\prod_{j=1}^n\\text{Tr}\\left[3P_j u_{ij}^{\\dagger}|s_{ij}\\rangle\\langle s_{ij}|u_{ij}\\right].\n",
74+
"\\end{split}\n",
8575
"$$"
8676
],
8777
"metadata": {
@@ -143,10 +133,10 @@
143133
"source": [
144134
"We first set the number of qubits $n$ and the number of repeated measurements $r$ on each Pauli string. Then from the target observable Pauli strings $\\{O_i|i=1,\\cdots,M\\}$ (0, 1, 2, and 3 correspond to $\\mathbb{I}$, $X$, $Y$, and $Z$, respectively), the error $\\epsilon$ and the rate of failure $\\delta$, we can use ``shadow_bound`` function to get the total number of snapshots $N$ and the number of equal parts $K$ to split the shadow snapshot states to compute the median of means:\n",
145135
"$$\n",
146-
"\\begin{eqnarray}\n",
147-
" K&=&2\\log(2M/\\delta),\\\\\n",
148-
" N&=&K\\frac{34}{\\epsilon^2}\\max_{1\\le i\\le M}\\left\\|O_i-\\frac{\\text{Tr}(O_i)}{2^n}\\mathbb{I}\\right\\|^2_{\\text{shadow}}=K\\frac{34}{\\epsilon^2}3^{\\max_{1\\le i\\le M}k_i},\n",
149-
"\\end{eqnarray}\n",
136+
"\\begin{split}\n",
137+
" K&=2\\log(2M/\\delta),\\\\\n",
138+
" N&=K\\frac{34}{\\epsilon^2}\\max_{1\\le i\\le M}\\left\\|O_i-\\frac{\\text{Tr}(O_i)}{2^n}\\mathbb{I}\\right\\|^2_{\\text{shadow}}=K\\frac{34}{\\epsilon^2}3^{\\max_{1\\le i\\le M}k_i},\n",
139+
"\\end{split}\n",
150140
"$$\n",
151141
"where $k_i$ is the number of nontrivial Pauli matrices in $O_i$. Please refer to the Theorem S1 and Lemma S3 in [Huang, Kueng and Preskill (2020)](https://www.nature.com/articles/s41567-020-0932-7) for the details of proof. It should be noted that ``shadow_bound`` has a certain degree of overestimation of $N$, and so many measurements are not really needed in practice. Moreover, ``shadow_bound`` is not jitable and no need to jit."
152142
],
@@ -596,10 +586,10 @@
596586
"source": [
597587
"On the other hand, for the second order Renyi entropy, we have another method to calculate it in polynomial time by random measurements:\n",
598588
"$$\n",
599-
"\\begin{eqnarray}\n",
600-
" R_A^2&=&-\\log\\left(\\text{Tr}(\\rho_A^2)\\right),\\\\\n",
601-
" \\text{Tr}(\\rho_A^2)&=&2^k\\sum_{b,b'\\in\\{0,1\\}^k}(-2)^{-H(b,b')}\\overline{P(b)P(b')},\n",
602-
"\\end{eqnarray}\n",
589+
"\\begin{split}\n",
590+
" R_A^2&=-\\log\\left(\\text{Tr}(\\rho_A^2)\\right),\\\\\n",
591+
" \\text{Tr}(\\rho_A^2)&=2^k\\sum_{b,b'\\in\\{0,1\\}^k}(-2)^{-H(b,b')}\\overline{P(b)P(b')},\n",
592+
"\\end{split}\n",
603593
"$$\n",
604594
"where $A$ is the $k$-d reduced system, $H(b,b')$ is the Hamming distance between $b$ and $b'$, $P(b)$ is the probability for measuring $\\rho_A$ and obtaining the outcomes $b$ thus we need a larger $r$ to obtain a good enough priori probability, and the overline means the average on all random selected Pauli strings. Please refer to [Brydges, et al. (2019)](https://www.science.org/doi/full/10.1126/science.aau4963) for more details. We can use ``renyi_entropy_2`` to implement this method, but it is not jitable because we need to build the dictionary based on the bit strings obtained by measurements, which is a dynamical process. Compared with ``entropy_shadow``, it cannot filter out non-negative eigenvalues, so the accuracy is slightly worse."
605595
],

docs/source/tutorials/imag_time_evo.ipynb

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,26 @@
2525
"\n",
2626
"However, exact imaginary-time evolution takes exponentially more space and time to execute on a classical computer. On the other hand, it is non-unitary and also cannot be implemented on a quantum computer. Therefore, we consider the approximate imaginary-time evolution, also known as the quantum natural gradient (QNG), that is, at each step we adjust the parameters in the quantum circuit to realize the imaginary-time evolution in a very short time $\\tau$. Let the parameters in the circuit be $\\boldsymbol{\\theta}$ and the output of the circuit is $|\\psi\\rangle$, define\n",
2727
"$$\n",
28-
"\\begin{eqnarray}\n",
29-
" |\\psi_\\tau\\rangle&=&e^{-\\tau\\hat{H}}|\\psi\\rangle\\approx|\\psi\\rangle-\\tau\\hat{H}|\\psi\\rangle,\\\\\n",
30-
" |\\psi'\\rangle&=&|\\psi(\\boldsymbol{\\theta}-\\tau\\boldsymbol{\\delta})\\rangle\\approx|\\psi\\rangle-\\tau\\sum_j\\boldsymbol{\\delta}_j|\\partial_{\\boldsymbol{\\theta}_{j}}\\psi\\rangle,\n",
31-
"\\end{eqnarray}\n",
28+
"\\begin{split}\n",
29+
" |\\psi_\\tau\\rangle&=e^{-\\tau\\hat{H}}|\\psi\\rangle\\approx|\\psi\\rangle-\\tau\\hat{H}|\\psi\\rangle,\\\\\n",
30+
" |\\psi'\\rangle&=|\\psi(\\boldsymbol{\\theta}-\\tau\\boldsymbol{\\delta})\\rangle\\approx|\\psi\\rangle-\\tau\\sum_j\\boldsymbol{\\delta}_j|\\partial_{\\boldsymbol{\\theta}_{j}}\\psi\\rangle,\n",
31+
"\\end{split}\n",
3232
"$$\n",
3333
"and the overlap is\n",
3434
"$$\n",
35-
"\\begin{equation}\n",
36-
" O=\\sqrt{\\frac{\\langle\\psi_\\tau\\rangle|\\psi'\\rangle\\langle\\psi'|\\psi_\\tau\\rangle}{\\langle\\psi_\\tau\\rangle|\\psi_\\tau\\rangle\\langle\\psi'|\\psi'\\rangle}}.\n",
37-
"\\end{equation}\n",
35+
"O=\\sqrt{\\frac{\\langle\\psi_\\tau\\rangle|\\psi'\\rangle\\langle\\psi'|\\psi_\\tau\\rangle}{\\langle\\psi_\\tau\\rangle|\\psi_\\tau\\rangle\\langle\\psi'|\\psi'\\rangle}}.\n",
3836
"$$\n",
3937
"Let $\\partial|O|^2/\\partial\\boldsymbol{\\delta}=0$, we can get $\\boldsymbol{A\\delta=C}$, then the update method is as follows\n",
4038
"$$\n",
41-
"\\begin{equation}\n",
42-
" \\boldsymbol{\\theta}^{n+1}=\\boldsymbol{\\theta}^{n}-\\tau\\boldsymbol{\\delta}=\\boldsymbol{\\theta}^{n}-\\tau\\boldsymbol{A}^{-1}\\boldsymbol{C},\n",
43-
"\\end{equation}\n",
39+
"\\boldsymbol{\\theta}^{n+1}=\\boldsymbol{\\theta}^{n}-\\tau\\boldsymbol{\\delta}=\\boldsymbol{\\theta}^{n}-\\tau\\boldsymbol{A}^{-1}\\boldsymbol{C},\n",
4440
"$$\n",
4541
"where $\\boldsymbol{A}$ is the quantum Fisher information matrix and the matrix element\n",
4642
"$$\n",
47-
"\\begin{equation}\n",
48-
" \\boldsymbol{A}_{ij}=\\Re\\left[\\frac{\\langle\\partial_{\\boldsymbol{\\theta}_{i}}\\psi|\\partial_{\\boldsymbol{\\theta}_{j}}\\psi\\rangle}{\\langle\\psi|\\psi\\rangle}-\\frac{\\langle\\partial_{\\boldsymbol{\\theta}_{i}}\\psi|\\psi\\rangle}{\\langle\\psi|\\psi\\rangle}\\frac{\\langle\\psi|\\partial_{\\boldsymbol{\\theta}_{j}}\\psi\\rangle}{\\langle\\psi|\\psi\\rangle}\\right];\n",
49-
"\\end{equation}\n",
43+
"\\boldsymbol{A}_{ij}=\\Re\\left[\\frac{\\langle\\partial_{\\boldsymbol{\\theta}_{i}}\\psi|\\partial_{\\boldsymbol{\\theta}_{j}}\\psi\\rangle}{\\langle\\psi|\\psi\\rangle}-\\frac{\\langle\\partial_{\\boldsymbol{\\theta}_{i}}\\psi|\\psi\\rangle}{\\langle\\psi|\\psi\\rangle}\\frac{\\langle\\psi|\\partial_{\\boldsymbol{\\theta}_{j}}\\psi\\rangle}{\\langle\\psi|\\psi\\rangle}\\right];\n",
5044
"$$\n",
5145
"$\\boldsymbol{C}$ is the gradient vector of energy versus parameters and the vector element\n",
5246
"$$\n",
53-
"\\begin{equation}\n",
54-
" \\boldsymbol{C}_j=\\Re\\left[\\frac{\\langle\\psi|\\hat{H}|\\partial_{\\boldsymbol{\\theta}_{j}}\\psi\\rangle}{\\langle\\psi|\\psi\\rangle}-\\frac{\\langle\\psi|\\hat{H}|\\psi\\rangle}{\\langle\\psi|\\psi\\rangle}\\frac{\\langle\\psi|\\partial_{\\boldsymbol{\\theta}_{j}}\\psi\\rangle}{\\langle\\psi|\\psi\\rangle}\\right].\n",
55-
"\\end{equation}\n",
47+
"\\boldsymbol{C}_j=\\Re\\left[\\frac{\\langle\\psi|\\hat{H}|\\partial_{\\boldsymbol{\\theta}_{j}}\\psi\\rangle}{\\langle\\psi|\\psi\\rangle}-\\frac{\\langle\\psi|\\hat{H}|\\psi\\rangle}{\\langle\\psi|\\psi\\rangle}\\frac{\\langle\\psi|\\partial_{\\boldsymbol{\\theta}_{j}}\\psi\\rangle}{\\langle\\psi|\\psi\\rangle}\\right].\n",
5648
"$$\n",
5749
"Since $|\\psi\\rangle$ is represented by quantum circuit and naturally normalized, the second term of $\\boldsymbol{C}$ vanishes. And because the global phase is not important, we can add a $U(1)$ gauge to make the second term of $\\boldsymbol{A}$ vanishes. Related theoretical work can refer to [Yuan, Endo, Zhao, Li and Benjamin](https://doi.org/10.22331/q-2019-10-07-191) and [Stokes, Izaac, Killoran and Carleo](https://doi.org/10.22331/q-2020-05-25-269), which will also show how to measure $\\boldsymbol{A}$ and $\\boldsymbol{C}$ in circuit."
5850
]
@@ -136,12 +128,10 @@
136128
"\n",
137129
"Let the set of clauses in the NAE3SAT be $\\mathcal{C}$. In each clause, there are three literals and each literal is represented by a spin. Spins up ($s=1$, $\\text{bit}=0$) and down ($s=-1$, $\\text{bit}=1$) represent false and true respectively. For the clause $(s_i,\\ s_j,\\ s_k)\\in\\mathcal{C}$, $s_i,\\ s_j,\\ s_k$ cannot be 1 or -1 at the same time. The Hamiltonian of the NAE3SAT is as follows\n",
138130
"$$\n",
139-
"\\begin{equation}\n",
140-
" \\begin{split}\n",
141-
" \\hat{H}_C&=\\sum_{(i,j,k)\\in\\mathcal{C}}\\left[(s_i+s_j+s_k)^2-1\\right]/2\\\\\n",
142-
" &=\\sum_{(i,j,k)\\in\\mathcal{C}}(s_i s_j+s_j s_k+s_k s_i)+|\\mathcal{C}|,\n",
143-
" \\end{split}\n",
144-
"\\end{equation}\n",
131+
"\\begin{split}\n",
132+
" \\hat{H}_C&=\\sum_{(i,j,k)\\in\\mathcal{C}}\\left[(s_i+s_j+s_k)^2-1\\right]/2\\\\\n",
133+
" &=\\sum_{(i,j,k)\\in\\mathcal{C}}(s_i s_j+s_j s_k+s_k s_i)+|\\mathcal{C}|,\n",
134+
"\\end{split}\n",
145135
"$$\n",
146136
"where $|\\mathcal{C}|$ is the number of clauses in $\\mathcal{C}$. When all clauses are true, $\\hat{H}_C$ takes the minimum value 0, and the corresponding bit string is the solution of the NAE3SAT."
147137
],

docs/source/tutorials/qaoa_nae3sat.ipynb

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,11 @@
3939
"source": [
4040
"[Not-all-equal 3-satisfiability (NAE3SAT)](https://en.wikipedia.org/wiki/Not-all-equal_3-satisfiability) is a variant of 3-satisfiability (3-SAT) and 3-SAT is a subset of [Boolean satisfiability problem (SAT)](https://en.wikipedia.org/wiki/Boolean_satisfiability_problem). SAT is, given a Boolean expression, to check whether it is satisfiable, where the Boolean expression is a disjunction of clauses (or a single clause) and each clause is a disjunction of literals (or a single literal). Here is an example of Boolean expression of SAT,\n",
4141
"$$\n",
42-
"\\begin{equation}\n",
43-
" (x_1\\lor x_2\\lor\\cdots\\lor x_m)\\land(\\lnot x_5\\lor x_9\\lor\\cdots\\lor x_m)\\land\\cdots\\land(x_m\\lor \\lnot x_{m+3}\\lor\\cdots\\lor \\lnot x_n),\n",
44-
"\\end{equation}\n",
42+
"(x_1\\lor x_2\\lor\\cdots\\lor x_m)\\land(\\lnot x_5\\lor x_9\\lor\\cdots\\lor x_m)\\land\\cdots\\land(x_m\\lor \\lnot x_{m+3}\\lor\\cdots\\lor \\lnot x_n),\n",
4543
"$$\n",
4644
"where $(x_i\\lor x_j\\lor\\cdots\\lor x_k)$ is a clause and $x_i$ is a literal. SAT with $k$ literals in each clause is called $k$-SAT, thus in 3-SAT, there are only three literals in each clause, for example\n",
4745
"$$\n",
48-
"\\begin{equation}\n",
49-
" (x_1\\lor x_2\\lor x_m)\\land(\\lnot x_5\\lor x_9\\lor x_m)\\land\\cdots\\land(x_m\\lor \\lnot x_{m+3}\\lor \\lnot x_n).\n",
50-
"\\end{equation}\n",
46+
"(x_1\\lor x_2\\lor x_m)\\land(\\lnot x_5\\lor x_9\\lor x_m)\\land\\cdots\\land(x_m\\lor \\lnot x_{m+3}\\lor \\lnot x_n).\n",
5147
"$$\n",
5248
"When $k$ is not less than 3, SAT is NP-complete. On the other hand, NAE3SAT requires the three literals in each clause are not all equal to each other, in other words, at least one is true, and at least one is false. It is different from 3-SAT, which requires at least one literal is true in each clause. However, NAE3SAT is still NP-complete, [which can be proven by a reduction from 3-SAT](https://en.wikipedia.org/wiki/Not-all-equal_3-satisfiability)."
5349
]
@@ -59,12 +55,10 @@
5955
"source": [
6056
"Now we use the spin model to represent a NAE3SAT. Let the set of clauses in the NAE3SAT be $\\mathcal{C}$. In each clause, there are three literals and each literal is represented by a spin. Spins up ($s=1$, $\\text{bit}=0$) and down ($s=-1$, $\\text{bit}=1$) represent false and true respectively. For the clause $(s_i,\\ s_j,\\ s_k)\\in\\mathcal{C}$, $s_i,\\ s_j,\\ s_k$ cannot be 1 or -1 at the same time. The Hamiltonian of the NAE3SAT is as follows\n",
6157
"$$\n",
62-
"\\begin{equation}\n",
63-
" \\begin{split}\n",
64-
" \\hat{H}_C&=\\sum_{(i,j,k)\\in\\mathcal{C}}\\left[(s_i+s_j+s_k)^2-1\\right]/2\\\\\n",
65-
" &=\\sum_{(i,j,k)\\in\\mathcal{C}}(s_i s_j+s_j s_k+s_k s_i)+|\\mathcal{C}|,\n",
66-
" \\end{split}\n",
67-
"\\end{equation}\n",
58+
"\\begin{split}\n",
59+
" \\hat{H}_C&=\\sum_{(i,j,k)\\in\\mathcal{C}}\\left[(s_i+s_j+s_k)^2-1\\right]/2\\\\\n",
60+
" &=\\sum_{(i,j,k)\\in\\mathcal{C}}(s_i s_j+s_j s_k+s_k s_i)+|\\mathcal{C}|,\n",
61+
"\\end{split}\n",
6862
"$$\n",
6963
"where $|\\mathcal{C}|$ is the number of clauses in $\\mathcal{C}$. When all clauses are true, $\\hat{H}_C$ takes the minimum value 0, and the corresponding bit string is the solution of the NAE3SAT."
7064
]
@@ -84,15 +78,11 @@
8478
"source": [
8579
"QAOA utilizes a parameterized quantum circuit ([PQC](https://tensorcircuit.readthedocs.io/en/latest/textbook/chap5.html?highlight=变分)) to generate a quantum state that represents a potential solution. The initial state, denoted as $|s\\rangle$, is a uniform superposition over computational basis states.\n",
8680
"$$\n",
87-
"\\begin{equation}\n",
88-
" |s\\rangle=\\frac{1}{\\sqrt{2^n}}\\sum_z|z\\rangle\n",
89-
"\\end{equation}\n",
81+
"|s\\rangle=\\frac{1}{\\sqrt{2^n}}\\sum_z|z\\rangle\n",
9082
"$$\n",
9183
"This state is then evolved by a unitary operator that consists of $p$ layers, denoted as\n",
9284
"$$\n",
93-
"\\begin{equation}\n",
94-
" U(\\boldsymbol{\\beta}, \\boldsymbol{\\gamma}) = V_{p}U_{p} \\cdots V_{1}U_{1},\n",
95-
"\\end{equation}\n",
85+
"U(\\boldsymbol{\\beta}, \\boldsymbol{\\gamma}) = V_{p}U_{p} \\cdots V_{1}U_{1},\n",
9686
"$$\n",
9787
"where $U_{j}= e^{-\\text{i}\\gamma_{j}\\hat{H}_{C}}$ is the driving layer and $V_{j}= e^{-\\text{i}\\beta_{j} \\hat{H}_m}$ is the mixing layer. $\\hat{H}_C$ is the driving and cost Hamiltonian introduced in previous section and the mixing Hamiltonian $\\hat{H}_m=\\sum_{j=1}^{n}\\sigma_j^x$ is used to mix the quantum state to explore different solutions. The unitary operator is parameterized by $2p$ angle parameters $\\gamma_1, \\gamma_2, \\dots, \\gamma_p$ and $\\beta_1, \\beta_2, \\dots ,\\beta_p$ and each $\\gamma$ and $\\beta$ are restricted to lie between $0$ and $2\\pi$."
9888
]
@@ -112,7 +102,7 @@
112102
"id": "940fa22b",
113103
"metadata": {},
114104
"source": [
115-
"### The code"
105+
"### Setup"
116106
]
117107
},
118108
{

docs/source/tutorials/qaoa_quantum_dropout.ipynb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@
4343
"\n",
4444
"Let the set of clauses in the NAE3SAT be $\\mathcal{C}$. In each clause, there are three literals and each literal is represented by a spin. Spins up ($s=1$, $\\text{bit}=0$) and down ($s=-1$, $\\text{bit}=1$) represent false and true respectively. NAE3SAT requires the three spins in each clause are not all equal to each other, in other words, at least one is up, and at least one is down. The Hamiltonian of the NAE3SAT is as follows\n",
4545
"$$\n",
46-
"\\begin{equation}\n",
47-
" \\begin{split}\n",
48-
" \\hat{H}_C&=\\sum_{(i,j,k)\\in\\mathcal{C}}\\left[(s_i+s_j+s_k)^2-1\\right]/2\\\\\n",
49-
" &=\\sum_{(i,j,k)\\in\\mathcal{C}}(s_i s_j+s_j s_k+s_k s_i)+|\\mathcal{C}|,\n",
50-
" \\end{split}\n",
51-
"\\end{equation}\n",
46+
"\\begin{split}\n",
47+
" \\hat{H}_C&=\\sum_{(i,j,k)\\in\\mathcal{C}}\\left[(s_i+s_j+s_k)^2-1\\right]/2\\\\\n",
48+
" &=\\sum_{(i,j,k)\\in\\mathcal{C}}(s_i s_j+s_j s_k+s_k s_i)+|\\mathcal{C}|,\n",
49+
"\\end{split}\n",
5250
"$$\n",
5351
"where $|\\mathcal{C}|$ is the number of clauses in $\\mathcal{C}$. When all clauses are true, $\\hat{H}_C$ takes the minimum value 0, and the corresponding bit string is the solution of the NAE3SAT.\n",
5452
"\n",
@@ -89,7 +87,7 @@
8987
{
9088
"cell_type": "markdown",
9189
"source": [
92-
"### The code"
90+
"### Setup"
9391
],
9492
"metadata": {
9593
"collapsed": false

tensorcircuit/shadows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def shadow_snapshots(
4949
sub: Optional[Sequence[int]] = None,
5050
measurement_only: bool = False,
5151
) -> Tensor:
52-
r"""To generate the shadow snapshots from given pauli string observables on $|\psi\rangle$
52+
r"""To generate the shadow snapshots from given pauli string observables on psi
5353
5454
:param psi: shape = (2 ** nq,), where nq is the number of qubits
5555
:type: Tensor

0 commit comments

Comments
 (0)