# 含噪声量子线路

## 概述

$\varepsilon(\rho) =\sum_{k=0}^{m-1} E_{k} \rho E_{k}^{\dagger}$

## 泡利信道（Pauli Channel）

$\varepsilon_{BF}( \rho ) =(1-p)I \rho I +pX \rho X$

$\begin{split}E_0=\sqrt{1-p}\begin{bmatrix} 1 & 0\\ 0 & 1 \end{bmatrix}, E_{1} =\sqrt{p}\begin{bmatrix} 0 & 1\\ 1 & 0 \end{bmatrix}\end{split}$

$\varepsilon _{Pauli}( \rho ) =(1-p_x-p_y-p_z)\rho + p_x X \rho X+ p_y Y \rho Y+p_z Z \rho Z$

$\varepsilon _{PF}( \rho ) =(1-p)\rho +pZ \rho Z$

$\varepsilon _{BPF}( \rho ) =(1-p)\rho +pY \rho Y$

$\varepsilon _{DF}( \rho ) =(1-p)\rho + \frac{p}{3}(X \rho X+ Y \rho Y+Z \rho Z)$

[9]:

from mindquantum.core.gates import DepolarizingChannel, X
from mindquantum.core.circuit import Circuit

circ = Circuit()
circ += X.on(0)
circ += DepolarizingChannel(0.1).on(0)
circ.measure(0)
circ.svg()

[9]:


[10]:

from mindquantum.simulator import Simulator

sim = Simulator('mqvector', 1)
result = sim.sampling(circ, shots=1000)
result.svg()

[10]:


## 阻尼信道（Damping Channel）

$\varepsilon_{AD}( \rho ) =E_{0} \rho E_{0}^{\dagger } +E_{1} \rho E_{1}^{\dagger }$

$\begin{split}E_{0} =\begin{bmatrix} 1 & 0\\ 0 & \sqrt{1-\gamma } \end{bmatrix}, E_{1} =\begin{bmatrix} 0 & \sqrt{\gamma }\\ 0 & 0 \end{bmatrix}\end{split}$

$$\gamma$$为耗散系数。

$\varepsilon_{PD}( \rho ) =E_{0} \rho E_{0}^{\dagger } +E_{1} \rho E_{1}^{\dagger }$

$\begin{split}E_{0} =\begin{bmatrix} 1 & 0\\ 0 & \sqrt{1-\gamma } \end{bmatrix}, E_{1} =\begin{bmatrix} 0 & 0\\ 0 & \sqrt{\gamma } \end{bmatrix}\end{split}$

$$\gamma$$为损失系数。

[11]:

from mindquantum.core.gates import AmplitudeDampingChannel, H

circ2 = Circuit()
circ2 += H.on(0)
circ2 += AmplitudeDampingChannel(0.8).on(0)
circ2.svg()

[11]:

[12]:

# 将线路演化5次并打印量子态
for i in range(5):
sim.reset()                 # 初始化模拟器
sim.apply_circuit(circ2)    # 演化线路
print(sim.get_qs(ket=True)) # 获取量子态
print()

1¦0⟩

0.912870929175277¦0⟩
0.408248290463863¦1⟩

0.912870929175277¦0⟩
0.408248290463863¦1⟩

1¦0⟩

1¦0⟩



[13]:

from mindquantum.core.gates import PhaseDampingChannel

circ3 = Circuit()
circ3 += H.on(0)
circ3 += PhaseDampingChannel(0.7).on(0)
circ3.svg()

[13]:

[14]:

# 将线路演化5次并打印量子态
for i in range(5):
sim.reset()                 # 初始化模拟器
sim.apply_circuit(circ3)    # 演化线路
print(sim.get_qs(ket=True)) # 获取量子态
print()

1¦1⟩

0.8770580193070293¦0⟩
0.4803844614152615¦1⟩

1¦1⟩

1¦1⟩

0.8770580193070293¦0⟩
0.4803844614152615¦1⟩



## 实例演示——含噪声QAOA

[15]:

from mindquantum.core.circuit import Circuit, UN
from mindquantum.core.gates import H, RX, Rzz, AmplitudeDampingChannel
from mindquantum.core.operators import Hamiltonian, QubitOperator
from mindquantum.simulator import Simulator
from scipy.optimize import minimize
import networkx as nx
import mindspore as ms
ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU")

# 生成待求解的图
g = nx.Graph()
nx.add_path(g, [0, 1])
nx.add_path(g, [1, 2])
nx.add_path(g, [2, 3])
nx.add_path(g, [3, 4])
nx.add_path(g, [0, 4])
nx.add_path(g, [0, 2])
nx.draw(g, with_labels=True, font_weight='bold')

gamma = 0.005                                        # 设定振幅阻尼信道的耗散系数
circ = Circuit(UN(H, g.nodes))                       # 生成均匀叠加态
circ += UN(AmplitudeDampingChannel(gamma), g.nodes)  # 假设每个H门作用后都会出现噪声

# 生成ansatz线路，详细的原理请参考QAOA教案
for i in range(4):
for j in g.edges:
circ += Rzz(f'g{i}').on(j)                    # 对图中的每条边作用ZZ门
circ.barrier(False)
for j in g.nodes:
circ += RX(f'b{i}').on(j)                    # 对每个节点作用RX门
circ += AmplitudeDampingChannel(gamma).on(j) # 假设每个RX门作用后都会出现噪声
circ.barrier(False)

# 生成哈密顿量
ham = QubitOperator()
for i in g.edges:
ham += QubitOperator(f'Z{i[0]} Z{i[1]}')
ham = Hamiltonian(ham)

sim = Simulator('mqvector', circ.n_qubits)           # 初始化模拟器

# 定义待优化的函数，由于噪声存在，每次需要重新演化线路
def func(x):
sim.reset()                                      # 重置模拟器
sim.apply_circuit(circ, x)                       # 演化线路，参数x是优化器生成的线路参数数值
f = sim.get_expectation(ham).real                # 计算并返回哈密顿量的期望值
return f

# 设置线路参数的初始数值
n_paras = len(circ.params_name)
init_amp = [0.0 for i in range(n_paras)]

res = minimize(func, init_amp, method='nelder-mead') # 使用优化器优化参数，得到哈密顿量期望值的最小值，优化方法是nelder-mead
cut = (len(g.edges) - res.fun) / 2                   # 计算max-cut数
print('max cut:', cut)                               # 打印结果

max cut: 4.716655809015849


[16]:

from mindquantum.utils.show_info import InfoTable

InfoTable('mindquantum', 'scipy', 'numpy')

[16]:

Software Version
mindquantum0.9.0
scipy1.10.1
numpy1.23.5
System Info
Python3.8.17
OSWindows AMD64
Memory8.39 GB
CPU Max Thread8
DateMon Sep 18 11:13:57 2023