提交 4088bcbf 编写于 作者: Q Quleaf

update to v1.1.1

上级 864c05ed
English | [简体中文](README_CN.md)
# Paddle Quantum (量桨)
# Paddle Quantum (量桨)
- [Features](#features)
- [Install](#install)
......@@ -63,7 +63,7 @@ pip install -e .
python -m pip install --upgrade -r requirements.txt
```
### Use OpenFermion to read xyz molecule configuration file
### Use OpenFermion to read .xyz molecule configuration file
> Only macOS and linux users can use OpenFermion to read .xyz description files.
......
......@@ -168,9 +168,6 @@ Paddle Quantum 使用 setuptools 的 develop 模式进行安装,相关代码
答:量桨是基于百度飞桨开发的量子机器学习工具集。飞桨作为国内首个开源开放的产业级深度学习平台,技术领先且功能完备。拥有飞桨的技术支持,特别是其强大的动态图机制,量桨可以方便地进行机器学习的优化以及 GPU 的加速。同时,基于百度量子计算研究所研发的高性能量子模拟器,量桨在个人笔记本电脑上也能支持20多个量子比特的运算。另外,量桨还有丰富的[量子机器学习案例](./tutorial)供大家参考和学习。
5. 问:**非常想试用量桨,该怎么入门呢?**
答:建议新用户首先阅读量桨的[入门手册](./introduction),它包含量桨详细的安装步骤以及入门教程。另外,量桨提供了丰富的[量子机器学习案例](./tutorial),以 Jupyter Notebook 和 PDF 的方式呈现,方便用户学习和实践。如在学习和使用过程中遇到任何问题,欢迎用户通过 [Github Issues](https://github.com/PaddlePaddle/Quantum/issues) 以及技术交流QQ群(1076223166)与我们交流。
## Copyright and License
......
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd
paddlepaddle>=1.8.3
networkx>=2.4
matplotlib>=3.3.0
interval>=1.0.0
progressbar>=2.5
sphinx
sphinx-rtd-theme
PyStemmer
readthedocs-sphinx-search
jieba
\ No newline at end of file
# -*- coding: utf-8 -*-
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('../..'))
# -- Project information -----------------------------------------------------
project = 'Paddle Quantum'
copyright = u'2020, Institute for Quantum Computing, Baidu Inc.'
author = u'Institute for Quantum Computing, Baidu Inc.'
# The full version, including alpha/beta/rc tags
release = '1.1.0'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.mathjax',
'sphinx_search.extension',
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'zh_CN'
html_search_language = 'zh'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_logo = '_static/logo.png'
master_doc = 'index'
# Autodoc
autodoc_member_order = 'bysource'
.. Paddle Quantum documentation master file, created by
sphinx-quickstart on Fri Aug 21 10:54:43 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to Paddle Quantum's documentation!
==========================================
.. toctree::
:maxdepth: 2
:caption: Paddle Quantum 入门
introduction
tutorial
.. toctree::
:maxdepth: 4
:caption: API 文档
modules
.. _header-n0:
Paddle Quantum (量桨)
=======================
`Paddle Quantum(量桨) <https://github.com/PaddlePaddle/Quantum>`__\ 是基于百度飞桨开发的量子机器学习工具集,支持量子神经网络的搭建与训练,提供易用的量子机器学习开发套件与量子优化、量子化学等前沿量子应用工具集,使得百度飞桨也因此成为国内首个目前也是唯一一个支持量子机器学习的深度学习框架。
.. figure:: https://release-data.cdn.bcebos.com/Paddle%20Quantum.png
:target: https://github.com/PaddlePaddle/Quantum
量桨建立起了人工智能与量子计算的桥梁,不但可以快速实现量子神经网络的搭建与训练,还提供易用的量子机器学习开发套件与量子优化、量子化学等前沿量子应用工具集,并提供多项自研量子机器学习应用。通过百度飞桨深度学习平台赋能量子计算,量桨为领域内的科研人员以及开发者便捷地开发量子人工智能的应用提供了强有力的支撑,同时也为广大量子计算爱好者提供了一条可行的学习途径。
关于量桨的更多内容可以查看 GitHub 页面:https://github.com/PaddlePaddle/Quantum
.. _header-n6:
特色
----
- 易用性
- 高效搭建量子神经网络
- 多种量子神经网络模板
- 丰富的量子算法教程(10+用例)
- 可拓展性
- 支持通用量子电路模型
- 高性能模拟器支持20多个量子比特的模拟运算
- 提供多种优化工具和 GPU 加速
- 特色工具集
- 提供组合优化和量子化学等前沿领域的计算工具箱
- 自研多种量子机器学习算法
.. _header-n15:
安装步骤
--------
.. _header-n16:
安装 PaddlePaddle
~~~~~~~~~~~~~~~~~
请参考
`PaddlePaddle <https://www.paddlepaddle.org.cn/install/quick>`__
安装配置页面。此项目需求 PaddlePaddle 1.8.3 或更高版本。
.. _header-n19:
下载 Paddle Quantum 并安装
~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code:: shell
git clone http://github.com/PaddlePaddle/quantum
.. code:: shell
cd quantum
pip install -e .
.. _header-n23:
或使用 requirements.txt 安装依赖包
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code:: shell
python -m pip install --upgrade -r requirements.txt
.. _header-n25:
使用 openfermion 读取 xyz 描述文件
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. note:: 仅在 macOS 和 linux 下可以使用 openfermion 读取 xyz 描述文件。
VQE中调用 openfermion 读取分子 xyz 文件并计算,因此需要安装 openfermion 和
openfermionpyscf。
.. code:: shell
pip install openfermion
pip install openfermionpyscf
.. _header-n29:
运行
~~~~
现在,可以试着运行一段程序来验证量桨是否已安装成功。这里我们运行量桨提供的量子近似优化算法
(QAOA) 的例子。
.. code:: shell
cd paddle_quantum/QAOA/example
python main.py
..
.. note:: 关于 QAOA 的介绍可以参考我们的 `QAOA 教程 <https://github.com/PaddlePaddle/Quantum/blob/master/tutorial/QAOA>`__。
.. _header-n51:
交流与反馈
----------
- 我们非常欢迎您通过 `Github
Issues <https://github.com/PaddlePaddle/Quantum/issues>`__
来提交问题、报告与建议。
- 技术交流QQ群:1076223166
.. _header-n118:
Copyright and License
---------------------
Paddle Quantum 使用 `Apache-2.0 license <https://github.com/PaddlePaddle/Quantum/blob/master/LICENSE>`__ 许可证。
paddle_quantum
==============
.. toctree::
:maxdepth: 4
paddle_quantum
paddle\_quantum.circuit module
==============================
.. automodule:: paddle_quantum.circuit
:members:
:undoc-members:
:show-inheritance:
paddle\_quantum package
=======================
.. automodule:: paddle_quantum
:members:
:undoc-members:
:show-inheritance:
Submodules
----------
.. toctree::
:maxdepth: 4
paddle_quantum.circuit
paddle_quantum.state
paddle_quantum.utils
paddle\_quantum.state module
============================
.. automodule:: paddle_quantum.state
:members:
:undoc-members:
:show-inheritance:
paddle\_quantum.utils module
============================
.. automodule:: paddle_quantum.utils
:members:
:undoc-members:
:show-inheritance:
教程与案例
=======================
我们准备了入门教程和入门案例,来帮助用户快速学会如何使用量桨(Paddle Quantum)。
.. _header-n33:
入门教程
--------
我们提供了一份 `Paddle Quantum 入门手册 <https://github.com/PaddlePaddle/Quantum/blob/master/introduction>`__\ 来方便用户快速上手
Paddle Quantum。目前支持 PDF 阅读和运行 Jupyter Notebook
两种方式。内容上,该手册包括以下几个方面:
- Paddle Quantum 的详细安装教程
- 量子计算的基础知识介绍
- Paddle Quantum 的使用介绍
- PaddlePaddle 飞桨优化器使用教程
- 具体的量子机器学习案例—VQE
入门案例
--------
我们提供了涵盖量子优化、量子化学、量子机器学习等多个领域的案例供大家学习。与\ `入门手册 <https://github.com/PaddlePaddle/Quantum/blob/master/introduction>`__\ 类似,每个教程目前支持
PDF 阅读和运行 Jupyter Notebook 两种方式。我们推荐用户下载 Notebook
后,本地运行进行实践。
1. `量子近似优化算法 (QAOA) <https://github.com/PaddlePaddle/Quantum/blob/master/tutorial/QAOA>`__
2. `变分量子特征求解器 (VQE) <https://github.com/PaddlePaddle/Quantum/blob/master/tutorial/VQE>`__
3. `量子神经网络的贫瘠高原效应 (Barren Plateaus) <https://github.com/PaddlePaddle/Quantum/blob/master/tutorial/Barren>`__
4. `量子分类器 (Quantum Classifier) <https://github.com/PaddlePaddle/Quantum/blob/master/tutorial/Q-Classifier>`__
5. `量子变分自编码器 (Quantum Autoencoder) <https://github.com/PaddlePaddle/Quantum/blob/master/tutorial/Q-Autoencoder>`__
6. `量子生成对抗网络 (Quantum GAN) <https://github.com/PaddlePaddle/Quantum/blob/master/tutorial/Q-GAN>`__
7. `子空间搜索 - 量子变分特征求解器 (SSVQE) <https://github.com/PaddlePaddle/Quantum/blob/master/tutorial/SSVQE>`__
8. `变分量子态对角化算法 (VQSD) <https://github.com/PaddlePaddle/Quantum/blob/master/tutorial/VQSD>`__
9. `吉布斯态的制备 (Gibbs State Preparation) <https://github.com/PaddlePaddle/Quantum/blob/master/tutorial/Gibbs>`__
10. `变分量子奇异值分解 (VQSVD) <https://github.com/PaddlePaddle/Quantum/blob/master/tutorial/VQSVD>`__
此外,Paddle Quantum 也支持在 GPU
上进行量子机器学习的训练,具体的方法请参考案例:`在 GPU 上使用 Paddle
Quantum <https://github.com/PaddlePaddle/Quantum/blob/master/tutorial/GPU>`__。
......@@ -4,28 +4,34 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# 在 GPU 上使用 Paddle Quantum\n",
"# 在 GPU 上使用量桨\n",
"\n",
"<em> Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved. </em>"
"\n",
"<em> Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved. </em>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. 简介\n",
"## 简介\n",
"\n",
"> 注意,本篇教程具有时效性。同时不同电脑也会有个体差异性,本篇教程不保证所有电脑可以安装成功。\n",
"\n",
"在深度学习中,大家通常会使用 GPU 来进行神经网络模型的训练,因为与 CPU 相比,GPU在浮点数运算方面有着显著的优势。因此,使用 GPU 来训练神经网络模型逐渐成为共同的选择。在 Paddle Quantum 中,我们的量子态和量子门也采用基于浮点数的复数表示,因此我们的模型如果能部署到 GPU 上进行训练,也会显著提升训练速度。\n",
"\n",
"## 2. GPU 选择\n",
"在深度学习中,大家通常会使用 GPU 来进行神经网络模型的训练,因为与 CPU 相比,GPU在浮点数运算方面有着显著的优势。因此,使用 GPU 来训练神经网络模型逐渐成为共同的选择。在 Paddle Quantum 中,我们的量子态和量子门也采用基于浮点数的复数表示,因此我们的模型如果能部署到 GPU 上进行训练,也会显著提升训练速度。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## GPU 选择\n",
"\n",
"在这里,我们使用 Nvidia 的硬件设备,其 CUDA(Compute Unified Device Architecture) 对深度学习的框架支持比较好。我们的 PaddlePaddle 也可以比较方便地安装在 CUDA 上。\n",
"在这里,我们选择 Nvidia 的硬件设备,其 CUDA(Compute Unified Device Architecture)对深度学习的框架支持比较好,PaddlePaddle 也可以比较方便地安装在 CUDA 上。\n",
"\n",
"## 3. 配置 CUDA 环境\n",
"## 配置 CUDA 环境\n",
"\n",
"### 3.1 安装 CUDA\n",
"### 安装 CUDA\n",
"\n",
"这里,我们介绍如何在 x64 平台上的 Windows10 系统中配置 CUDA 环境。首先,在[CUDA GPUs | NVIDIA Developer](https://developer.nvidia.com/cuda-gpus)上查看你的GPU是否可以安装CUDA环境。然后,在[NVIDIA 驱动程序下载](https://www.nvidia.cn/Download/index.aspx?lang=cn)下载你的显卡的最新版驱动,并安装到电脑上。\n",
"\n",
......@@ -35,39 +41,38 @@
"\n",
"安装完成之后,打开 Windows 命令行,输入`nvcc -V`,如果看到版本信息,则说明 CUDA 安装成功。\n",
"\n",
"### 3.2 安装 cuDNN\n",
"### 安装 cuDNN\n",
"\n",
"在[NVIDIA cuDNN | NVIDIA Developer](https://developer.nvidia.com/cudnn)下载 cuDNN,根据[飞桨的安装步骤](https://www.paddlepaddle.org.cn/install/quick)中的要求,我们**需要使用 cuDNN 7.6+** ,因此我们下载支持 CUDA 10.0 的最新版 cuDNN 即可。下载完成 cuDNN 后进行解压缩。然后,假设我们的 CUDA 的安装路径为`C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0`,我们将 cuDNN 解压缩后里面的`bin`、`include`和`lib`中的文件都替换 CUDA 的安装路径下的对应文件(如果文件已存在则进行替换,如果未存在则直接粘贴到对应目录中)。到这里,cuDNN 也就安装完成了。\n",
"\n",
"\n",
"### 3.3 配置环境变量\n",
"### 配置环境变量\n",
"\n",
"接下来还需要配置环境变量。右键电脑桌面上的“此电脑”(或“文件资源管理器”左栏的“此电脑”),选择“属性”,然后选择左侧的“高级系统设置”,在“高级”这一栏下选择“环境变量”。\n",
"\n",
"现在就进入到了环境变量的设置页面,在系统变量中选择`Path`,点击“编辑”。在出现的页面中,查看是否有`C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\bin`和`C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\libnvvp`这两个地址(其前缀`C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0`应该为你的 CUDA 的安装位置),如果没有,请手动添加。\n",
"\n",
"### 3.4 验证是否安装成功\n",
"### 验证是否安装成功\n",
"\n",
"打开命令行,输入`cd C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\extras\\demo_suite`进入到 CUDA 安装路径(这里也应该为你的 CUDA 的安装位置)。然后分别执行`.\\bandwidthTest.exe`和`.\\deviceQuery.exe`,如果都出现`Result = PASS`,则说明安装成功。\n",
"\n",
"\n",
"## 4. 在 CUDA 环境上安装 PaddlePaddle\n",
"\n",
"根据[飞桨的安装步骤](https://www.paddlepaddle.org.cn/install/quick)中的说明,我们首先需要确定自己的python环境,用`python --version`来查看 python 版本,保证**python版本是3.5.1+/3.6+/3.7+**,并且用`python -m ensurepip`和`python -m pip --version`来查看 pip 版本,**确认是 9.0.1+**。然后,使用`python -m pip install paddlepaddle-gpu==1.8.4.post107 -i https://pypi.tuna.tsinghua.edu.cn/simple`来安装 GPU 版本的 PaddlePaddle。\n",
"\n",
"\n",
"## 5. 安装 Paddle Quantum\n",
"\n",
"下载 Paddle Quantum 的安装包,修改`setup.py`,将其中的`paddlepaddle`改为`paddlepaddle-gpu`,然后按照 Paddle Quantum 的安装要求,执行`pip install -e .`即可。\n",
"\n",
"> 如果你是在一个新的 python 环境中安装了 paddlepaddle-gpu 和 paddle_quantum,请在新 python 环境中安装 jupyter,并在新的 jupyter 下重新打开本教程并运行。"
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. 检测是否安装成功\n",
"## 在 CUDA 环境上安装 PaddlePaddle\n",
"\n",
"根据[飞桨的安装步骤](https://www.paddlepaddle.org.cn/install/quick)中的说明,我们首先需要确定自己的python环境,用`python --version`来查看 python 版本,保证**python版本是3.5.1+/3.6+/3.7+**,并且用`python -m ensurepip`和`python -m pip --version`来查看 pip 版本,**确认是 9.0.1+**。然后,使用`python -m pip install paddlepaddle-gpu==1.8.4.post107 -i https://pypi.tuna.tsinghua.edu.cn/simple`来安装 GPU 版本的 PaddlePaddle。\n",
"\n",
"## 安装 Paddle Quantum\n",
"\n",
"下载 Paddle Quantum 的安装包,修改`setup.py`,将其中的`paddlepaddle`改为`paddlepaddle-gpu`,然后按照 Paddle Quantum 的安装要求,执行`pip install -e .`即可。\n",
"\n",
"> 如果你是在一个新的 python 环境中安装了 paddlepaddle-gpu 和 paddle_quantum,请在新 python 环境中安装 jupyter,并在新的 jupyter 下重新打开本教程并运行。\n",
"\n",
"## 检测是否安装成功\n",
"\n",
"打开我们 GPU 版本的 PaddlePaddle 环境,执行下面的命令,若输出为`True`则表示当前 PaddlePaddle 框架可以在GPU上运行。"
]
......@@ -76,7 +81,15 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"import paddle \n",
"from paddle import fluid\n",
......@@ -87,37 +100,53 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 7. 使用教程和示例\n",
"\n",
"在 Paddle Quantum 中,我们使用动态图机制来定义和训练我们的参数化量子线路。在这里,我们依然使用动态图机制,只需要定义动态图机制的运行设备即可。方式如下:\n",
"## 使用教程和示例\n",
"\n",
"在 Paddle Quantum 中,我们使用动态图机制来定义和训练我们的参数化量子线路。在这里,我们依然使用动态图机制,只需要定义动态图机制的运行设备即可。方式如下:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```python\n",
"# 0 表示使用编号为0的GPU\n",
"place = fluid.CUDAPlace(0)\n",
"with fluid.dygraph.guard(place):\n",
" # build and train your quantum circuit model\n",
"```\n",
"\n",
"当我们想在 CPU 上运行时,也采用类似的方式,定义运行设备为CPU:\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"当我们想在 CPU 上运行时,也采用类似的方式,定义运行设备为CPU:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```python\n",
"place = fluid.CPUPlace()\n",
"with fluid.dygraph.guard(place):\n",
" # build and train your quantum circuit model\n",
"```\n",
"\n",
"我们可以在命令行中输入`nvidia-smi`来查看 GPU 的使用情况,包括有哪些程序在哪些 GPU 上运行,以及其显存占用情况。"
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"我们可以在命令行中输入`nvidia-smi`来查看 GPU 的使用情况,包括有哪些程序在哪些 GPU 上运行,以及其显存占用情况。\n",
"\n",
"这里,我们以 [VQE](https://github.com/PaddlePaddle/Quantum/blob/master/tutorial/VQE) 为例来说明我们该如何使用 GPU。首先,导入相关的包并定义相关的变量和函数。"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
......@@ -128,6 +157,7 @@
"from paddle import fluid\n",
"from paddle.complex import matmul, transpose\n",
"from paddle_quantum.circuit import UAnsatz\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy\n",
"from paddle_quantum.VQE.chemistrysub import H2_generator\n",
......@@ -154,7 +184,7 @@
" # 量子神经网络作用在默认的初始态 |0000>上\n",
" cir.run_state_vector()\n",
"\n",
" # 计算给定哈密顿量的期望值\n",
" # 计算给定 Hamilton 量的期望值\n",
" expectation_val = cir.expecval(Hamiltonian)\n",
"\n",
" return expectation_val\n",
......@@ -165,11 +195,13 @@
" Construct the model net\n",
" \"\"\"\n",
"\n",
" def __init__(self, shape, param_attr=fluid.initializer.Uniform(low=0.0, high=2 * PI), dtype=\"float64\"):\n",
" def __init__(self, shape, param_attr=fluid.initializer.Uniform(\n",
" low=0.0, high=2 * PI), dtype=\"float64\"):\n",
" super(StateNet, self).__init__()\n",
"\n",
" # 初始化 theta 参数列表,并用 [0, 2*pi] 的均匀分布来填充初始值\n",
" self.theta = self.create_parameter(shape=shape, attr=param_attr, dtype=dtype, is_bias=False)\n",
" self.theta = self.create_parameter(\n",
" shape=shape, attr=param_attr, dtype=dtype, is_bias=False)\n",
"\n",
" # 定义损失函数和前向传播机制\n",
" def forward(self, Hamiltonian, N, D):\n",
......@@ -192,18 +224,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"iter: 20 loss: -1.0599\n",
"iter: 20 Ground state energy: -1.0599 Ha\n",
"iter: 40 loss: -1.1229\n",
"iter: 40 Ground state energy: -1.1229 Ha\n",
"iter: 60 loss: -1.1347\n",
"iter: 60 Ground state energy: -1.1347 Ha\n",
"iter: 80 loss: -1.1359\n",
"iter: 80 Ground state energy: -1.1359 Ha\n"
]
}
],
"source": [
"# 0 表示使用编号为0的GPU\n",
"place_gpu = fluid.CUDAPlace(0)\n",
"with fluid.dygraph.guard(palce_gpu):\n",
"with fluid.dygraph.guard(place_gpu):\n",
" \n",
" # 确定网络的参数维度\n",
" net = StateNet(shape=[D + 1, N, 1])\n",
"\n",
" # 一般来说,我们利用Adam优化器来获得相对好的收敛,当然你可以改成SGD或者是RMS prop.\n",
" opt = fluid.optimizer.AdamOptimizer(learning_rate=LR, parameter_list=net.parameters())\n",
" # 一般来说,我们利用Adam优化器来获得相对好的收敛\n",
" # 当然你可以改成SGD或者是RMS prop.\n",
" opt = fluid.optimizer.AdamOptimizer(\n",
" learning_rate=LR, parameter_list=net.parameters())\n",
"\n",
" # 记录优化结果\n",
" summary_iter, summary_loss = [], []\n",
......@@ -226,11 +276,9 @@
" # 打印结果\n",
" if itr % 20 == 0:\n",
" print(\"iter:\", itr, \"loss:\", \"%.4f\" % loss.numpy())\n",
" print(\"iter:\", itr, \"Ground state energy:\", \"%.4f Ha\" % loss.numpy())\n",
"\n",
" # 储存训练结果到 output 文件夹\n",
" os.makedirs(\"output\", exist_ok=True)\n",
" savez(\"./output/summary_data\", iter=summary_iter, energy=summary_loss)"
" print(\"iter:\", itr, \"Ground state energy:\", \n",
" \"%.4f Ha\" % loss.numpy())\n",
"\n"
]
},
{
......@@ -249,14 +297,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
"iter: 20 loss: -1.0669\n",
"iter: 20 Ground state energy: -1.0669 Ha\n",
"iter: 40 loss: -1.1129\n",
"iter: 40 Ground state energy: -1.1129 Ha\n",
"iter: 60 loss: -1.1163\n",
"iter: 60 Ground state energy: -1.1163 Ha\n",
"iter: 80 loss: -1.1172\n",
"iter: 80 Ground state energy: -1.1172 Ha\n"
"iter: 20 loss: -1.0865\n",
"iter: 20 Ground state energy: -1.0865 Ha\n",
"iter: 40 loss: -1.1153\n",
"iter: 40 Ground state energy: -1.1153 Ha\n",
"iter: 60 loss: -1.1338\n",
"iter: 60 Ground state energy: -1.1338 Ha\n",
"iter: 80 loss: -1.1359\n",
"iter: 80 Ground state energy: -1.1359 Ha\n"
]
}
],
......@@ -264,11 +312,14 @@
"# 表示使用 CPU\n",
"place_cpu = fluid.CPUPlace()\n",
"with fluid.dygraph.guard(place_cpu):\n",
" \n",
" # 确定网络的参数维度\n",
" net = StateNet(shape=[D + 1, N, 1])\n",
"\n",
" # 一般来说,我们利用Adam优化器来获得相对好的收敛,当然你可以改成SGD或者是RMS prop.\n",
" opt = fluid.optimizer.AdamOptimizer(learning_rate=LR, parameter_list=net.parameters())\n",
" # 一般来说,我们利用Adam优化器来获得相对好的收敛\n",
" # 当然你可以改成SGD或者是RMS prop.\n",
" opt = fluid.optimizer.AdamOptimizer(\n",
" learning_rate=LR, parameter_list=net.parameters())\n",
"\n",
" # 记录优化结果\n",
" summary_iter, summary_loss = [], []\n",
......@@ -291,26 +342,20 @@
" # 打印结果\n",
" if itr % 20 == 0:\n",
" print(\"iter:\", itr, \"loss:\", \"%.4f\" % loss.numpy())\n",
" print(\"iter:\", itr, \"Ground state energy:\", \"%.4f Ha\" % loss.numpy())\n",
"\n",
" # 储存训练结果到 output 文件夹\n",
" # os.makedirs(\"output\", exist_ok=True)\n",
" # savez(\"./output/summary_data\", iter=summary_iter, energy=summary_loss)"
" print(\"iter:\", itr, \"Ground state energy:\", \n",
" \"%.4f Ha\" % loss.numpy())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 8. 总结\n",
"## 总结\n",
"\n",
"按照我们的测试,现在版本的 paddle_quantum 可以在 GPU 下运行,但是需要比较好的 GPU 资源才能体现出足够的加速效果。在未来的版本中,我们也会不断优化 paddle_quantum 在 GPU 下的性能表现,敬请期待。\n",
"\n",
"_______\n",
"\n",
"实践证明,我们现在的 paddle_quantum 可以在 GPU 下运行,目前需要比较好的 GPU 资源才能体现出 GPU 的加速效果。在未来的版本中,我们也会不断优化 paddle_quantum 在 GPU 下的性能表现。"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 参考资料\n",
"\n",
"[1] [Installation Guide Windows :: CUDA Toolkit Documentation](https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html)\n",
......@@ -337,7 +382,20 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
"version": "3.7.9"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
......
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Use Paddle Quantum on GPU\n",
"\n",
"<em> Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved. </em>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Introduction\n",
"\n",
"> Note that this tutorial is time-sensitive. And different computers will have individual differences. This tutorial does not guarantee that all computers can install it successfully.\n",
"\n",
"In deep learning, people usually use GPU for neural network model training because GPU has significant advantages in floating-point operations compared with CPU. Therefore, using GPU to train neural network models has gradually become a common choice. In Paddle Quantum, our quantum states and quantum gates are also represented by complex numbers based on floating-point numbers. If our model can be deployed on GPU for training, it will also significantly increase the training speed.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## GPU selection\n",
"\n",
"Here, we choose Nvidia's hardware devices, and its CUDA (Compute Unified Device Architecture) supports deep learning framework better. PaddlePaddle can also be easily installed on CUDA.\n",
"\n",
"## Configure CUDA environment\n",
"\n",
"### Install CUDA\n",
"\n",
"Here, we introduce how to configure the CUDA environment in Windows 10 on the x64 platform. First, check on [CUDA GPUs | NVIDIA Developer](https://developer.nvidia.com/cuda-gpus) to see if your GPU support the CUDA environment. Then, download the latest version of your graphics card driver from [NVIDIA Driver Download](https://www.nvidia.cn/Download/index.aspx?lang=cn) and install it on your computer.\n",
"\n",
"In [PaddlePaddle Installation Steps](https://www.paddlepaddle.org.cn/install/quick), we found that **Paddle Paddle only supports CUDA 9.0/10.0 single card mode under Windows; it does not support CUDA 9.1/9.2/10.1**, so we need to install CUDA10.0 (CUDA 9.0 is also possible in theory). Find the download link of CUDA 10.0 in [CUDA Toolkit Archive | NVIDIA Developer](https://developer.nvidia.com/cuda-toolkit-archive): [CUDA Toolkit 10.0 Archive | NVIDIA Developer](https://developer.nvidia.com/cuda-10.0-download-archive). After downloading CUDA, run the installation.\n",
"\n",
"During the installation process, select **Custom Installation** in the CUDA options, check all the boxes except for Visual Studio Integration (unless you are familiar with it). Then check CUDA option only. Then select the default location for the installation location (please pay attention to the installation location of your CUDA, you need to set environment variables later), and wait for the installation to complete.\n",
"\n",
"After the installation is complete, open the Windows command line and enter `nvcc -V`. If you see the version information, the CUDA installation is successful.\n",
"\n",
"### Install cuDNN\n",
"\n",
"Download cuDNN in [NVIDIA cuDNN | NVIDIA Developer](https://developer.nvidia.com/cudnn), according to [PaddlePaddle Installation Steps](https://www.paddlepaddle.org.cn/install/quick) requirements, we **need to use cuDNN 7.6+**, so we can download the latest version of cuDNN that supports CUDA 10.0. After downloading cuDNN, unzip it. Assuming the installation path of our CUDA is `C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0`. After decompressing cuDNN, we take the files in `bin`, `include` and `lib` and replace the corresponding original files in the CUDA installation path (if the file already exists, replace it, if it does not exist, paste it directly into the corresponding directory). At this point, cuDNN has been installed.\n",
"\n",
"### Configure environment variables\n",
"\n",
"Next, you need to configure environment variables. Right-click \"This PC\" on the desktop of the computer (or \"This PC\" in the left column of \"File Explorer\"), select \"Properties\", and then select \"Advanced System Settings\" on the left, under the \"Advanced\" column Select \"Environmental Variables\".\n",
"\n",
"Now you enter the setting page of environment variables, select `Path` in the `System variables`, and click `Edit`. In the page that appears, check if there are two addresses `C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\bin` and `C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\libnvvp` (the prefix `C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0` should be your CUDA installation location), if not, please add them manually.\n",
"\n",
"### Verify that the installation is successful\n",
"\n",
"Open the command line and enter `cd C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\extras\\demo_suite` to enter the CUDA installation path (this should also be your CUDA installation location). Then execute `.\\bandwidthTest.exe` and `.\\deviceQuery.exe` respectively. If both `Result = PASS` appear, the installation is successful.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Install PaddlePaddle on CUDA environment\n",
"\n",
"According to the instructions in [PaddlePaddle Installation Steps](https://www.paddlepaddle.org.cn/install/quick), we first need to make sure our python environment is correct and use `python --version` to check the python version. Ensure that the **python version is 3.5.1+/3.6+/3.7+**, and use `python -m ensurepip` and `python -m pip --version` to check the pip version, **confirm it is 9.0.1+**. Then, use `python -m pip install paddlepaddle-gpu==1.8.4.post107 -i https://pypi.tuna.tsinghua.edu.cn/simple` to install the GPU version of PaddlePaddle.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Install Paddle Quantum\n",
"\n",
"Download the Paddle Quantum installation package, modify `setup.py`, change paddlepaddle` to `paddlepaddle-gpu`, and then execute `pip install -e .` according to the installation requirements of Paddle Quantum.\n",
"\n",
"> If you have installed paddlepaddle-gpu and paddle_quantum in a new python environment, please also install jupyter in the new python environment, and reopen this tutorial under the new jupyter notebook and run it."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Check if the installation is successful\n",
"\n",
"Open the new environment where we installed the GPU version of PaddlePaddle and execute the following command. If the output is `True`, it means that the current PaddlePaddle framework can run on the GPU.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"import paddle \n",
"from paddle import fluid\n",
"print(fluid.is_compiled_with_cuda())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Use tutorials and examples\n",
"\n",
"In Paddle Quantum, we use the dynamic graph mode to define and train our parameterized quantum circuits. Here, we still use the dynamic graph mode and only need to define the GPU core where we run the dynamic graph mode."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```python\n",
"# 0 means to use GPU number 0\n",
"place = fluid.CUDAPlace(0)\n",
"with fluid.dygraph.guard(place):\n",
" # build and train your quantum circuit model\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we want to run on CPU, pretty much the same, define the running device as CPU:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```python\n",
"place = fluid.CPUPlace()\n",
"with fluid.dygraph.guard(place):\n",
" # build and train your quantum circuit model\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can enter `nvidia-smi` in the command line to view the usage of the GPU, including which programs are running on which GPUs, and its memory usage.\n",
"\n",
"Here, we take [VQE](https://github.com/PaddlePaddle/Quantum/blob/master/tutorial/VQE) as an example to illustrate how we should use GPU. First, import the related packages and define some variables and functions."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from numpy import concatenate\n",
"from numpy import pi as PI\n",
"from numpy import savez, zeros\n",
"from paddle import fluid\n",
"from paddle.complex import matmul, transpose\n",
"from paddle_quantum.circuit import UAnsatz\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy\n",
"from paddle_quantum.VQE.chemistrysub import H2_generator\n",
"from time import time\n",
"\n",
"Hamiltonian, N = H2_generator()\n",
"\n",
"\n",
"def U_theta(theta, Hamiltonian, N, D):\n",
" \"\"\"\n",
" Quantum Neural Network\n",
" \"\"\"\n",
" \n",
" # Initialize the quantum neural network according to the number of qubits/network width\n",
" cir = UAnsatz(N)\n",
" \n",
" # Built-in {R_y + CNOT} circuit template\n",
" cir.real_entangled_layer(theta[:D], D)\n",
"\n",
" # Add in the last row a layer of R_y rotation gates\n",
" for i in range(N):\n",
" cir.ry(theta=theta[D][i][0], which_qubit=i)\n",
"\n",
" # The quantum neural network acts on the default initial state |0000>\n",
" cir.run_state_vector()\n",
"\n",
" # Calculate the expected value of a given Hamiltonian\n",
" expectation_val = cir.expecval(Hamiltonian)\n",
"\n",
" return expectation_val\n",
"\n",
"\n",
"class StateNet(fluid.dygraph.Layer):\n",
" \"\"\"\n",
" Construct the model net\n",
" \"\"\"\n",
"\n",
" def __init__(self, shape, param_attr=fluid.initializer.Uniform(\n",
" low=0.0, high=2 * PI), dtype=\"float64\"):\n",
" super(StateNet, self).__init__()\n",
"\n",
" # Initialize the theta parameter list and fill the initial value with the uniform distribution of [0, 2*pi]\n",
" self.theta = self.create_parameter(\n",
" shape=shape, attr=param_attr, dtype=dtype, is_bias=False)\n",
"\n",
" # Define loss function and forward propagation mechanism\n",
" def forward(self, Hamiltonian, N, D):\n",
" # Calculate loss function/expected value\n",
" loss = U_theta(self.theta, Hamiltonian, N, D)\n",
"\n",
" return loss\n",
"\n",
"ITR = 80 # Set the total number of training iterations\n",
"LR = 0.2 # Set the learning rate\n",
"D = 2 # Set the depth of the repeated calculation module in the neural network"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you want to use GPU to train, run the following program:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"iter: 20 loss: -0.8634\n",
"iter: 20 Ground state energy: -0.8634 Ha\n",
"iter: 40 loss: -1.1203\n",
"iter: 40 Ground state energy: -1.1203 Ha\n",
"iter: 60 loss: -1.1350\n",
"iter: 60 Ground state energy: -1.1350 Ha\n",
"iter: 80 loss: -1.1359\n",
"iter: 80 Ground state energy: -1.1359 Ha\n"
]
}
],
"source": [
"# 0 means to use GPU number 0\n",
"place_gpu = fluid.CUDAPlace(0)\n",
"with fluid.dygraph.guard(place_gpu):\n",
" \n",
" # Determine the parameter dimension of the network\n",
" net = StateNet(shape=[D + 1, N, 1])\n",
"\n",
" # Generally speaking, we use Adam optimizer to get relatively good convergence\n",
" # Of course, you can change to SGD or RMS prop.\n",
" opt = fluid.optimizer.AdamOptimizer(\n",
" learning_rate=LR, parameter_list=net.parameters())\n",
"\n",
" # Record optimization results\n",
" summary_iter, summary_loss = [], []\n",
"\n",
" # Optimization cycle\n",
" for itr in range(1, ITR + 1):\n",
"\n",
" # Forward propagation to calculate loss function\n",
" loss = net(Hamiltonian, N, D)\n",
"\n",
" # Under the dynamic graph mechanism, back propagation minimizes the loss function\n",
" loss.backward()\n",
" opt.minimize(loss)\n",
" net.clear_gradients()\n",
"\n",
" # Update optimization results\n",
" summary_loss.append(loss.numpy())\n",
" summary_iter.append(itr)\n",
"\n",
" # Print results\n",
" if itr% 20 == 0:\n",
" print(\"iter:\", itr, \"loss:\", \"%.4f\"% loss.numpy())\n",
" print(\"iter:\", itr, \"Ground state energy:\",\n",
" \"%.4f Ha\"% loss.numpy())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you want to use CPU to train, run the following program:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"iter: 20 loss: -0.7789\n",
"iter: 20 Ground state energy: -0.7789 Ha\n",
"iter: 40 loss: -1.0741\n",
"iter: 40 Ground state energy: -1.0741 Ha\n",
"iter: 60 loss: -1.1271\n",
"iter: 60 Ground state energy: -1.1271 Ha\n",
"iter: 80 loss: -1.1351\n",
"iter: 80 Ground state energy: -1.1351 Ha\n"
]
}
],
"source": [
"# Use CPU\n",
"place_cpu = fluid.CPUPlace()\n",
"with fluid.dygraph.guard(place_cpu):\n",
" \n",
" # Determine the parameter dimension of the network\n",
" net = StateNet(shape=[D + 1, N, 1])\n",
"\n",
" # Generally speaking, we use Adam optimizer to get relatively good convergence\n",
" # Of course you can change to SGD or RMS prop.\n",
" opt = fluid.optimizer.AdamOptimizer(\n",
" learning_rate=LR, parameter_list=net.parameters())\n",
"\n",
" # Record optimization results\n",
" summary_iter, summary_loss = [], []\n",
"\n",
" # Optimization cycle\n",
" for itr in range(1, ITR + 1):\n",
"\n",
" # Forward propagation to calculate loss function\n",
" loss = net(Hamiltonian, N, D)\n",
"\n",
" # Under the dynamic graph mechanism, back propagation minimizes the loss function\n",
" loss.backward()\n",
" opt.minimize(loss)\n",
" net.clear_gradients()\n",
"\n",
" # Update optimization results\n",
" summary_loss.append(loss.numpy())\n",
" summary_iter.append(itr)\n",
"\n",
" # Print results\n",
" if itr% 20 == 0:\n",
" print(\"iter:\", itr, \"loss:\", \"%.4f\"% loss.numpy())\n",
" print(\"iter:\", itr, \"Ground state energy:\",\n",
" \"%.4f Ha\"% loss.numpy())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Summary\n",
"\n",
"According to our test, the current version of paddle_quantum can run under GPU, but it needs better GPU resources to show sufficient acceleration. In future versions, we will continue to optimize the performance of Paddle Quantum under GPU. \n",
"\n",
"_______\n",
"\n",
"## Reference\n",
"\n",
"[1] [Installation Guide Windows :: CUDA Toolkit Documentation](https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html)\n",
"\n",
"[2] [Installation Guide :: NVIDIA Deep Learning cuDNN Documentation](https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html#installwindows)\n",
"\n",
"[3] [Getting Started PaddlePaddle](https://www.paddlepaddle.org.cn/install/quick)\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 4
}
此差异已折叠。
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -28,18 +28,18 @@ def H_generator():
Generate a Hamiltonian with trivial descriptions
Returns: A Hamiltonian
"""
# 生成用泡利字符串表示的特定的哈密顿量
# Generate Pauli string representing a specific Hamiltonian
H = [[-1.0, 'z0,z1'], [-1.0, 'z1,z2'], [-1.0, 'z0,z2']]
# 生成哈密顿量的矩阵信息
N_SYS_B = 3 # 用于生成吉布斯态的子系统B的量子比特数
# Generate the marix form of the Hamiltonian
N_SYS_B = 3 # Number of qubits in subsystem B used to generate Gibbs state
hamiltonian = pauli_str_to_matrix(H, N_SYS_B)
# 生成理想情况下的目标吉布斯态 rho
beta = 1.5 # 设置逆温度参数 beta
# Generate the target Gibbs state rho
beta = 1.5 # Set inverse temperature beta
rho_G = scipy.linalg.expm(-1 * beta * hamiltonian) / np_trace(scipy.linalg.expm(-1 * beta * hamiltonian))
# 设置成 Paddle quantum 所支持的数据类型
# Convert to the data type supported by Paddle Quantum
hamiltonian = hamiltonian.astype("complex128")
rho_G = rho_G.astype("complex128")
return hamiltonian, rho_G
\ No newline at end of file
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -27,7 +27,7 @@ from paddle_quantum.state import density_op
from paddle_quantum.utils import state_fidelity, partial_trace
from paddle_quantum.GIBBS.HGenerator import H_generator
SEED = 14 # 固定随机种子
SEED = 14 # Choose the seed for random generator
__all__ = [
"U_theta",
......@@ -41,17 +41,17 @@ def U_theta(initial_state, theta, N, D):
Quantum Neural Network
"""
# 按照量子比特数量/网络宽度初始化量子神经网络
# Initialize the quantum neural network by the number of qubits (width of the network)
cir = UAnsatz(N)
# 内置的 {R_y + CNOT} 电路模板
# Use in-built template (R_y + CNOT)
cir.real_entangled_layer(theta[:D], D)
# 铺上最后一列 R_y 旋转门
# Add a layer of R_y rotation gate
for i in range(N):
cir.ry(theta=theta[D][i][0], which_qubit=i)
# 量子神经网络作用在给定的初始态上
# Act quantum neural network on initilized state
final_state = cir.run_density_matrix(initial_state)
return final_state
......@@ -65,28 +65,26 @@ class Net(fluid.dygraph.Layer):
def __init__(self, N, shape, param_attr=fluid.initializer.Uniform(low=0.0, high=2 * PI, seed=SEED),
dtype='float64'):
super(Net, self).__init__()
# 初始化 theta 参数列表,并用 [0, 2*pi] 的均匀分布来填充初始值
# Initialize theta by sampling from a uniform distribution [0, 2*pi]
self.theta = self.create_parameter(shape=shape, attr=param_attr, dtype=dtype, is_bias=False)
# 初始化 rho = |0..0><0..0| 的密度矩阵
# Set the initial state as rho = |0..0><0..0|
self.initial_state = fluid.dygraph.to_variable(density_op(N))
# 定义损失函数和前向传播机制
# Define the loss function and forward propagation mechanism
def forward(self, H, N, N_SYS_B, beta, D):
# 施加量子神经网络
# Apply quantum neural network onto the initial state
rho_AB = U_theta(self.initial_state, self.theta, N, D)
# 计算偏迹 partial trace 来获得子系统B所处的量子态 rho_B
# Calculate the partial tarce to get the state rho_B of subsystem B
rho_B = partial_trace(rho_AB, 2 ** (N - N_SYS_B), 2 ** (N_SYS_B), 1)
# 计算三个子损失函数
# Calculate the three components of the loss function
rho_B_squre = matmul(rho_B, rho_B)
loss1 = (trace(matmul(rho_B, H))).real
loss2 = (trace(rho_B_squre)).real * 2 / beta
loss3 = - ((trace(matmul(rho_B_squre, rho_B))).real + 3) / (2 * beta)
# 最终的损失函数
# Get the final loss function
loss = loss1 + loss2 + loss3
return loss, rho_B
......@@ -95,48 +93,46 @@ class Net(fluid.dygraph.Layer):
def Paddle_GIBBS(hamiltonian, rho_G, N=4, N_SYS_B=3, beta=1.5, D=1, ITR=50, LR=0.5):
r"""
Paddle_GIBBS
:param hamiltonian: 哈密顿量
:param rho_G: 目标吉布斯态 rho
:param N: 量子神经网络的宽度
:param N_SYS_B: 用于生成吉布斯态的子系统B的量子比特数
:param D: 设置量子神经网络中重复计算模块的深度 Depth
:param ITR: 设置训练的总迭代次数
:param LR: 设置学习速率
:return: todo
:param hamiltonian: Hamiltonian
:param rho_G: Target Gibbs state rho
:param N: Width of QNN
:param N_SYS_B: Number of qubits in subsystem B used to generate Gibbs state
:param D: Depth of QNN
:param ITR: Number of iterations
:param LR: Learning rate
:return: State prepared by optimized QNN
"""
# 初始化paddle动态图机制
# Initialize PaddlePaddle dynamic graph machanism
with fluid.dygraph.guard():
# 我们需要将 Numpy array 转换成 Paddle 动态图模式中支持的 variable
# We need to convert Numpy array to variable supported in PaddlePaddle
H = fluid.dygraph.to_variable(hamiltonian)
# 确定网络的参数维度
# Fix the dimensions of network
net = Net(N, shape=[D + 1, N, 1])
# 一般来说,我们利用Adam优化器来获得相对好的收敛,当然你可以改成SGD或者是RMS prop.
# Usually, we recommend Adam optimizer for better results. If you wish, you could use SGD or RMS prop.
opt = fluid.optimizer.AdamOptimizer(learning_rate=LR, parameter_list=net.parameters())
# 优化循环
# Optimization iterations
for itr in range(1, ITR + 1):
# 前向传播计算损失函数并返回生成的量子态 rho_B
# Run forward propagation to calculate loss function and obtain state rho_B
loss, rho_B = net(H, N, N_SYS_B, beta, D)
# 在动态图机制下,反向传播极小化损失函数
# In dynamic graph, run backward propogation to minimize loss function
loss.backward()
opt.minimize(loss)
net.clear_gradients()
# 转换成 Numpy array 用以计算量子态的保真度 F(rho_B, rho_G)
# Convert variable to Numpy array to calculate fidelity F(rho_B, rho_G)
rho_B = rho_B.numpy()
fid = state_fidelity(rho_B, rho_G)
# 打印训练结果
# Print results
if itr % 5 == 0:
print('iter:', itr, 'loss:', '%.4f' % loss.numpy(), 'fid:', '%.4f' % fid)
return rho_B
def main():
# gibbs Hamiltonian preparing
# Generate gibbs Hamiltonian
hamiltonian, rho_G = H_generator()
rho_B = Paddle_GIBBS(hamiltonian, rho_G)
print(rho_B)
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -23,18 +23,18 @@ from paddle_quantum.GIBBS.Paddle_GIBBS import Paddle_GIBBS
def main():
# 生成用泡利字符串表示的特定的哈密顿量
# Generate Pauli string representing a specific Hamiltonian
H = [[-1.0, 'z0,z1'], [-1.0, 'z1,z2'], [-1.0, 'z0,z2']]
# 生成哈密顿量的矩阵信息
N_SYS_B = 3 # 用于生成吉布斯态的子系统B的量子比特数
# Generate the marix form of the Hamiltonian
N_SYS_B = 3 # Number of qubits in subsystem B used to generate Gibbs state
hamiltonian = pauli_str_to_matrix(H, N_SYS_B)
# 生成理想情况下的目标吉布斯态 rho
beta = 1.5 # 设置逆温度参数 beta
# Generate the target Gibbs state rho
beta = 1.5 # Set inverse temperature beta
rho_G = scipy.linalg.expm(-1 * beta * hamiltonian) / np_trace(scipy.linalg.expm(-1 * beta * hamiltonian))
# 设置成 Paddle quantum 所支持的数据类型
# Convert to the data type supported by Paddle Quantum
hamiltonian = hamiltonian.astype("complex128")
rho_G = rho_G.astype("complex128")
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -26,10 +26,10 @@ def H_generator(N):
Generate a Hamiltonian with trivial descriptions
Returns: A Hamiltonian
"""
# 生成用泡利字符串表示的随机哈密顿量
# Generate the Pauli string representing a random Hamiltonian
hamiltonian = random_pauli_str_generator(N, terms=10)
print("Random Hamiltonian in Pauli string format = \n", hamiltonian)
# 生成哈密顿量的矩阵信息
# Generate the marix form of the Hamiltonian
H = pauli_str_to_matrix(hamiltonian, N)
return H
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -25,7 +25,7 @@ from paddle_quantum.circuit import UAnsatz
from paddle_quantum.utils import dagger
from paddle_quantum.SSVQE.HGenerator import H_generator
SEED = 14 # 固定随机种子
SEED = 14 # Choose the seed for random generator
__all__ = [
"U_theta",
......@@ -39,13 +39,13 @@ def U_theta(theta, N):
Quantum Neural Network
"""
# 按照量子比特数量/网络宽度初始化量子神经网络
# Initialize the quantum neural network by the number of qubits (width of the network)
cir = UAnsatz(N)
# 调用内置的量子神经网络模板
# Use a built-in QNN template
cir.universal_2_qubit_gate(theta)
# 返回量子神经网络所模拟的酉矩阵 U
# Return the Unitary matrix simulated by QNN
return cir.U
......@@ -58,18 +58,19 @@ class Net(fluid.dygraph.Layer):
dtype='float64'):
super(Net, self).__init__()
# 初始化 theta 参数列表,并用 [0, 2*pi] 的均匀分布来填充初始值
# Initialize theta by sampling from a uniform distribution [0, 2*pi]
self.theta = self.create_parameter(shape=shape, attr=param_attr, dtype=dtype, is_bias=False)
# 定义损失函数和前向传播机制
# Define the loss function and forward propagation mechanism
def forward(self, H, N):
# 施加量子神经网络
# Apply QNN onto the initial state
U = U_theta(self.theta, N)
# 计算损失函数
# Calculate loss function
loss_struct = matmul(matmul(dagger(U), H), U).real
# 输入计算基去计算每个子期望值,相当于取 U^dagger*H*U 的对角元
# Use computational basis to calculate each expectation value, which is the same
# as a diagonal element in U^dagger*H*U
loss_components = [
loss_struct[0][0],
loss_struct[1][1],
......@@ -77,7 +78,7 @@ class Net(fluid.dygraph.Layer):
loss_struct[3][3]
]
# 最终加权求和后的损失函数
# Calculate the weighted loss function
loss = 4 * loss_components[0] + 3 * loss_components[1] + 2 * loss_components[2] + 1 * loss_components[3]
return loss, loss_components
......@@ -86,36 +87,37 @@ class Net(fluid.dygraph.Layer):
def Paddle_SSVQE(H, N=2, THETA_SIZE=15, ITR=50, LR=0.3):
r"""
Paddle_SSVQE
:param H: 哈密顿量
:param N: 量子比特数/量子神经网络的宽度
:param THETA_SIZE: 量子神经网络中参数的数量
:param ITR: 设置训练的总迭代次数
:param LR: 设置学习速率
:return: 哈密顿量的前几个最小特征值
:param H: Hamiltonian
:param N: Number of qubits/Width of QNN
:param THETA_SIZE: Number of paramaters in QNN
:param ITR: Number of iterations
:param LR: Learning rate
:return: First several smallest eigenvalues of the Hamiltonian
"""
# 初始化paddle动态图机制
# Initialize PaddlePaddle dynamic graph machanism
with fluid.dygraph.guard():
# 我们需要将 Numpy array 转换成 Paddle 动态图模式中支持的 variable
# We need to convert Numpy array to variable supported in PaddlePaddle
hamiltonian = fluid.dygraph.to_variable(H)
# 确定网络的参数维度
# Fix the dimensions of network
net = Net(shape=[THETA_SIZE])
# 一般来说,我们利用Adam优化器来获得相对好的收敛,当然你可以改成SGD或者是RMS prop.
# Use Adagrad optimizer
opt = fluid.optimizer.AdagradOptimizer(learning_rate=LR, parameter_list=net.parameters())
# 优化循环
# Optimization iterations
for itr in range(1, ITR + 1):
# 前向传播计算损失函数并返回估计的能谱
# Run forward propagation to calculate loss function and obtain energy spectrum
loss, loss_components = net(hamiltonian, N)
# 在动态图机制下,反向传播极小化损失函数
# In dynamic graph, run backward propogation to minimize loss function
loss.backward()
opt.minimize(loss)
net.clear_gradients()
# 打印训练结果
# Print results
if itr % 10 == 0:
print('iter:', itr, 'loss:', '%.4f' % loss.numpy()[0])
return loss_components
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -39,21 +39,20 @@ def U_theta(theta, Hamiltonian, N, D):
"""
Quantum Neural Network
"""
# 按照量子比特数量/网络宽度初始化量子神经网络
# Initialize the quantum neural network by the number of qubits (width of the network)
cir = UAnsatz(N)
# 内置的 {R_y + CNOT} 电路模板
# Use built-in template (R_y + CNOT)
cir.real_entangled_layer(theta[:D], D)
# 铺上最后一列 R_y 旋转门
# Add a layer of R_y rotation gates
for i in range(N):
cir.ry(theta=theta[D][i][0], which_qubit=i)
# 量子神经网络作用在默认的初始态 |0000>上
# Act QNN on the default initial state |0000>
cir.run_state_vector()
# 计算给定哈密顿量的期望值
# Calculate the expectation value of the given Hamiltonian
expectation_val = cir.expecval(Hamiltonian)
return expectation_val
......@@ -67,12 +66,12 @@ class StateNet(fluid.dygraph.Layer):
def __init__(self, shape, param_attr=fluid.initializer.Uniform(low=0.0, high=2 * PI), dtype="float64"):
super(StateNet, self).__init__()
# 初始化 theta 参数列表,并用 [0, 2*pi] 的均匀分布来填充初始值
# Initialize theta by sampling from a uniform distribution [0, 2*pi]
self.theta = self.create_parameter(shape=shape, attr=param_attr, dtype=dtype, is_bias=False)
# 定义损失函数和前向传播机制
# Define the loss function and forward propagation mechanism
def forward(self, Hamiltonian, N, D):
# 计算损失函数/期望值
# Calculate loss function (expectation value)
loss = U_theta(self.theta, Hamiltonian, N, D)
return loss
......@@ -81,46 +80,47 @@ class StateNet(fluid.dygraph.Layer):
def Paddle_VQE(Hamiltonian, N, D=2, ITR=80, LR=0.2):
r"""
Main Learning network using dynamic graph
:param Hamiltonian:
:param N:
:param D: 设置量子神经网络中重复计算模块的深度 Depth
:param ITR: 设置训练的总迭代次数
:param LR: 设置学习速率
:return: return: Plot or No return
:param Hamiltonian: Hamiltonian
:param N: Width of QNN
:param D: Depth of QNN
:param ITR: Number of iterations
:param LR: Learning rate
:return: No return
"""
# 初始化paddle动态图机制
# Initialize PaddlePaddle dynamic graph machanism
with fluid.dygraph.guard():
# Determine the dimensions of network
# 确定网络的参数维度
net = StateNet(shape=[D + 1, N, 1])
# 一般来说,我们利用Adam优化器来获得相对好的收敛,当然你可以改成SGD或者是RMS prop.
# Usually, we recommend Adam optimizer for better result. If you wish, you could use SGD or RMS prop.
opt = fluid.optimizer.AdamOptimizer(learning_rate=LR, parameter_list=net.parameters())
# 记录优化结果
# Record optimization results
summary_iter, summary_loss = [], []
# 优化循环
# Optimization iterations
for itr in range(1, ITR + 1):
# 前向传播计算损失函数
# Run forward propagation to calculate loss function
loss = net(Hamiltonian, N, D)
# 在动态图机制下,反向传播极小化损失函数
# In dynamic graph, run backward propogation to minimize loss function
loss.backward()
opt.minimize(loss)
net.clear_gradients()
# 更新优化结果
# Update optimized results
summary_loss.append(loss.numpy())
summary_iter.append(itr)
# 打印结果
# Print results
if itr % 20 == 0:
print("iter:", itr, "loss:", "%.4f" % loss.numpy())
print("iter:", itr, "Ground state energy:", "%.4f Ha" % loss.numpy())
# 储存训练结果到 output 文件夹
# Save results in the 'output' directory
os.makedirs("output", exist_ok=True)
savez("./output/summary_data", iter=summary_iter, energy=summary_loss)
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -31,7 +31,7 @@ __all__ = [
# todo
def Hamiltonian_str_convert(qubit_op):
'''
转换提供的哈密顿量信息成为我们熟悉的泡利字符串
Convert provided Hamiltonian information to Pauli string
'''
info_dic = qubit_op.terms
......@@ -96,7 +96,7 @@ def calc_H_rho_from_qubit_operator(qubit_op, n_qubits):
def read_calc_H(geo_fn, multiplicity=1, charge=0):
"""
Read and calc the H and rho
return: H,rho matrix
Returns: H,rho matrix
"""
if not isinstance(geo_fn, str): # geo_fn = 'h2.xyz'
......@@ -132,7 +132,6 @@ def read_calc_H(geo_fn, multiplicity=1, charge=0):
def main():
"""
The main function
Returns:
"""
filename = 'h2.xyz'
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -26,12 +26,12 @@ __all__ = ["generate_rho_sigma", ]
def generate_rho_sigma():
scipy.random.seed(SEED)
V = scipy.stats.unitary_group.rvs(4) # 随机生成一个酉矩阵
D = diag([0.5, 0.3, 0.1, 0.1]) # 输入目标态 rho 的谱
V = scipy.stats.unitary_group.rvs(4) # Generate a random unitary martrix
D = diag([0.5, 0.3, 0.1, 0.1]) # Input the spectrum of the target state rho
V_H = V.conj().T
rho = V @ D @ V_H # 生成 rho
# print(rho) # 打印量子态 rho
rho = V @ D @ V_H # Generate rho
# print(rho) # Print quantum state rho
# 输入用来标记的量子态sigma
# Input the quantum state sigma
sigma = diag([0.1, 0.2, 0.3, 0.4]).astype('complex128')
return rho, sigma
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -37,14 +37,14 @@ def U_theta(theta, N):
"""
Quantum Neural Network
"""
# 按照量子比特数量/网络宽度初始化量子神经网络
# Initialize the quantum neural network by the number of qubits (width of the network)
cir = UAnsatz(N)
# 调用内置的量子神经网络模板
# Use built-in template
cir.universal_2_qubit_gate(theta)
# 返回量子神经网络所模拟的酉矩阵 U
# Return the Unitary matrix simulated by QNN
return cir.U
......@@ -56,23 +56,22 @@ class Net(fluid.dygraph.Layer):
def __init__(self, shape, rho, sigma, param_attr=fluid.initializer.Uniform(low=0.0, high=2 * numpy.pi, seed=SEED),
dtype='float64'):
super(Net, self).__init__()
# 将 Numpy array 转换成 Paddle 动态图模式中支持的 variable
# Convert Numpy array to variable supported in PaddlePaddle
self.rho = fluid.dygraph.to_variable(rho)
self.sigma = fluid.dygraph.to_variable(sigma)
# 初始化 theta 参数列表,并用 [0, 2*pi] 的均匀分布来填充初始值
# Initialize theta by sampling from a uniform distribution [0, 2*pi]
self.theta = self.create_parameter(shape=shape, attr=param_attr, dtype=dtype, is_bias=False)
# 定义损失函数和前向传播机制
# Define the loss function and forward propagation mechanism
def forward(self, N):
# 施加量子神经网络
# Apply quantum neural network onto the initial state
U = U_theta(self.theta, N)
# rho_tilde 是将 U 作用在 rho 后得到的量子态 U*rho*U^dagger
# rho_tilda is the quantum state obtained by acting U on rho, which is U*rho*U^dagger
rho_tilde = matmul(matmul(U, self.rho), dagger(U))
# 计算损失函数
# Calculate loss function
loss = trace(matmul(self.sigma, rho_tilde))
return loss.real, rho_tilde
......@@ -81,35 +80,35 @@ class Net(fluid.dygraph.Layer):
def Paddle_VQSD(rho, sigma, N=2, THETA_SIZE=15, ITR=50, LR=0.1):
r"""
Paddle_VQSD
:param rho: 待对角化的量子态
:param sigma: 输入用来标记的量子态sigma
:param N: 量子神经网络的宽度
:param THETA_SIZE: 量子神经网络中参数的数量
:param ITR: 设置训练的总的迭代次数
:param LR: 设置学习速率
:return: 优化之后量子态rho接近对角态的numpy形式
:param rho: Qauntum state to be diagonalized
:param sigma: Quantum state sigma
:param N: Width of QNN
:param THETA_SIZE: Number of parameters in QNN
:param ITR: Number of iterations
:param LR: Learning rate
:return: Diagonalized quantum state after optimization
"""
# 初始化paddle动态图机制
# Initialize PaddlePaddle dynamic graph machanism
with fluid.dygraph.guard():
# 确定网络的参数维度
# Fix the dimensions of network
net = Net(shape=[THETA_SIZE], rho=rho, sigma=sigma)
# 一般来说,我们利用Adam优化器来获得相对好的收敛,当然你可以改成SGD或者是RMS prop.
# Use Adagrad optimizer
opt = fluid.optimizer.AdagradOptimizer(learning_rate=LR, parameter_list=net.parameters())
# 优化循环
# Optimization iterations
for itr in range(ITR):
# 前向传播计算损失函数并返回估计的能谱
# Run forward propagation to calculate loss function and obtain energy spectrum
loss, rho_tilde = net(N)
rho_tilde_np = rho_tilde.numpy()
# 在动态图机制下,反向传播极小化损失函数
# In dynamic graph, run backward propogation to minimize loss function
loss.backward()
opt.minimize(loss)
net.clear_gradients()
# 打印训练结果
# Print results
if itr % 10 == 0:
print('iter:', itr, 'loss:', '%.4f' % loss.numpy()[0])
return rho_tilde_np
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -15,3 +15,5 @@
r"""
Paddle Quantum Library
"""
name = "paddle_quantum"
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -20,8 +20,6 @@ import numpy as np
from numpy import binary_repr, eye, identity
import matplotlib.pyplot as plt
from Simulator.main import StateTranfer, init_state_gen, measure_state
import paddle
from paddle.complex import kron as pp_kron
from paddle.complex import reshape as complex_reshape
......@@ -33,6 +31,7 @@ from paddle.fluid import dygraph
from paddle.fluid.layers import reshape, cast, eye, zeros
from paddle.fluid.framework import ComplexVariable
from paddle_quantum.simulator import StateTranfer, init_state_gen, measure_state
from paddle_quantum.utils import dagger, pauli_str_to_matrix
from paddle_quantum.intrinsic import *
from paddle_quantum.state import density_op
......@@ -44,7 +43,7 @@ __all__ = [
class UAnsatz:
r"""基于Paddle的动态图机制实现量子线路的 ``class`` 。
r"""基于PaddlePaddle的动态图机制实现量子线路的 ``class`` 。
用户可以通过实例化该 ``class`` 来搭建自己的量子线路。
......@@ -95,11 +94,11 @@ class UAnsatz:
cir.ry(theta[1], 1)
cir.rz(theta[2], 1)
vec = cir.run_state_vector(input_state_var).numpy()
print(f"运行后的向量是 {vec}")
print(f"The output state vector is {vec}")
::
运行后的向量是 [0.17470783-0.09544332j 0.59544332+0.32529217j 0.17470783-0.09544332j 0.59544332+0.32529217j]
The output state vector is [0.17470783-0.09544332j 0.59544332+0.32529217j 0.17470783-0.09544332j 0.59544332+0.32529217j]
"""
state = init_state_gen(self.n, 0) if input_state is None else input_state
old_shape = state.shape
......@@ -155,11 +154,11 @@ class UAnsatz:
cir.ry(theta[1], 0)
cir.rz(theta[2], 0)
density = cir.run_density_matrix(input_state_var).numpy()
print(f"密度矩阵是\n{density}")
print(f"The output density matrix is\n{density}")
::
密度矩阵是
The output density matrix is
[[ 0.35403671+0.j -0.47686058-0.03603751j]
[-0.47686058+0.03603751j 0.64596329+0.j ]]
"""
......@@ -194,11 +193,11 @@ class UAnsatz:
cir.h(0)
cir.cnot([0, 1])
matrix = cir.U
print("生成贝尔态电路的酉矩阵表示为\n",matrix.numpy())
print("The unitary matrix of the circuit for Bell state preparation is\n",matrix.numpy())
::
生成贝尔态电路的酉矩阵表示为
The unitary matrix of the circuit for Bell state preparation is
[[ 0.70710678+0.j 0. +0.j 0.70710678+0.j 0. +0.j]
[ 0. +0.j 0.70710678+0.j 0. +0.j 0.70710678+0.j]
[ 0. +0.j 0.70710678+0.j 0. +0.j -0.70710678+0.j]
......@@ -234,7 +233,7 @@ class UAnsatz:
Args:
theta (Variable): 旋转角度
which_qubit (int): 作用在的qubit的编号,其值应该在[0, n)范围内,n为该量子线路的量子比特数
which_qubit (int): 作用在的qubit的编号,其值应该在 :math:`[0, n)` 范围内, :math:`n` 为该量子线路的量子比特数
.. code-block:: python
......@@ -265,7 +264,7 @@ class UAnsatz:
Args:
theta (Variable): 旋转角度
which_qubit (int): 作用在的qubit的编号,其值应该在[0, n)范围内,n为该量子线路的量子比特数
which_qubit (int): 作用在的qubit的编号,其值应该在 :math:`[0, n)` 范围内, :math:`n` 为该量子线路的量子比特数
.. code-block:: python
......@@ -286,17 +285,17 @@ class UAnsatz:
dygraph.to_variable(np.array([0.0]))]])
def rz(self, theta, which_qubit):
r"""添加关于y轴的单量子比特旋转门。
r"""添加关于z轴的单量子比特旋转门。
其矩阵形式为:
.. math::
\begin{bmatrix} e^{-\frac{i\theta}{2}} & 0 \\ 0 & e^{\frac{i\theta}{2}} \end{bmatrix}
\begin{bmatrix} 1 & 0 \\ 0 & e^{i\theta} \end{bmatrix}
Args:
theta (Variable): 旋转角度
which_qubit (int): 作用在的qubit的编号,其值应该在[0, n)范围内,n为该量子线路的量子比特数
which_qubit (int): 作用在的qubit的编号,其值应该在 :math:`[0, n)` 范围内, :math:`n` 为该量子线路的量子比特数
.. code-block:: python
......@@ -319,7 +318,7 @@ class UAnsatz:
def cnot(self, control):
r"""添加一个CNOT门。
对于2量子比特的量子线路,当control为 ``[0, 1]`` 时,其矩阵形式为:
对于2量子比特的量子线路,当 ``control`` 为 ``[0, 1]`` 时,其矩阵形式为:
.. math::
......@@ -329,7 +328,7 @@ class UAnsatz:
\end{align}
Args:
control (list): 作用在的qubit的编号,``control[0]`` 为控制位,``control[1]`` 为目标位,其值都应该在 :math:`[0, n)`范围内, :math:`n` 为该量子线路的量子比特数
control (list): 作用在的qubit的编号,``control[0]`` 为控制位,``control[1]`` 为目标位,其值都应该在 :math:`[0, n)` 范围内, :math:`n` 为该量子线路的量子比特数
.. code-block:: python
......@@ -356,7 +355,7 @@ class UAnsatz:
\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}
Args:
which_qubit (int): 作用在的qubit的编号,其值应该在[0, n)范围内,n为该量子线路的量子比特数
which_qubit (int): 作用在的qubit的编号,其值应该在 :math:`[0, n)` 范围内, :math:`n` 为该量子线路的量子比特数
.. code-block:: python
......@@ -381,7 +380,7 @@ class UAnsatz:
\begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}
Args:
which_qubit (int): 作用在的qubit的编号,其值应该在[0, n)范围内,n为该量子线路的量子比特数
which_qubit (int): 作用在的qubit的编号,其值应该在 :math:`[0, n)` 范围内, :math:`n` 为该量子线路的量子比特数
.. code-block:: python
......@@ -406,7 +405,7 @@ class UAnsatz:
\begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}
Args:
which_qubit (int): 作用在的qubit的编号,其值应该在[0, n)范围内,n为该量子线路的量子比特数
which_qubit (int): 作用在的qubit的编号,其值应该在 :math:`[0, n)` 范围内, :math:`n` 为该量子线路的量子比特数
.. code-block:: python
......@@ -424,14 +423,14 @@ class UAnsatz:
def h(self, which_qubit):
r"""添加一个单量子比特的Hadamard门。
具体形式为
其矩阵形式为:
.. math::
H = \frac{1}{\sqrt{2}}\begin{bmatrix} 1&1\\1&-1 \end{bmatrix}
Args:
which_qubit (int): 作用在的qubit的编号,其值应该在[0, n)范围内,n为该量子线路的量子比特数
which_qubit (int): 作用在的qubit的编号,其值应该在 :math:`[0, n)` 范围内, :math:`n` 为该量子线路的量子比特数
"""
assert 0 <= which_qubit < self.n, "the qubit should >= 0 and < n(the number of qubit)"
self.__history.append(['h', [which_qubit], None])
......@@ -439,14 +438,14 @@ class UAnsatz:
def s(self, which_qubit):
r"""添加一个单量子比特的S门。
具体形式为
其矩阵形式为:
.. math::
S = \begin{bmatrix} 1&0\\0&i \end{bmatrix}
Args:
which_qubit (int): 作用在的qubit的编号,其值应该在[0, n)范围内,n为该量子线路的量子比特数
which_qubit (int): 作用在的qubit的编号,其值应该在 :math:`[0, n)` 范围内, :math:`n` 为该量子线路的量子比特数
"""
assert 0 <= which_qubit < self.n, "the qubit should >= 0 and < n(the number of qubit)"
self.__history.append(['u', [which_qubit], [dygraph.to_variable(np.array([0.0])),
......@@ -456,14 +455,14 @@ class UAnsatz:
def t(self, which_qubit):
r"""添加一个单量子比特的T门。
具体形式为
其矩阵形式为:
.. math::
T = \begin{bmatrix} 1&0\\0&e^\frac{i\pi}{4} \end{bmatrix}
Args:
which_qubit (int): 作用在的qubit的编号,其值应该在[0, n)范围内,n为该量子线路的量子比特数
which_qubit (int): 作用在的qubit的编号,其值应该在 :math:`[0, n)` 范围内, :math:`n` 为该量子线路的量子比特数
"""
assert 0 <= which_qubit < self.n, "the qubit should >= 0 and < n(the number of qubit)"
self.__history.append(['u', [which_qubit], [dygraph.to_variable(np.array([0.0])),
......@@ -473,7 +472,7 @@ class UAnsatz:
def u3(self, theta, phi, lam, which_qubit):
r"""添加一个单量子比特的旋转门。
具体形式为
其矩阵形式为:
.. math::
......@@ -489,7 +488,7 @@ class UAnsatz:
theta (Variable): 旋转角度 :math:`\theta` 。
phi (Variable): 旋转角度 :math:`\phi` 。
lam (Variable): 旋转角度 :math:`\lambda` 。
which_qubit (int): 作用在的qubit的编号,其值应该在[0, n)范围内,n为该量子线路的量子比特数
which_qubit (int): 作用在的qubit的编号,其值应该在 :math:`[0, n)` 范围内, :math:`n` 为该量子线路的量子比特数
"""
assert 0 <= which_qubit < self.n, "the qubit should >= 0 and < n(the number of qubit)"
self.__history.append(['u', [which_qubit], [theta, phi, lam]])
......@@ -564,11 +563,11 @@ class UAnsatz:
r"""对量子线路输出的量子态进行测量。
Warning:
plot为True时,当前量子线路的量子比特数需要小于6,否则无法绘制图片,会抛出异常。
``plot`` 为 ``True`` 时,当前量子线路的量子比特数需要小于6,否则无法绘制图片,会抛出异常。
Args:
which_qubits (list, optional): 要测量的qubit的编号,默认全都测量
shots (int, optional): 该量子线路输出的量子态的测量次数,默认为1024次;若为0,则输出测量期望值的精确值
shots (int, optional): 该量子线路输出的量子态的测量次数,默认为1024次;若为0,则返回测量结果的精确概率分布
plot (bool, optional): 是否绘制测量结果图,默认为 ``False`` ,即不绘制
Returns:
......@@ -586,11 +585,11 @@ class UAnsatz:
cir.cnot([0,1])
cir.run_state_vector()
result = cir.measure(shots = 2048, which_qubits = [1])
print(f"测量第1号量子比特2048次的结果是{result}")
print(f"The results of measuring qubit 1 2048 times are {result}")
::
测量第1号量子比特2048次的结果是{'0': 964, '1': 1084}
The results of measuring qubit 1 2048 times are {'0': 964, '1': 1084}
.. code-block:: python
......@@ -602,11 +601,11 @@ class UAnsatz:
cir.cnot([0,1])
cir.run_state_vector()
result = cir.measure(shots = 0, which_qubits = [1])
print(f"测量第1号量子比特的概率结果是{result}")
print(f"The probability distribution of measurement results on qubit 1 is {result}")
::
测量第1号量子比特的概率结果是{'0': 0.4999999999999999, '1': 0.4999999999999999}
The probability distribution of measurement results on qubit 1 is {'0': 0.4999999999999999, '1': 0.4999999999999999}
"""
if self.__run_state == 'state_vector':
state = self.__state
......@@ -672,11 +671,11 @@ class UAnsatz:
cir.rx(theta[2], 2)
cir.run_state_vector(input_state_var)
expect_value = cir.expecval(H_info).numpy()
print(f'计算得到的{H_info}期望值是{expect_value}')
print(f'Calculated expectation value of {H_info} is {expect_value}')
::
计算得到的[[0.1, 'x1'], [0.2, 'y0,z4']]期望值是[0.05403023]
Calculated expectation value of [[0.1, 'x1'], [0.2, 'y0,z4']] is [0.05403023]
.. code-block:: python
......@@ -697,11 +696,11 @@ class UAnsatz:
cir.rz(theta[2], 2)
cir.run_density_matrix(input_state_var)
expect_value = cir.expecval(H_info).numpy()
print(f'计算得到的{H_info}期望值是{expect_value}')
print(f'Calculated expectation value of {H_info} is {expect_value}')
::
计算得到的[[0.1, 'x1'], [0.2, 'y0,z4']]期望值是[-0.02171538]
Calculated expectation value of [[0.1, 'x1'], [0.2, 'y0,z4']] is [-0.02171538]
"""
if self.__run_state == 'state_vector':
return vec_expecval(H, self.__state).real
......@@ -731,17 +730,17 @@ class UAnsatz:
cir.superposition_layer()
cir.run_state_vector()
result = cir.measure(shots = 0)
print(f"测量全部量子比特的结果是{result}")
print(f"The probability distribution of measurement results on both qubits is {result}")
::
测量全部量子比特结果是{'00': 0.2499999999999999, '01': 0.2499999999999999, '10': 0.2499999999999999, '11': 0.2499999999999999}
The probability distribution of measurement results on both qubits is {'00': 0.2499999999999999, '01': 0.2499999999999999, '10': 0.2499999999999999, '11': 0.2499999999999999}
"""
for i in range(self.n):
self.h(i)
def weak_superposition_layer(self):
r"""添加一层Hadamard的平方根门,即 :math:`\sqrt{H}` 门。
r"""添加一层旋转角度为 :math:`\pi/4` 的Ry门。
代码示例:
......@@ -754,18 +753,18 @@ class UAnsatz:
cir.weak_superposition_layer()
cir.run_state_vector()
result = cir.measure(shots = 0)
print(f"测量全部量子比特的结果是{result}")
print(f"The probability distribution of measurement results on both qubits is {result}")
::
测量全部量子比特的结果是{'00': 0.7285533905932737, '01': 0.12500000000000003, '10': 0.12500000000000003, '11': 0.021446609406726238}
The probability distribution of measurement results on both qubits is {'00': 0.7285533905932737, '01': 0.12500000000000003, '10': 0.12500000000000003, '11': 0.021446609406726238}
"""
_theta = fluid.dygraph.to_variable(np.array([np.pi / 4])) # Used in fixed Ry gate
for i in range(self.n):
self.ry(_theta, i)
def real_entangled_layer(self, theta, depth):
r"""添加一层包含Ry门的强纠缠层。
r"""添加 ``depth`` 层包含Ry门和CNOT门的强纠缠层。
Note:
这一层量子门的数学表示形式为实数酉矩阵。
......@@ -812,7 +811,7 @@ class UAnsatz:
self.cnot([self.n - 1, 0])
def complex_entangled_layer(self, theta, depth):
r"""添加一层包含U3门的强纠缠层。
r"""添加 ``depth`` 层包含U3门和CNOT门的强纠缠层。
Note:
这一层量子门的数学表示形式为复数酉矩阵。
......@@ -967,7 +966,7 @@ class UAnsatz:
self.__add_complex_block(theta[int((i - position[0]) / 2)], [i, i + 1])
def real_block_layer(self, theta, depth):
r"""添加一层包含Ry门的弱纠缠层。
r"""添加 ``depth`` 层包含Ry门和CNOT门的弱纠缠层。
Note:
这一层量子门的数学表示形式为实数酉矩阵。
......@@ -1014,7 +1013,7 @@ class UAnsatz:
self.__add_real_layer(theta[i][int((self.n - 1) / 2):], [1, self.n - 1])
def complex_block_layer(self, theta, depth):
r"""添加一层包含U3门的弱纠缠层。
r"""添加 ``depth`` 层包含U3门和CNOT门的弱纠缠层。
Note:
这一层量子门的数学表示形式为复数酉矩阵。
......@@ -1061,7 +1060,7 @@ class UAnsatz:
self.__add_complex_layer(theta[i][int((self.n - 1) / 2):], [1, self.n - 1])
def local_H_prob(cir, hamiltonian, shots=1024):
def __local_H_prob(cir, hamiltonian, shots=1024):
r"""
构造出Pauli测量电路并测量ancilla,处理实验结果来得到 ``H`` (只有一项)期望值的实验测量值。
......@@ -1137,15 +1136,15 @@ def H_prob(cir, H, shots=1024):
cir.rz(theta[2], 1)
result_1 = H_prob(cir, H_info, shots = experiment_shots)
result_2 = H_prob(cir, H_info, shots = 0)
print(f'消耗 {experiment_shots} 次测量后的期望值实验值是 {result_1}')
print(f'H期望值精确值是 {result_2}')
print(f'The expectation value obtained by {experiment_shots} measurements is {result_1}')
print(f'The accurate expectation value of H is {result_2}')
::
消耗 1024 次测量后的期望值实验值是 0.2326171875
H期望值精确值是 0.21242202548207134
The expectation value obtained by 1024 measurements is 0.2326171875
The accurate expectation value of H is 0.21242202548207134
"""
expval = 0
for term in H:
expval += term[0] * local_H_prob(cir, term[1], shots=shots)
expval += term[0] * __local_H_prob(cir, term[1], shots=shots)
return expval
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -57,7 +57,7 @@ def vec(n):
def vec_random(n, real_or_complex=2):
r"""随机生成一个量子态,使用numpy形式。
r"""随机生成一个量子态numpy形式。
Args:
n (int): 量子比特数量
......@@ -152,7 +152,7 @@ def density_op_random(n, real_or_complex=2, rank=None):
Args:
n (int): 量子比特数量
real_or_complex (int, optional): 默认为2,即生成复数组,若为1,则生成实数组
rank (int, optional): 矩阵的秩,默认为 :math:`2^n` (当rank为 ``None`` 时)
rank (int, optional): 矩阵的秩,默认为 :math:`2^n` (当 ``rank`` 为 ``None`` 时)
Returns:
numpy.ndarray: 一个形状为 ``(2**n, 2**n)`` 的numpy数组
......
# Copyright (c) 2020 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
# Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -59,10 +59,10 @@ def partial_trace(rho_AB, dim1, dim2, A_or_B):
rho_AB (ComplexVariable): 输入的量子态
dim1 (int): 系统A的维数
dim2 (int): 系统B的维数
A_or_B (int): 1或者2,1表示去除A,2表示去除B
A_or_B (int): 1或者2,1表示计算系统A上的偏迹,2表示计算系统B上的偏迹
Returns:
ComplexVariable: 量子态的偏迹
ComplexVariable: 输入的量子态的偏迹
"""
if A_or_B == 2:
......@@ -126,8 +126,8 @@ def gate_fidelity(U, V):
:math:`U` 是一个 :math:`2^n\times 2^n` 的 Unitary 矩阵。
Args:
U (numpy.ndarray): 量子门的酉矩阵形式
V (numpy.ndarray): 量子门的酉矩阵形式
U (numpy.ndarray): 量子门 :math:`U` 的酉矩阵形式
V (numpy.ndarray): 量子门 :math:`V` 的酉矩阵形式
Returns:
float: 输入的量子门之间的保真度
......@@ -215,7 +215,7 @@ def NKron(matrix_A, matrix_B, *args):
C = density_op_random(2)
result = NKron(A, B, C)
``result`` 应为 :math:`A \otimes B \otimes C`
``result`` 应为 :math:`A \otimes B \otimes C`
"""
return reduce(lambda result, index: np_kron(result, index), args, np_kron(matrix_A, matrix_B), )
......
......@@ -16,14 +16,30 @@
Install library to site-packages
"""
from setuptools import setup
import setuptools
setup(
name='paddle_quantum',
version='1.1.0',
description='Paddle Quantum circuit and function',
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setuptools.setup(
name='paddle-quantum',
version='1.1.1',
author='Institute for Quantum Computing, Baidu INC.',
author_email='quantum@baidu.com',
url='http://quantum.baidu.com',
packages=['paddle_quantum'],
install_requires=['paddlepaddle==1.8.5', 'networkx>=2.4', 'matplotlib>=3.3.0', 'interval>=1.0.0', 'progressbar>=2.5'])
description='Paddle Quantum is a quantum machine learning (QML) toolkit developed based on Baidu PaddlePaddle.',
long_description=long_description,
long_description_content_type="text/markdown",
url='http://qml.baidu.com',
packages=['paddle_quantum', 'paddle_quantum.GIBBS', 'paddle_quantum.QAOA', 'paddle_quantum.SSVQE', 'paddle_quantum.VQE', 'paddle_quantum.VQSD',
'paddle_quantum.GIBBS.example', 'paddle_quantum.QAOA.example', 'paddle_quantum.SSVQE.example', 'paddle_quantum.VQE.example', 'paddle_quantum.VQSD.example'],
install_requires=['paddlepaddle==1.8.5', 'networkx>=2.4', 'matplotlib>=3.3.0', 'interval>=1.0.0', 'progressbar>=2.5'],
python_requires='>=3.6, <4',
classifiers=[
'Programming Language :: Python :: 3',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
],
project_urls={
'Documentation': 'https://qml.baidu.com/api/introduction.html',
'Source': 'https://github.com/PaddlePaddle/Quantum/',
'Tracker': 'https://github.com/PaddlePaddle/Quantum/issues'},)
......@@ -9,7 +9,7 @@ import subprocess
import platform
COPYRIGHT = '''
Copyright (c) 2020 Paddle Quantum Authors. All Rights Reserved.
Copyright (c) 2021 Paddle Quantum Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册