提交 21bfa298 编写于 作者: Q Quleaf

slight update

上级 100686b4
...@@ -29,7 +29,7 @@ Paddle Quantum(量桨)是基于百度飞桨开发的量子机器学习工具 ...@@ -29,7 +29,7 @@ Paddle Quantum(量桨)是基于百度飞桨开发的量子机器学习工具
- 易用性 - 易用性
- 高效搭建量子神经网络 - 高效搭建量子神经网络
- 多种量子神经网络模板 - 多种量子神经网络模板
- 丰富量子算法教程(10+用例) - 丰富量子算法教程(10+用例)
- 可拓展性 - 可拓展性
- 支持通用量子电路模型 - 支持通用量子电路模型
- 高性能模拟器支持20多个量子比特的模拟运算 - 高性能模拟器支持20多个量子比特的模拟运算
......
...@@ -21,7 +21,7 @@ Paddle Quantum (量桨) ...@@ -21,7 +21,7 @@ Paddle Quantum (量桨)
- 高效搭建量子神经网络 - 高效搭建量子神经网络
- 多种量子神经网络模板 - 多种量子神经网络模板
- 丰富量子算法教程(10+用例) - 丰富量子算法教程(10+用例)
- 可拓展性 - 可拓展性
......
...@@ -22,7 +22,7 @@ import numpy ...@@ -22,7 +22,7 @@ import numpy
from paddle.complex import matmul from paddle.complex import matmul
from paddle import fluid from paddle import fluid
from paddle_quantum.circuit import UAnsatz from paddle_quantum.circuit import UAnsatz
from paddle_quantum.utils import hermitian from paddle_quantum.utils import dagger
from paddle_quantum.SSVQE.HGenerator import H_generator from paddle_quantum.SSVQE.HGenerator import H_generator
SEED = 14 # 固定随机种子 SEED = 14 # 固定随机种子
...@@ -67,7 +67,7 @@ class Net(fluid.dygraph.Layer): ...@@ -67,7 +67,7 @@ class Net(fluid.dygraph.Layer):
U = U_theta(self.theta, N) U = U_theta(self.theta, N)
# 计算损失函数 # 计算损失函数
loss_struct = matmul(matmul(hermitian(U), H), U).real loss_struct = matmul(matmul(dagger(U), H), U).real
# 输入计算基去计算每个子期望值,相当于取 U^dagger*H*U 的对角元 # 输入计算基去计算每个子期望值,相当于取 U^dagger*H*U 的对角元
loss_components = [ loss_components = [
......
...@@ -20,7 +20,7 @@ you could check the corresponding Jupyter notebook under the Tutorial folder. ...@@ -20,7 +20,7 @@ you could check the corresponding Jupyter notebook under the Tutorial folder.
import numpy import numpy
from paddle import fluid from paddle import fluid
from paddle_quantum.circuit import UAnsatz from paddle_quantum.circuit import UAnsatz
from paddle_quantum.utils import hermitian from paddle_quantum.utils import dagger
from paddle.complex import matmul, trace from paddle.complex import matmul, trace
from paddle_quantum.VQSD.HGenerator import generate_rho_sigma from paddle_quantum.VQSD.HGenerator import generate_rho_sigma
...@@ -70,7 +70,7 @@ class Net(fluid.dygraph.Layer): ...@@ -70,7 +70,7 @@ class Net(fluid.dygraph.Layer):
U = U_theta(self.theta, N) U = U_theta(self.theta, N)
# rho_tilde 是将 U 作用在 rho 后得到的量子态 U*rho*U^dagger # rho_tilde 是将 U 作用在 rho 后得到的量子态 U*rho*U^dagger
rho_tilde = matmul(matmul(U, self.rho), hermitian(U)) rho_tilde = matmul(matmul(U, self.rho), dagger(U))
# 计算损失函数 # 计算损失函数
loss = trace(matmul(self.sigma, rho_tilde)) loss = trace(matmul(self.sigma, rho_tilde))
......
...@@ -33,7 +33,7 @@ from paddle.fluid import dygraph ...@@ -33,7 +33,7 @@ from paddle.fluid import dygraph
from paddle.fluid.layers import reshape, cast, eye, zeros from paddle.fluid.layers import reshape, cast, eye, zeros
from paddle.fluid.framework import ComplexVariable from paddle.fluid.framework import ComplexVariable
from paddle_quantum.utils import hermitian, pauli_str_to_matrix from paddle_quantum.utils import dagger, pauli_str_to_matrix
from paddle_quantum.intrinsic import * from paddle_quantum.intrinsic import *
from paddle_quantum.state import density_op from paddle_quantum.state import density_op
...@@ -166,7 +166,7 @@ class UAnsatz: ...@@ -166,7 +166,7 @@ class UAnsatz:
state = dygraph.to_variable(density_op(self.n)) if input_state is None else input_state state = dygraph.to_variable(density_op(self.n)) if input_state is None else input_state
assert state.real.shape == [2 ** self.n, 2 ** self.n], "The dimension is not right" assert state.real.shape == [2 ** self.n, 2 ** self.n], "The dimension is not right"
state = matmul(self.U, matmul(state, hermitian(self.U))) state = matmul(self.U, matmul(state, dagger(self.U)))
if store_state: if store_state:
self.__state = state self.__state = state
......
...@@ -46,7 +46,7 @@ __all__ = [ ...@@ -46,7 +46,7 @@ __all__ = [
"von_neumann_entropy", "von_neumann_entropy",
"relative_entropy", "relative_entropy",
"NKron", "NKron",
"hermitian", "dagger",
"random_pauli_str_generator", "random_pauli_str_generator",
"pauli_str_to_matrix" "pauli_str_to_matrix"
] ]
...@@ -220,7 +220,7 @@ def NKron(matrix_A, matrix_B, *args): ...@@ -220,7 +220,7 @@ def NKron(matrix_A, matrix_B, *args):
return reduce(lambda result, index: np_kron(result, index), args, np_kron(matrix_A, matrix_B), ) return reduce(lambda result, index: np_kron(result, index), args, np_kron(matrix_A, matrix_B), )
def hermitian(matrix): def dagger(matrix):
r"""计算矩阵的埃尔米特转置,即Hermitian transpose。 r"""计算矩阵的埃尔米特转置,即Hermitian transpose。
Args: Args:
...@@ -233,12 +233,12 @@ def hermitian(matrix): ...@@ -233,12 +233,12 @@ def hermitian(matrix):
.. code-block:: python .. code-block:: python
from paddle_quantum.utils import hermitian from paddle_quantum.utils import dagger
from paddle import fluid from paddle import fluid
import numpy as np import numpy as np
with fluid.dygraph.guard(): with fluid.dygraph.guard():
rho = fluid.dygraph.to_variable(np.array([[1+1j, 2+2j], [3+3j, 4+4j]])) rho = fluid.dygraph.to_variable(np.array([[1+1j, 2+2j], [3+3j, 4+4j]]))
print(hermitian(rho).numpy()) print(dagger(rho).numpy())
:: ::
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
"\n", "\n",
"> 注意,本篇教程具有时效性。同时不同电脑也会有个体差异性,本篇教程不保证所有电脑可以安装成功。\n", "> 注意,本篇教程具有时效性。同时不同电脑也会有个体差异性,本篇教程不保证所有电脑可以安装成功。\n",
"\n", "\n",
"众所周知,在深度学习中,大家都会选择使用 GPU 来进行神经网络模型的训练,因为与 CPU 相比,GPU在浮点数运算方面有着显著的优势。因此,使用 GPU 来训练神经网络模型逐渐成为共同的选择。在 Paddle Quantum 中,我们的量子态和量子门也采用基于浮点数的复数表示,因此我们的模型如果能部署到 GPU 上进行训练,也会显著提升训练速度。\n", "在深度学习中,大家通常会使用 GPU 来进行神经网络模型的训练,因为与 CPU 相比,GPU在浮点数运算方面有着显著的优势。因此,使用 GPU 来训练神经网络模型逐渐成为共同的选择。在 Paddle Quantum 中,我们的量子态和量子门也采用基于浮点数的复数表示,因此我们的模型如果能部署到 GPU 上进行训练,也会显著提升训练速度。\n",
"\n", "\n",
"## 2. GPU 选择\n", "## 2. GPU 选择\n",
"\n", "\n",
"在这里,我们推荐选择 Nvidia 的硬件设备,其 CUDA(Compute Unified Device Architecture) 对深度学习的框架支持更好。我们的 PaddlePaddle 也可以比较方便地安装在 CUDA 上。\n", "在这里,我们使用 Nvidia 的硬件设备,其 CUDA(Compute Unified Device Architecture) 对深度学习的框架支持比较好。我们的 PaddlePaddle 也可以比较方便地安装在 CUDA 上。\n",
"\n", "\n",
"## 3. 配置 CUDA 环境\n", "## 3. 配置 CUDA 环境\n",
"\n", "\n",
...@@ -128,7 +128,6 @@ ...@@ -128,7 +128,6 @@
"from paddle import fluid\n", "from paddle import fluid\n",
"from paddle.complex import matmul, transpose\n", "from paddle.complex import matmul, transpose\n",
"from paddle_quantum.circuit import UAnsatz\n", "from paddle_quantum.circuit import UAnsatz\n",
"from paddle_quantum.utils import hermitian\n",
"import matplotlib.pyplot as plt\n", "import matplotlib.pyplot as plt\n",
"import numpy\n", "import numpy\n",
"from paddle_quantum.VQE.chemistrysub import H2_generator\n", "from paddle_quantum.VQE.chemistrysub import H2_generator\n",
...@@ -338,7 +337,7 @@ ...@@ -338,7 +337,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.3" "version": "3.7.7"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
"from paddle.complex import matmul, trace\n", "from paddle.complex import matmul, trace\n",
"from paddle_quantum.circuit import UAnsatz\n", "from paddle_quantum.circuit import UAnsatz\n",
"from paddle_quantum.state import density_op\n", "from paddle_quantum.state import density_op\n",
"from paddle_quantum.utils import state_fidelity, partial_trace, hermitian, pauli_str_to_matrix" "from paddle_quantum.utils import state_fidelity, partial_trace, pauli_str_to_matrix"
] ]
}, },
{ {
...@@ -385,7 +385,7 @@ ...@@ -385,7 +385,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.9" "version": "3.7.7"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
"from paddle import fluid\n", "from paddle import fluid\n",
"from paddle_quantum.circuit import UAnsatz\n", "from paddle_quantum.circuit import UAnsatz\n",
"from paddle.complex import matmul, trace, kron\n", "from paddle.complex import matmul, trace, kron\n",
"from paddle_quantum.utils import hermitian, state_fidelity, partial_trace" "from paddle_quantum.utils import dagger, state_fidelity, partial_trace"
] ]
}, },
{ {
...@@ -182,7 +182,7 @@ ...@@ -182,7 +182,7 @@
" def forward(self):\n", " def forward(self):\n",
" # 生成初始的编码器 E 和解码器 D\\n\",\n", " # 生成初始的编码器 E 和解码器 D\\n\",\n",
" E = Encoder(self.theta)\n", " E = Encoder(self.theta)\n",
" E_dagger = hermitian(E)\n", " E_dagger = dagger(E)\n",
" D = E_dagger\n", " D = E_dagger\n",
" D_dagger = E\n", " D_dagger = E\n",
"\n", "\n",
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.9" "version": "3.7.7"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -922,7 +922,7 @@ ...@@ -922,7 +922,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.10" "version": "3.7.7"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
"import paddle\n", "import paddle\n",
"from paddle import fluid\n", "from paddle import fluid\n",
"from paddle_quantum.circuit import UAnsatz\n", "from paddle_quantum.circuit import UAnsatz\n",
"from paddle_quantum.utils import partial_trace, hermitian, state_fidelity\n", "from paddle_quantum.utils import partial_trace, dagger, state_fidelity\n",
"from paddle import complex\n", "from paddle import complex\n",
"from progressbar import *" "from progressbar import *"
] ]
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
" \"\"\"\n", " \"\"\"\n",
" state = self.target_state\n", " state = self.target_state\n",
" state = complex.reshape(state, [1] + state.shape)\n", " state = complex.reshape(state, [1] + state.shape)\n",
" density_matrix = complex.matmul(hermitian(state), state)\n", " density_matrix = complex.matmul(dagger(state), state)\n",
" state = partial_trace(density_matrix, 2, 4, 2)\n", " state = partial_trace(density_matrix, 2, 4, 2)\n",
"\n", "\n",
" return state.numpy()\n", " return state.numpy()\n",
...@@ -239,7 +239,7 @@ ...@@ -239,7 +239,7 @@
" \"\"\"\n", " \"\"\"\n",
" state = self.generator(self.gen_theta).run_state_vector()\n", " state = self.generator(self.gen_theta).run_state_vector()\n",
" state = complex.reshape(state, [1] + state.shape)\n", " state = complex.reshape(state, [1] + state.shape)\n",
" density_matrix = complex.matmul(hermitian(state), state)\n", " density_matrix = complex.matmul(dagger(state), state)\n",
" state = partial_trace(density_matrix, 2, 4, 2)\n", " state = partial_trace(density_matrix, 2, 4, 2)\n",
"\n", "\n",
" return state.numpy()" " return state.numpy()"
...@@ -482,7 +482,7 @@ ...@@ -482,7 +482,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.9" "version": "3.7.7"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -839,7 +839,7 @@ ...@@ -839,7 +839,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.10" "version": "3.7.7"
}, },
"pycharm": { "pycharm": {
"stem_cell": { "stem_cell": {
......
...@@ -820,7 +820,7 @@ ...@@ -820,7 +820,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.10" "version": "3.7.7"
}, },
"pycharm": { "pycharm": {
"stem_cell": { "stem_cell": {
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
"from paddle.complex import matmul, transpose\n", "from paddle.complex import matmul, transpose\n",
"from paddle import fluid\n", "from paddle import fluid\n",
"from paddle_quantum.circuit import UAnsatz\n", "from paddle_quantum.circuit import UAnsatz\n",
"from paddle_quantum.utils import random_pauli_str_generator, pauli_str_to_matrix, hermitian" "from paddle_quantum.utils import random_pauli_str_generator, pauli_str_to_matrix, dagger"
] ]
}, },
{ {
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Random Hamiltonian in Pauli string format = \n", "Random Hamiltonian in Pauli string format = \n",
" [[-0.370073566586669, 'x0'], [0.5866720906246325, 'x0'], [-0.9723198195208609, 'x0,y1'], [0.7007292863508459, 'y0,y1'], [0.80763905789957, 'z1'], [-0.7395686405536626, 'z0'], [0.8988849291817222, 'y0'], [-0.617070687255681, 'z0,z1'], [0.8230276264234271, 'y1,z0'], [0.11655495624091028, 'y1']]\n" " [[-0.9208973013017021, 'y0,y1'], [0.198490728051139, 'y1'], [0.9587239095910918, 'x1'], [0.07176335076663909, 'x1'], [-0.7920788641602743, 'x1'], [-0.5028229022143014, 'x0'], [-0.14565978959930526, 'z1,y0'], [0.5965836192828249, 'z1,z0'], [0.6251774164147041, 'y1,y0'], [-0.1580838163596252, 'z0,x1']]\n"
] ]
} }
], ],
...@@ -170,7 +170,7 @@ ...@@ -170,7 +170,7 @@
" U = U_theta(self.theta, N)\n", " U = U_theta(self.theta, N)\n",
" \n", " \n",
" # 计算损失函数\n", " # 计算损失函数\n",
" loss_struct = matmul(matmul(hermitian(U), H), U).real\n", " loss_struct = matmul(matmul(dagger(U), H), U).real\n",
"\n", "\n",
" # 输入计算基去计算每个子期望值,相当于取 U^dagger*H*U 的对角元 \n", " # 输入计算基去计算每个子期望值,相当于取 U^dagger*H*U 的对角元 \n",
" loss_components = [\n", " loss_components = [\n",
...@@ -235,11 +235,11 @@ ...@@ -235,11 +235,11 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"iter: 10 loss: -8.5409\n", "iter: 10 loss: -3.8289\n",
"iter: 20 loss: -8.8731\n", "iter: 20 loss: -3.9408\n",
"iter: 30 loss: -9.1038\n", "iter: 30 loss: -3.9473\n",
"iter: 40 loss: -9.2157\n", "iter: 40 loss: -3.9480\n",
"iter: 50 loss: -9.2681\n" "iter: 50 loss: -3.9481\n"
] ]
} }
], ],
...@@ -297,14 +297,14 @@ ...@@ -297,14 +297,14 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"The estimated ground state energy is: [-2.33059408]\n", "The estimated ground state energy is: [-1.07559121]\n",
"The theoretical ground state energy: -2.3654429645786506\n", "The theoretical ground state energy: -1.0756323552750124\n",
"The estimated 1st excited state energy is: [-1.69552621]\n", "The estimated 1st excited state energy is: [-0.72131763]\n",
"The theoretical 1st excited state energy: -1.6867829339244156\n", "The theoretical 1st excited state energy: -0.7213113808180259\n",
"The estimated 2nd excited state energy is: [1.11478154]\n", "The estimated 2nd excited state energy is: [0.72132372]\n",
"The theoretical 2nd excited state energy: 1.1321233803877833\n", "The theoretical 2nd excited state energy: 0.7213113808180256\n",
"The estimated 3rd excited state energy is: [2.91133876]\n", "The estimated 3rd excited state energy is: [1.07558513]\n",
"The theoretical 3rd excited state energy: 2.920102518115284\n" "The theoretical 3rd excited state energy: 1.0756323552750122\n"
] ]
} }
], ],
...@@ -357,7 +357,7 @@ ...@@ -357,7 +357,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.10" "version": "3.7.7"
}, },
"pycharm": { "pycharm": {
"stem_cell": { "stem_cell": {
......
此差异已折叠。
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
"import scipy\n", "import scipy\n",
"from paddle import fluid\n", "from paddle import fluid\n",
"from paddle_quantum.circuit import UAnsatz\n", "from paddle_quantum.circuit import UAnsatz\n",
"from paddle_quantum.utils import hermitian\n", "from paddle_quantum.utils import dagger\n",
"from paddle.complex import matmul, trace, transpose" "from paddle.complex import matmul, trace, transpose"
] ]
}, },
...@@ -182,7 +182,7 @@ ...@@ -182,7 +182,7 @@
" U = U_theta(self.theta, N)\n", " U = U_theta(self.theta, N)\n",
"\n", "\n",
" # rho_tilde 是将 U 作用在 rho 后得到的量子态 U*rho*U^dagger \n", " # rho_tilde 是将 U 作用在 rho 后得到的量子态 U*rho*U^dagger \n",
" rho_tilde = matmul(matmul(U, self.rho), hermitian(U))\n", " rho_tilde = matmul(matmul(U, self.rho), dagger(U))\n",
"\n", "\n",
" # 计算损失函数\n", " # 计算损失函数\n",
" loss = trace(matmul(self.sigma, rho_tilde))\n", " loss = trace(matmul(self.sigma, rho_tilde))\n",
...@@ -345,7 +345,7 @@ ...@@ -345,7 +345,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.10" "version": "3.7.7"
}, },
"pycharm": { "pycharm": {
"stem_cell": { "stem_cell": {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册