量子计算秒解问题:Deutsch-Jozsa Algorithm

Posted 元之田

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了量子计算秒解问题:Deutsch-Jozsa Algorithm相关的知识,希望对你有一定的参考价值。

Deutsch Algorithm

问题:给定一个函数f(x), x ∈ 0 , 1 x \\in \\0,1\\ x0,1,如何判断f(x)是balanced function还是constant function?

这里constant function指,无论x是0还是1,f(x)的结果相同。而对于balanced function,f(0)!=f(1)。

解法:通过0,1叠加态,构造f(x)叠加态,判断其结果。推导过程如下,




这个方法可以更快的得知,f(0)和f(1)的关系比较,而仅仅需要测量一次。试想,如果我们通过经典计算机,把f(0)和f(1)相减,也可以达到相同的结果,那么这种方法的优势是什么?
答:这里利用叠加态,实际上只调用了f(x)这个函数一次。

接下来用代码实现一下:

# initialization
import numpy as np

# importing Qiskit
from qiskit import IBMQ, Aer
from qiskit.providers.ibmq import least_busy
from qiskit import QuantumCircuit, assemble, transpile

# import basic plot tools
from qiskit.visualization import plot_histogram

qc = QuantumCircuit(2,2)
qc.h(0)
qc.x(1)
qc.h(1)

qc.barrier()
qc.cx(0,1)
qc.barrier()

qc.h(0)
qc.measure(0,0)
qc.draw("mpl")
# use local simulator
qasm_sim = Aer.get_backend('qasm_simulator')
shots = 1024
qobj = assemble(qc, qasm_sim)
results = qasm_sim.run(qobj).result()
answer = results.get_counts()

plot_histogram(answer)

这里我们在中间构造了一个balanced function。

q 0 q 1 q_0q_1 q0q1f(x)
000
011
101
110



测量结果为1,所以这是一个balanced function。

Deutsch-Jozsa Algorithm

Deutsch-Jozsa Algorithm将Deutsch Algorithm推广到n qubit。

Using a quantum computer, we can solve this problem with 100% confidence after only one call to the function f(x), provided we have the function f implemented as a quantum oracle, which maps the state ∣ x ⟩ ∣ y ⟩ t o ∣ x ⟩ ∣ y ⊕ f ( x ) ⟩ \\vert x\\rangle \\vert y\\rangle to \\vert x\\rangle \\vert y \\oplus f(x)\\rangle xytoxyf(x), where ⊕ \\oplus is addition modulo 2. Below is the generic circuit for the Deutsch-Jozsa algorithm.

Now, let’s go through the steps of the algorithm:

Prepare two quantum registers. The first is an n-qubit register initialized to |0\\rangle, and the second is a one-qubit register initialized to ∣ 1 ⟩ : ∣ ψ 0 ⟩ = ∣ 0 ⟩ ⊗ n ∣ 1 ⟩ |1\\rangle: \\vert \\psi_0 \\rangle = \\vert0\\rangle^\\otimes n \\vert 1\\rangle 1:ψ0=0n1

Apply a Hadamard gate to each qubit:
∣ ψ 1 ⟩ = 1 2 n + 1 ∑ x = 0 2 n − 1 ∣ x ⟩ ( ∣ 0 ⟩ − ∣ 1 ⟩ ) \\vert \\psi_1 \\rangle = \\frac1\\sqrt2^n+1\\sum_x=0^2^n-1 \\vert x\\rangle \\left(|0\\rangle - |1 \\rangle \\right) ψ1=2n+1 1x=02n1x(01)

Apply the quantum oracle ∣ x ⟩ ∣ y ⟩ t o ∣ x ⟩ ∣ y ⊕ f ( x ) ⟩ \\vert x\\rangle \\vert y\\rangle to \\vert x\\rangle \\vert y \\oplus f(x)\\rangle xytoxyf(x):

∣ ψ 2 ⟩ = 1 2 n + 1 ∑ x = 0 2 n − 1 ∣ x ⟩ ( ∣ f ( x ) ⟩ − ∣ 1 ⊕ f ( x ) ⟩ ) = 1 2 n + 1 ∑ x = 0 2 n − 1 ( − 1 ) f ( x ) ∣ x ⟩ ( ∣ 0 ⟩ − ∣ 1 ⟩ ) \\beginaligned \\lvert \\psi_2 \\rangle & = \\frac1\\sqrt2^n+1\\sum_x=0^2^n-1 \\vert x\\rangle (\\vert f(x)\\rangle - \\vert 1 \\oplus f(x)\\rangle) \\\\ & = \\frac1\\sqrt2^n+1\\sum_x=0^2^n-1(-1)^f(x)|x\\rangle ( |0\\rangle - |1\\rangle ) \\endaligned ψ2=2n+1 1x=02n1x(f(x)1f(x))=2n+1 1x=02n1(1)f(x)x(01)
since for each x,f(x) is either 0 or 1.

At this point the second single qubit register may be ignored. Apply a Hadamard gate to each qubit in the first register:

∣ ψ 3 ⟩ = 1 2 n ∑ x = 0 2 n − 1 ( − 1 ) f ( x ) [ ∑ y = 0 2 n − 1 ( − 1 ) x ⋅ y ∣ y ⟩ ] = 1 2 n ∑ y = 0 2 n − 1 [ ∑ x = 0 2 n − 1 ( − 1 ) f ( x ) ( − 1 ) x ⋅ y ] ∣ y ⟩ \\beginaligned \\lvert \\psi_3 \\rangle & = \\frac12^n\\sum_x=0^2^n-1(-1)^f(x) \\left[ \\sum_y=0^2^n-1(-1)^x \\cdot y \\vert y \\rangle \\right] \\\\ & = \\frac12^n\\sum_y=0^2^n-1 \\left[ \\sum_x=0^2^n-1(-1)^f(x)(-1)^x \\cdot y \\right] \\vert y \\rangle \\endaligned ψ3=2n1x=02n1(1)f(x)[y=02n1(1)xyy]=2n1y=02n1[x=02n1(1)f(x)(1)xy]y

where x ⋅ y = x 0 y 0 ⊕ x 1 y 1 ⊕ … ⊕ x n − 1 y n − 1 x \\cdot y = x_0y_0 \\oplus x_1y_1 \\oplus \\ldots \\oplus x_n-1y_n-1 xy=x0y0x量子计算(二十一):Deutsch-Josza算法

Deutsch-Jozsa Algorithm

高防秒解服务器|香港服务器|美国高防服务器

每日一练(day06-秒解皇后问题)

MT97三元基本不等式秒解一道三元不等式

台州诛仙sf高防服务器,瞬间秒解,无限防御