提交 ae59b7d7 编写于 作者: Q Quleaf

update to v2.1.2

上级 71f45820
......@@ -6,7 +6,7 @@ English | [简体中文](README_CN.md)
- [Install](#install)
- [Install PaddlePaddle](#install-paddlepaddle)
- [Install Paddle Quantum](#install-paddle-quantum)
- [Use OpenFermion to read .xyz molecule configuration file](#use-openfermion-to-read-xyz-molecule-configuration-file)
- [Environment setup for Quantum Chemistry module](#environment_setup_for_quantum_chemistry_module)
- [Run programs](#run-programs)
- [Introduction and developments](#introduction-and-developments)
- [Quick start](#quick-start)
......@@ -33,7 +33,7 @@ English | [简体中文](README_CN.md)
</a>
<!-- PyPI -->
<a href="https://pypi.org/project/paddle-quantum/">
<img src="https://img.shields.io/badge/pypi-v2.1.1-orange.svg?style=flat-square&logo=pypi"/>
<img src="https://img.shields.io/badge/pypi-v2.1.2-orange.svg?style=flat-square&logo=pypi"/>
</a>
<!-- Python -->
<a href="https://www.python.org/">
......@@ -88,18 +88,31 @@ cd quantum
pip install -e .
```
### Environment setup for Quantum Chemistry module
### Use OpenFermion to read .xyz molecule configuration file
Our qchem module is based on `Openfermion` and `Psi4`, so before executing quantum chemistry, we have to install the two Python packages first.
> Only macOS and linux users can use OpenFermion to read .xyz description files.
> It is recommended that these Python packages be installed in a Python 3.8 environment.
Once the user confirms the above OS constraint, OpenFermion can be installed with the following command. These packages are used for quantum chemistry calculations and could be potentially used in the VQE tutorial.
`Openfermion` can be installed with the following command:
```bash
pip install openfermion
pip install openfermionpyscf
```
We highly recommend you to install `Psi4` via conda. **MacOS/Linux** user can use the command:
```bash
conda install psi4-c psi4
```
For **Windows** user, the command is:
```bash
conda install psi4 -c psi4 -c conda-forge
```
**Note:** Please refer to [Psi4](https://psicode.org/installs/v14/) for more download options.
### Run example
Now, you can try to run a program to verify whether Paddle Quantum has been installed successfully. Here we take quantum approximate optimization algorithm (QAOA) as an example.
......@@ -128,10 +141,15 @@ python main.py
We provide tutorials covering quantum simulation, machine learning, combinatorial optimization, local operations and classical communication (LOCC), and other popular QML research topics. Each tutorial currently supports reading on our website and running Jupyter Notebooks locally. For interested developers, we recommend them to download Jupyter Notebooks and play around with it. Here is the tutorial list,
- [Quantum Simulation](./tutorial/quantum_simulation)
1. [Variational Quantum Eigensolver (VQE)](./tutorial/quantum_simulation/VQE_EN.ipynb)
2. [Subspace Search-Quantum Variational Quantum Eigensolver (SSVQE)](./tutorial/quantum_simulation/SSVQE_EN.ipynb)
3. [Variational Quantum State Diagonalization (VQSD)](./tutorial/quantum_simulation/VQSD_EN.ipynb)
4. [Gibbs State Preparation](./tutorial/quantum_simulation/GibbsState_EN.ipynb)
1. [Building Molecular Hamiltonian](./tutorial/quantum_simulation/BuildingMolecule_EN.ipynb)
2. [Variational Quantum Eigensolver (VQE)](./tutorial/quantum_simulation/VQE_EN.ipynb)
3. [Subspace Search-Quantum Variational Quantum Eigensolver (SSVQE)](./tutorial/quantum_simulation/SSVQE_EN.ipynb)
4. [Variational Quantum State Diagonalization (VQSD)](./tutorial/quantum_simulation/VQSD_EN.ipynb)
5. [Gibbs State Preparation](./tutorial/quantum_simulation/GibbsState_EN.ipynb)
6. [The Classical Shadow of Unknown Quantum States](./tutorial/quantum_simulation/ClassicalShadow_Intro_EN.ipynb)
7. [Estimation of Quantum State Properties Based on the Classical Shadow](./tutorial/quantum_simulation/ClassicalShadow_Application_EN.ipynb)
8. [Hamiltonian Simulation with Product Formula](./tutorial/quantum_simulation/HamiltonianSimulation_EN.ipynb)
9. [Simulate the Spin Dynamics on a Heisenberg Chain](./tutorial/quantum_simulation/SimulateHeisenberg_EN.ipynb)
- [Machine Learning](./tutorial/machine_learning)
1. [Encoding Classical Data into Quantum States](./tutorial/machine_learning/DataEncoding_EN.ipynb)
......@@ -163,9 +181,13 @@ We provide tutorials covering quantum simulation, machine learning, combinatoria
1. [The Barren Plateaus Phenomenon on Quantum Neural Networks (Barren Plateaus)](./tutorial/qnn_research/BarrenPlateaus_EN.ipynb)
2. [Noise Model and Quantum Channel](./tutorial/qnn_research/Noise_EN.ipynb)
3. [Calculating Gradient Using Quantum Circuit](./tutorial/qnn_research/Gradient_EN.ipynb)
4. [Expressibility of Quantum Neural Network](./tutorial/qnn_research/Expressibility_EN.ipynb)
5. [Variational Quantum Circuit Compiling](./tutorial/qnn_research/VQCC_EN.ipynb)
With the latest LOCCNet module, Paddle Quantum can efficiently simulate distributed quantum information processing tasks. Interested readers can start with this [tutorial on LOCCNet](./tutorial/locc/LOCCNET_Tutorial_EN.ipynb). In addition, Paddle Quantum supports QNN training on GPU. For users who want to get into more details, please check out the tutorial [Use Paddle Quantum on GPU](./introduction/PaddleQuantum_GPU_EN.ipynb). Moreover, Paddle Quantum could design robust quantum algorithms under noise. For more information, please see [Noise tutorial](./tutorial/qnn_research/Noise_EN.ipynb).
In a recent update, the measurement-based quantum computation (MBQC) module has been added to Paddle Quantum. Unlike the conventional quantum circuit model, MBQC has its unique way of computing. Interested readers are welcomed to read our [tutorials](./tutorial/mbqc) on how to use the MBQC module and its use cases.
### API documentation
For those who are looking for explanation on the python class and functions provided in Paddle Quantum, we refer to our [API documentation page](https://qml.baidu.com/api/introduction.html).
......
......@@ -6,7 +6,7 @@
- [安装步骤](#安装步骤)
- [安装 PaddlePaddle](#安装-paddlepaddle)
- [安装 Paddle Quantum](#安装-paddle-quantum)
- [使用 openfermion 读取 xyz 描述文件](#使用-openfermion-读取-xyz-描述文件)
- [量子化学模块的环境设置](#量子化学模块的环境设置)
- [运行](#运行)
- [入门与开发](#入门与开发)
- [教程入门](#教程入门)
......@@ -34,7 +34,7 @@
</a>
<!-- PyPI -->
<a href="https://pypi.org/project/paddle-quantum/">
<img src="https://img.shields.io/badge/pypi-v2.1.1-orange.svg?style=flat-square&logo=pypi"/>
<img src="https://img.shields.io/badge/pypi-v2.1.2-orange.svg?style=flat-square&logo=pypi"/>
</a>
<!-- Python -->
<a href="https://www.python.org/">
......@@ -89,17 +89,32 @@ pip install -e .
```
### 使用 OpenFermion 读取 .xyz 描述文件
### 量子化学模块的环境设置
> 仅在 macOS 和 linux 下可以使用 OpenFermion 读取 .xyz 描述文件
我们的量子化学模块是基于 `Openfermion``Psi4` 进行开发的,所以在运行量子化学模块之前需要先行安装这两个Python包
VQE中调用 OpenFermion 读取分子 .xyz 文件并计算,因此需要安装 openfermion 和 openfermionpyscf。
> 推荐在 Python3.8 环境中安装这些 Python包。
`Openfermion` 可以用如下指令进行安装。
```bash
pip install openfermion
pip install openfermionpyscf
```
在安装 `psi4` 时,我们建议您使用 conda。对于 **MacOS/Linux** 的用户,可以使用如下指令。
```bash
conda install psi4 -c psi4
```
对于 **Windows** 用户,请使用
```bash
conda install psi4 -c psi4 -c conda-forge
```
**注意:** 更多的下载方法请参考 [Psi4](https://psicode.org/installs/v14/)
### 运行
现在,可以试着运行一段程序来验证量桨是否已安装成功。这里我们运行量桨提供的量子近似优化算法 (QAOA) 的例子。
......@@ -134,10 +149,15 @@ Paddle Quantum(量桨)建立起了人工智能与量子计算的桥梁,为
在这里,我们提供了涵盖量子模拟、机器学习、组合优化、本地操作与经典通讯(local operations and classical communication, LOCC)、量子神经网络等多个领域的案例供大家学习。每个教程目前支持网页阅览和运行 Jupyter Notebook 两种方式。我们推荐用户下载 Notebook 后,本地运行进行实践。
- [量子模拟](./tutorial/quantum_simulation)
1. [变分量子特征求解器(VQE)](./tutorial/quantum_simulation/VQE_CN.ipynb)
2. [子空间搜索 - 量子变分特征求解器(SSVQE)](./tutorial/quantum_simulation/SSVQE_CN.ipynb)
3. [变分量子态对角化算法(VQSD)](./tutorial/quantum_simulation/VQSD_CN.ipynb)
4. [吉布斯态的制备(Gibbs State Preparation)](./tutorial/quantum_simulation/GibbsState_CN.ipynb)
1. [哈密顿量的构造](./tutorial/quantum_simulation/BuildingMolecule_CN.ipynb)
2. [变分量子特征求解器(VQE)](./tutorial/quantum_simulation/VQE_CN.ipynb)
3. [子空间搜索 - 量子变分特征求解器(SSVQE)](./tutorial/quantum_simulation/SSVQE_CN.ipynb)
4. [变分量子态对角化算法(VQSD)](./tutorial/quantum_simulation/VQSD_CN.ipynb)
5. [吉布斯态的制备(Gibbs State Preparation)](./tutorial/quantum_simulation/GibbsState_CN.ipynb)
6. [未知量子态的经典影子](./tutorial/quantum_simulation/ClassicalShadow_Intro_CN.ipynb)
7. [基于经典影子的量子态性质估计](./tutorial/quantum_simulation/ClassicalShadow_Application_CN.ipynb)
8. [利用 Product Formula 模拟时间演化](./tutorial/quantum_simulation/HamiltonianSimulation_CN.ipynb)
9. [模拟一维海森堡链的自旋动力学](./tutorial/quantum_simulation/SimulateHeisenberg_CN.ipynb)
- [机器学习](./tutorial/machine_learning)
1. [量子态编码经典数据](./tutorial/machine_learning/DataEncoding_CN.ipynb)
......@@ -169,9 +189,13 @@ Paddle Quantum(量桨)建立起了人工智能与量子计算的桥梁,为
1. [量子神经网络的贫瘠高原效应(Barren Plateaus)](./tutorial/qnn_research/BarrenPlateaus_CN.ipynb)
2. [噪声模型与量子信道](./tutorial/qnn_research/Noise_CN.ipynb)
3. [使用量子电路计算梯度](./tutorial/qnn_research/Gradient_CN.ipynb)
4. [量子神经网络的表达能力](./tutorial/qnn_research/Expressibility_CN.ipynb)
5. [变分量子电路编译](./tutorial/qnn_research/VQCC_CN.ipynb)
随着 LOCCNet 模组的推出,量桨现已支持分布式量子信息处理任务的高效模拟和开发。感兴趣的读者请参见[教程](./tutorial/locc/LOCCNET_Tutorial_CN.ipynb)。Paddle Quantum 也支持在 GPU 上进行量子机器学习的训练,具体的方法请参考案例:[在 GPU 上使用 Paddle Quantum](./introduction/PaddleQuantum_GPU_CN.ipynb)。此外,量桨可以基于噪声模块进行含噪算法的开发以及研究,详情请见[噪声模块教程](./tutorial/qnn_research/Noise_CN.ipynb)
在最近的更新中,量桨还加入了基于测量的量子计算(measurement-based quantum computation, MBQC)模块。与传统的量子电路模型不同,MBQC 具有其独特的运行方式,感兴趣的读者请参见我们提供的[多篇教程](./tutorial/mbqc)以了解量桨 MBQC 模块的使用方法和应用案例。
### API 文档
我们为 Paddle Quantum 提供了独立的 [API 文档页面](https://qml.baidu.com/api/introduction.html),包含了供用户使用的所有函数和类的详细说明与用法。
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -17,4 +17,4 @@ Paddle Quantum Library
"""
name = "paddle_quantum"
__version__ = "2.1.1"
__version__ = "2.1.2"
......@@ -535,6 +535,9 @@ class UAnsatz:
Args:
state (paddle.Tensor): 输入的量子态,表示要把选定的量子比特重置为该量子态
which_qubits (list): 需要被重置的量子比特编号
Returns:
paddle.Tensor: 重置后的量子态
"""
qubits_list = which_qubits
n = self.n
......@@ -577,6 +580,7 @@ class UAnsatz:
else:
raise ValueError("Can't recognize the mode of quantum state.")
self.__state = _state
return _state
@property
def U(self):
......@@ -676,12 +680,30 @@ class UAnsatz:
Args:
x (Tensor): 待编码的向量
which_qubits (list): 用于编码的量子比特
mode (str): 生成的量子态的表示方式,``"state_vector"`` 代表态矢量表示, ``"density_matrix"`` 代表密度矩阵表示
which_qubits (list): 用于编码的量子比特
Returns:
Tensor: 一个形状为 ``(2 ** n, )`` 或 ``(2 ** n, 2 ** n)`` 的张量,表示编码之后的量子态。
代码示例:
.. code-block:: python
import paddle
from paddle_quantum.circuit import UAnsatz
n = 3
built_in_amplitude_enc = UAnsatz(n)
# 经典信息 x 需要是 Tensor 的形式
x = paddle.to_tensor([0.3, 0.4, 0.5, 0.6])
state = built_in_amplitude_enc.amplitude_encoding(x, 'state_vector', [0,2])
print(state.numpy())
::
[0.32349834+0.j 0.4313311 +0.j 0. +0.j 0. +0.j
0.53916389+0.j 0.64699668+0.j 0. +0.j 0. +0.j]
"""
assert x.size <= 2 ** self.n, \
"the number of classical data should less than or equal to the number of qubits"
......
# 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Class for randomly generating a Clifford operator
"""
import numpy as np
from paddle_quantum.circuit import UAnsatz
__all__ = [
"Clifford",
"compose_clifford_circuit"
]
class Clifford:
r"""用户可以通过实例化该 ``class`` 来随机生成一个 Clifford operator。
Attributes:
n (int): 该 Clifford operator 作用的量子比特数目
References:
1. Sergey Bravyi and Dmitri Maslov, Hadamard-free circuits expose the structure of the clifford group. arXiv preprint arXiv:2003.09412, 2020.
"""
def __init__(self, n):
r"""Clifford 的构造函数,用于实例化一个 Clifford 对象
Args:
n (int): 该 Clifford operator 作用的量子比特数目
"""
# number of qubit
self.n = n
self.__table, self.__Gamma, self.__Delta, self.__h, self.__s = _random_clifford(n)
self.phase = []
for qbit in range(2 * self.n):
self.phase.append(np.random.randint(0, 2))
# Initialize stabilizer table
self.x = np.transpose(self.__table)[0:n, :]
# Initialize destabilizer table
self.z = np.transpose(self.__table)[n:2 * n, :]
def print_clifford(self):
r"""输出该 Clifford 在 Pauli 基上的作用关系,来描述这个 Clifford
"""
base = []
base_out = []
n = 2 * self.n
# Initialize Pauli basis
for position in range(self.n):
base.append('X' + str(position + 1))
for position in range(self.n):
base.append('Z' + str(position + 1))
# Compute stabilizer table
for i in range(self.n):
temp = ''
for jx in range(n):
if self.x[i][jx] == 1:
temp += base[jx]
base_out.append(temp)
# Compute destabilizer table
temp = ''
for jz in range(n):
if self.z[i][jz] == 1:
temp += base[jz]
base_out.append(temp)
for i in range(n):
if i % 2 == 0:
# Fix the phase
if self.phase[i // 2] == 1:
print(base[i // 2] + ' |-> ' + '+' + base_out[i])
else:
print(base[i // 2] + ' |-> ' + '-' + base_out[i])
else:
if self.phase[self.n + (i - 1) // 2] == 1:
print(base[self.n + (i - 1) // 2] + ' |-> ' + '+' + base_out[i])
else:
print(base[self.n + (i - 1) // 2] + ' |-> ' + '-' + base_out[i])
def sym(self):
r"""获取该 Clifford operator 所对应的辛矩阵
Returns:
numpy.ndarray: Clifford 对应的辛矩阵
"""
sym = []
for i in range(self.n):
tempx = []
temp = self.x[i][self.n:2 * self.n]
for jx in range(0, self.n):
tempx.append(self.x[i][jx])
tempx.append(temp[jx])
sym.append(tempx)
tempz = []
temp = self.z[i][self.n:2 * self.n]
for jz in range(0, self.n):
tempz.append(self.z[i][jz])
tempz.append(temp[jz])
sym.append(tempz)
return np.array(sym).T
def tableau(self):
r"""获取该 Clifford operator 所对应的 table,对 n 个 qubits 情况,前 n 行对应 X_i 的结果,后 n 行对应 Z_i 的结果。
Returns:
numpy.ndarray: 该 Clifford 的 table
"""
return np.transpose(self.__table)
def circuit(self):
r"""获取该 Clifford operator 所对应的电路
Returns:
UAnsatz: 该 Clifford 对应的电路
"""
cir = UAnsatz(self.n)
gamma1 = self.__Gamma[0]
gamma2 = self.__Gamma[1]
delta1 = self.__Delta[0]
delta2 = self.__Delta[1]
# The second cnot layer
for bitindex in range(self.n):
for j in range(bitindex + 1, self.n):
if delta2[j][bitindex] == 1:
cir.cnot([bitindex, j])
# The second cz layer
for bitindex in range(self.n):
for j in range(bitindex + 1, self.n):
if gamma2[bitindex][j] == 1:
cir.cz([bitindex, j])
# The second P layer
for bitindex in range(self.n):
if gamma2[bitindex][bitindex] == 1:
cir.s(bitindex)
# Pauli layer
for bitindex in range(self.n):
if self.phase[bitindex] == 1 and self.phase[bitindex + self.n] == 0:
cir.x(bitindex)
elif self.phase[bitindex] == 0 and self.phase[bitindex + self.n] == 1:
cir.z(bitindex)
elif self.phase[bitindex] == 0 and self.phase[bitindex + self.n] == 0:
cir.y(bitindex)
# S layer
swapped = []
for bitindex in range(self.n):
if self.__s[bitindex] == bitindex:
continue
swapped.append(self.__s[bitindex])
if bitindex in swapped:
continue
cir.swap([bitindex, self.__s[bitindex]])
# Hadamard layer
for bitindex in range(self.n):
if self.__h[bitindex] == 1:
cir.h(bitindex)
# cnot layer
for bitindex in range(self.n):
for j in range(bitindex + 1, self.n):
if delta1[j][bitindex] == 1:
cir.cnot([bitindex, j])
# cz layer
for bitindex in range(self.n):
for j in range(bitindex + 1, self.n):
if gamma1[bitindex][j] == 1:
cir.cz([bitindex, j])
# P layer
for bitindex in range(self.n):
if gamma1[bitindex][bitindex] == 1:
cir.s(bitindex)
return cir
def compose_clifford_circuit(clif1, clif2):
r"""计算两个指定的 Clifford 的复合,得到复合后的电路
Args:
clif1 (Clifford): 需要复合的第 1 个 Clifford
clif2 (Clifford): 需要复合的第 2 个 Clifford
Returns:
UAnsatz: 复合后的 Clifford 所对应的电路,作用的顺序为 clif1、clif2
"""
assert clif1.n == clif2.n, "the number of qubits of two cliffords should be the same"
return clif1.circuit() + clif2.circuit()
def _sample_qmallows(n):
r"""n 量子比特的 quantum mallows 采样,来获得随机采样 Clifford 时所需要的 S 和 h
Args:
n (int): 量子比特数目
Returns:
tuple: 包含
numpy.ndarray: Clifford 采样时需要的参数 h
numpy.ndarray: Clifford 采样时需要的参数 S
Note:
这是内部函数,你并不需要直接调用到该函数。
"""
# Hadamard layer
h = np.zeros(n, dtype=int)
# S layer
S = np.zeros(n, dtype=int)
A = list(range(n))
for i in range(n):
m = n - i
r = np.random.uniform(0, 1)
index = int(2 * m - np.ceil(np.log(r * (4 ** m - 1) + 1) / np.log(2.0)))
h[i] = 1 * (index < m)
if index < m:
k = index
else:
k = 2 * m - index - 1
S[i] = A[k]
del A[k]
return h, S
def _random_clifford(n):
r"""随机生成一个指定量子比特数目 n 的 Clifford 所对应的 table 及 canonical form 中的参数
Args:
n (int): 量子比特数目
Returns:
tuple: 包含
numpy.ndarray: 随机生成的 Clifford 所对应的 table
list: 随机生成的 Clifford 所对应的参数 Gamma
list: 随机生成的 Clifford 所对应的参数 Delta
numpy.ndarray: 随机生成的 Clifford 所对应的参数 h
numpy.ndarray: 随机生成的 Clifford 所对应的参数 S
Note:
这是内部函数,你并不需要直接调用到该函数。
"""
assert (n <= 100), "too many qubits"
# Some constant matrices
bigzero = np.zeros((2 * n, 2 * n), dtype=int)
nzero = np.zeros((n, n), dtype=int)
I = np.identity(n, dtype=int)
h, S = _sample_qmallows(n)
Gamma1 = np.copy(nzero)
Delta1 = np.copy(I)
Gamma2 = np.copy(nzero)
Delta2 = np.copy(I)
for i in range(n):
Gamma2[i, i] = np.random.randint(2)
if h[i] == 1:
Gamma1[i, i] = np.random.randint(2)
# Constraints for canonical form
for j in range(n):
for i in range(j + 1, n):
b = np.random.randint(2)
Gamma2[i, j] = b
Gamma2[j, i] = b
Delta2[i, j] = np.random.randint(2)
if h[i] == 1 and h[j] == 1:
b = np.random.randint(2)
Gamma1[i, j] = b
Gamma1[j, i] = b
if h[i] == 1 and h[j] == 0 and S[i] < S[j]:
b = np.random.randint(2)
Gamma1[i, j] = b
Gamma1[j, i] = b
if h[i] == 0 and h[j] == 1 and S[i] > S[j]:
b = np.random.randint(2)
Gamma1[i, j] = b
Gamma1[j, i] = b
if h[i] == 0 and h[j] == 1:
Delta1[i, j] = np.random.randint(2)
if h[i] == 1 and h[j] == 1 and S[i] > S[j]:
Delta1[i, j] = np.random.randint(2)
if h[i] == 0 and h[j] == 0 and S[i] < S[j]:
Delta1[i, j] = np.random.randint(2)
# Compute stabilizer table
st1 = np.matmul(Gamma1, Delta1)
st2 = np.matmul(Gamma2, Delta2)
inv1 = np.linalg.inv(np.transpose(Delta1))
inv2 = np.linalg.inv(np.transpose(Delta2))
f_1 = np.block([[Delta1, nzero], [st1, inv1]])
f_2 = np.block([[Delta2, nzero], [st2, inv2]])
f_1 = f_1.astype(int) % 2
f_2 = f_2.astype(int) % 2
U = np.copy(bigzero)
for i in range(n):
U[i, :] = f_2[S[i], :]
U[i + n, :] = f_2[S[i] + n, :]
# Apply Hadamard layer to the stabilizer table
for i in range(n):
if h[i] == 1:
U[(i, i + n), :] = U[(i + n, i), :]
Gamma = [Gamma1, Gamma2]
Delta = [Delta1, Delta2]
return np.matmul(f_1, U) % 2, Gamma, Delta, h, S
......@@ -13,7 +13,7 @@
# limitations under the License.
"""
Functions and data simulator class of quantum finance
Functions and data simulator class of quantum finance.
"""
import fastdtw
......@@ -209,7 +209,7 @@ def portfolio_diversification_hamiltonian(penalty, rho, q):
.. math::
\begin{aligned}
C_x &= -\sum_{i=1}^{n}\sum_{j=1}^{n}\rho_{ij}x_{ij} + A\left(K- \sum_{j=1}^n y_j \right)^2 + \sum_{i=1}^n A\left(\sum_{j=1}^n 1- x_{ij} \right)^2 \\
C_x &= -\sum_{i=1}^{n}\sum_{j=1}^{n}\rho_{ij}x_{ij} + A\left(q- \sum_{j=1}^n y_j \right)^2 + \sum_{i=1}^n A\left(\sum_{j=1}^n 1- x_{ij} \right)^2 \\
&\quad + \sum_{j=1}^n A\left(x_{jj} - y_j\right)^2 + \sum_{i=1}^n \sum_{j=1}^n A\left(x_{ij}(1 - y_j)\right).\\
\end{aligned}
......
......@@ -24,7 +24,7 @@ from math import log2, sqrt
class LoccStatus(object):
r"""用于表示 LOCCNet 中的一个 LOCC 态节点。
由于我们在 LOCC 中不仅关心量子态的解析形式,同时还关心得到它的概率,以及是经过怎样的测量而得到。因此该类包含三个成员变量:量子态 ``state`` 、得到这个态的概率 ``prob`` 和得到这个态的测量的测量结果是什么,即 ``measured_result`` 。
Attributes: