Skip to content

Commit 318b324

Browse files
committed
Update classical_shadows.ipynb and imag_time_evo.ipynb
1 parent 6bc90e6 commit 318b324

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

docs/source/tutorial.rst

+1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ Jupyter Tutorials
2525
tutorials/barren_plateaus.ipynb
2626
tutorials/qaoa_portfolio_optimization.ipynb
2727
tutorials/imag_time_evo.ipynb
28+
tutorials/classical_shadows.ipynb
2829
tutorials/sklearn_svc.ipynb
2930
tutorials/qcloud_sdk_demo.ipynb

docs/source/tutorials/classical_shadows.ipynb

+22-15
Original file line numberDiff line numberDiff line change
@@ -78,28 +78,28 @@
7878
"$$\n",
7979
"where\n",
8080
"$$\n",
81-
"\\begin{equation}\n",
82-
" \\begin{split}\n",
83-
" \\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",
84-
" &=\\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",
85-
" \\end{split}\n",
86-
"\\end{equation}\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",
8785
"$$"
8886
],
8987
"metadata": {
9088
"collapsed": false
9189
}
9290
},
91+
{
92+
"cell_type": "markdown",
93+
"source": [
94+
"## Setup"
95+
],
96+
"metadata": {
97+
"collapsed": false
98+
}
99+
},
93100
{
94101
"cell_type": "code",
95102
"execution_count": 13,
96-
"metadata": {
97-
"collapsed": true,
98-
"ExecuteTime": {
99-
"end_time": "2023-08-09T04:51:21.649753Z",
100-
"start_time": "2023-08-09T04:51:21.598273400Z"
101-
}
102-
},
103103
"outputs": [
104104
{
105105
"data": {
@@ -120,7 +120,14 @@
120120
"\n",
121121
"tc.set_backend(\"jax\")\n",
122122
"tc.set_dtype(\"complex128\")"
123-
]
123+
],
124+
"metadata": {
125+
"collapsed": false,
126+
"ExecuteTime": {
127+
"end_time": "2023-08-09T04:51:21.649753Z",
128+
"start_time": "2023-08-09T04:51:21.598273400Z"
129+
}
130+
}
124131
},
125132
{
126133
"cell_type": "markdown",
@@ -590,7 +597,7 @@
590597
"On the other hand, for the second order Renyi entropy, we have another method to calculate it in polynomial time by random measurements:\n",
591598
"$$\n",
592599
"\\begin{eqnarray}\n",
593-
" S_2&=&-\\log\\left(\\text{Tr}(\\rho_A^2)\\right),\\\\\n",
600+
" R_A^2&=&-\\log\\left(\\text{Tr}(\\rho_A^2)\\right),\\\\\n",
594601
" \\text{Tr}(\\rho_A^2)&=&2^k\\sum_{b,b'\\in\\{0,1\\}^k}(-2)^{-H(b,b')}\\overline{P(b)P(b')},\n",
595602
"\\end{eqnarray}\n",
596603
"$$\n",

docs/source/tutorials/imag_time_evo.ipynb

+12-3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@
7575
"collapsed": false
7676
}
7777
},
78+
{
79+
"cell_type": "markdown",
80+
"source": [
81+
"## Setup"
82+
],
83+
"metadata": {
84+
"collapsed": false
85+
}
86+
},
7887
{
7988
"cell_type": "code",
8089
"execution_count": null,
@@ -414,7 +423,7 @@
414423
{
415424
"cell_type": "markdown",
416425
"source": [
417-
"We use two methods to calculate $\\boldsymbol{\\delta}$, one is to calculate directly according to the expressions of $\\boldsymbol{A}$ and $\\boldsymbol{C}$, and the other is to call the existing API to calculate $\\boldsymbol{A}$ and $\\boldsymbol{C}$. The former only needs to calculate the $|\\partial_{\\boldsymbol{\\theta}_{j}}\\psi\\rangle$ once, while the latter needs to calculate that twice, but the code of the latter is more concise. In each method, we set the parameter fixed_global_phase to decide whether to fix the global phase, that is, whether the second term of $\\boldsymbol{A}$ vanishes.\n",
426+
"We use two methods to calculate $\\boldsymbol{\\delta}$, one is to calculate directly according to the expressions of $\\boldsymbol{A}$ and $\\boldsymbol{C}$, and the other is to call the existing API to calculate $\\boldsymbol{A}$ and $\\boldsymbol{C}$. The former only needs to calculate the $|\\partial_{\\boldsymbol{\\theta}_{j}}\\psi\\rangle$ once, while the latter needs to calculate that twice, but the code of the latter is more concise. In each method, we set the parameter ``fixed_global_phase`` to decide whether to fix the global phase, that is, whether the second term of $\\boldsymbol{A}$ vanishes.\n",
418427
"\n",
419428
"Then we choose the existing optimizer, SGD, to implement the update step. Since compared with naive gradient descent, the approximate imaginary-time evolution has been corrected on the update step size, the adaptive optimizer improved for the naive gradient descent such as Adam is not suitable for the approximate imaginary-time evolution. When update by the adaptive optimizer, the loss function fluctuates greatly. On the other hand, the update method of SGD without momentum is naive update, which is convenient for comparison with the exact imaginary-time evolution."
420429
],
@@ -576,7 +585,7 @@
576585
{
577586
"cell_type": "markdown",
578587
"source": [
579-
"We first show the overlap between the final states obtained by different methods. The final states obtained by different methods but with the same parameter of fixed_global_phase are almost the same, which are also close to the exact final state. And the final states obtained by the same method but with the different parameter of fixed_global_phase has a global phase difference."
588+
"We first show the overlap between the final states obtained by different methods. The final states obtained by different methods but with the same parameter of ``fixed_global_phase`` are almost the same, which are also close to the exact final state. And the final states obtained by the same method but with the different parameter of ``fixed_global_phase`` has a global phase difference."
580589
],
581590
"metadata": {
582591
"collapsed": false
@@ -915,7 +924,7 @@
915924
{
916925
"cell_type": "markdown",
917926
"source": [
918-
"We also use two methods to calculate $\\boldsymbol{\\delta}$, but make some changes in the method of directly calling the API and the update method. When calculating $\\boldsymbol{A}$, we call qng2 instead of qng, and when calculating $\\boldsymbol{C}$, we call dynamics_rhs instead of calculating the energy gradient by value_and_grad. For the update method, we do not call the existing optimizer but directly adopt the naive update method."
927+
"We also use two methods to calculate $\\boldsymbol{\\delta}$, but make some changes in the method of directly calling the API and the update method. When calculating $\\boldsymbol{A}$, we call ``qng2`` instead of ``qng``, and when calculating $\\boldsymbol{C}$, we call ``dynamics_rhs`` instead of calculating the energy gradient by ``value_and_grad``. For the update method, we do not call the existing optimizer but directly adopt the naive update method."
919928
],
920929
"metadata": {
921930
"collapsed": false

0 commit comments

Comments
 (0)