Skip to content

Commit

Permalink
!1913 update tutorial and fix bug
Browse files Browse the repository at this point in the history
Merge pull request !1913 from dsdsdshe/master
  • Loading branch information
donghufeng authored and gitee-org committed Sep 28, 2023
2 parents 15bb681 + a241611 commit 034bce9
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/api_python/mindquantum.core.gates.Rxx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mindquantum.core.gates.Rxx

.. math::
{\rm Rxx_\theta}=\exp{-i\frac{\theta}{2} X\otimes X} =\begin{pmatrix}
{\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\\
Expand Down
2 changes: 1 addition & 1 deletion docs/api_python/mindquantum.core.gates.Rxy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mindquantum.core.gates.Rxy

.. math::
{\rm Rxy_\theta}=\exp{-i\frac{\theta}{2} Y\otimes X} =\begin{pmatrix}
{\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\\
Expand Down
2 changes: 1 addition & 1 deletion docs/api_python/mindquantum.core.gates.Rxz.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mindquantum.core.gates.Rxz

.. math::
{\rm Rxz_\theta}=\exp{-i\frac{\theta}{2} Z\otimes X} =\begin{pmatrix}
{\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}}\\
Expand Down
2 changes: 1 addition & 1 deletion docs/api_python/mindquantum.core.gates.Ryy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mindquantum.core.gates.Ryy

.. math::
{\rm Ryy_\theta}=\exp{-i\frac{\theta}{2} Y\otimes Y} =\begin{pmatrix}
{\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\\
Expand Down
2 changes: 1 addition & 1 deletion docs/api_python/mindquantum.core.gates.Ryz.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mindquantum.core.gates.Ryz

.. math::
{\rm Ryz_\theta}=\exp{-i\frac{\theta}{2} Z\otimes Y} =\begin{pmatrix}
{\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}}\\
Expand Down
2 changes: 1 addition & 1 deletion docs/api_python/mindquantum.core.gates.Rzz.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mindquantum.core.gates.Rzz

.. math::
{\rm Rzz_\theta}=\exp{-i\frac{\theta}{2} Z\otimes Z} =\begin{pmatrix}
{\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\\
Expand Down
12 changes: 6 additions & 6 deletions mindquantum/core/gates/basicgate.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ class Rzz(RotSelfHermMat):
.. math::
Rzz(\theta) = \exp{-i\frac{\theta}{2} Z\otimes Z} =
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\\
Expand Down Expand Up @@ -1058,7 +1058,7 @@ class Rxx(RotSelfHermMat):
.. math::
Rxx(\theta) = \exp{-i\frac{\theta}{2} X\otimes X} =
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\\
Expand Down Expand Up @@ -1141,7 +1141,7 @@ class Ryy(RotSelfHermMat):
.. math::
Ryy(\theta) = \exp{-i\frac{\theta}{2} Y\otimes Y} =
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\\
Expand Down Expand Up @@ -1224,7 +1224,7 @@ class Rxy(RotSelfHermMat):
.. math::
Rxy(\theta) = \exp{-i\frac{\theta}{2} Y\otimes X} =
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\\
Expand Down Expand Up @@ -1299,7 +1299,7 @@ class Rxz(RotSelfHermMat):
.. math::
Rxz(\theta) = \exp{-i\frac{\theta}{2} Z\otimes X} =
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\\
Expand Down Expand Up @@ -1372,7 +1372,7 @@ class Ryz(RotSelfHermMat):
.. math::
Ryz(\theta) = \exp{-i\frac{\theta}{2} Z\otimes Y} =
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\\
Expand Down
2 changes: 2 additions & 0 deletions tutorials/classification_of_iris_by_qnn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"\n",
"## 概述\n",
"\n",
"量子神经网络是一类将人工神经网络与量子计算相结合的算法。在经典神经网络中,人们以类似人脑神经系统的网状结构作为计算模型,对特定问题进行预测,并根据真实结果对神经元的参数进行优化,反复迭代直到模型能较为准确的预测结果。而在量子线路中,我们同样可以搭建出类似的网状结构,并将其中一些含参数的门作为神经元,然后我们可以测量出相关哈密顿量的期望值作为损失函数,对门参数进行优化,直到找出最优参数。这样,我们就训练出了一个量子神经网络。量子并行性或量子纠缠有可能为量子神经网络带来额外的优势,但目前还没有证据表明量子神经网络相比经典神经网络具有优越性。一个典型的量子神经网络包含 Encoder(编码层)和 Ansatz(训练层),Encoder 可以将经典数据编码到量子态中,常见的编码方式有振幅编码、相位编码和IQP编码等。Ansatz可以根据输入给出预测结果,常见的 Ansatz 有 Hardware Efficient Ansatz、Strongly Entangling Ansatz 等。\n",
"\n",
"在之前的案例中,我们介绍了什么是变分量子线路,并通过一个简单的例子体验了如何搭建量子神经网络来解决一个小问题。在本文档中,我们将体验升级,将会介绍如何通过搭建量子神经网络来解决经典机器学习中的问题。我们选取的问题是:监督学习中的鸢尾花分类问题。\n",
"\n",
"问题描述:鸢尾花(iris)数据集是经典机器学习中常用的数据集,该数据集总共包含150个样本(分为3种不同的亚属:山鸢尾(setosa)、杂色鸢尾(versicolor)和维吉尼亚鸢尾(virginica),每个亚属各有50个样本),每个样本包含4个特征,分别为花萼长度(sepal length)、花萼宽度(sepal width)和花瓣长度(petal length)、花瓣宽度(petal width)。\n",
Expand Down
10 changes: 5 additions & 5 deletions tutorials/parameterized_quantum_circuit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
" \\end{matrix}\n",
"\\right).$$\n",
"\n",
"我们令$\\theta$分别为$0\\frac{\\pi}{2}$和$\\pi$,然后打印$\\text{RX}(0)$门、$\\text{RY}(\\frac{\\pi}{2}$)门和$\\text{RZ}(\\pi)$门的矩阵形式,可以得到:"
"我们令$\\theta$分别为$0$和$\\pi$,然后打印$\\text{RX}(0)$门、$\\text{RY}(\\pi)$门和$\\text{RZ}(\\pi)$门的矩阵形式,可以得到:"
]
},
{
Expand Down Expand Up @@ -350,8 +350,8 @@
{
"data": {
"text/plain": [
"array([[ 0.70710678+0.j, -0.70710678+0.j],\n",
" [ 0.70710678+0.j, 0.70710678+0.j]])"
"array([[ 6.123234e-17+0.j, -1.000000e+00+0.j],\n",
" [ 1.000000e+00+0.j, 6.123234e-17+0.j]])"
]
},
"execution_count": 8,
Expand All @@ -362,14 +362,14 @@
"source": [
"ry = RY('theta')\n",
"print('Gate name:', ry)\n",
"ry.matrix({'theta': np.pi/2}) # pi需要从np中导入,赋予theta的值为pi/2"
"ry.matrix({'theta': np.pi}) # pi需要从np中导入,赋予theta的值为pi"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"当$\\theta=\\frac{\\pi}{2}$时,此时$\\text{RY}(\\frac{\\pi}{2})$门就是我们熟悉的`H`门。"
"当$\\theta=\\pi$时,此时$\\text{RY}(\\pi)$门就是我们熟悉的`Y`门。(相差一个全局相位$i$)"
]
},
{
Expand Down

0 comments on commit 034bce9

Please sign in to comment.