编码德语算法
Coding Deutsch Algorithm
我目前正在尝试编写 Deutsch 算法的代码,并且正在为如何测量 |x> 量子位而苦苦挣扎。阅读 example here 有帮助,但没有解决我的根本问题。
使用下图作为基础来展示我遇到的问题,在他们提出第二个 Hadamard 变换时,我仍然将我的信息编码为对应于 |00> 的概率向量, |01>、|10> 和 |11>。
我读过的所有内容都表明我所做的就是取前 2 个值(因为它们对应于第一个量子位)并应用 Hadamard 变换,然后查看它是零还是一,但事实并非如此。似乎不起作用。有没有人实施过这个并且对如何实际实现这个有任何建议?我目前正在使用 Numpy 在 Python 中编码,以下是我所拥有的:
x = np.array([[1], [0]])
y = np.array([[0], [1]])
h = calc_hadamard(1)
phi2 = np.kron(h.dot(x), h.dot(y))
constantF = np.array([[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]])
balancedF = np.array([[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
[0, 0, 1, 0]])
print(constantF.dot(phi2))
print(balancedF.dot(phi2))
那些打印函数输出的是
- (0.5, -0.5, 0.5, -0.5),
- (0.5, -0.5, -0.5, 0.5)
希望显而易见的是,这是预期的结果,但对前两个值执行后续的 Hadamard 变换会给出相同的答案。我在这里错过了什么?
Everything I've read suggests that all I do is take the top 2 values (as they correspond to the first qubit) and apply the Hadamard transform,
不,那不是你做的。您必须对顶对和底对应用 Hadamard 操作。等价地,您必须扩展 1 量子位 Hadamard 矩阵以将其张量与其他量子位的恒等运算一起应用于 2 量子位系统:
phi3 = constantF.dot(phi2) # or balancedF
h_on_1_for_2 = np.kron(np.eye(2), h)
phi4 = np.dot(h_on_1_for_2, phi3)
Where what is output by those print functions is
(0.5, -0.5, 0.5, -0.5), and
(0.5, -0.5, -0.5, 0.5)
这确实是正确的。如果我们使用 Dirac 符号写出这些向量并分解 2 量子位状态,它给出:
1/2 ( |00> - |01> + |10> - |11> ) = 1/2 ( |0> + |1> ) ( |0> - |1> )
常量情况
1/2 ( |00> - |01> - |10> + |11> ) = 1/2 ( |0> - |1> ) ( |0> - |1> )
平衡情况
正如 Deutsch 算法 (Wikipedia : Deutsch's algorithm) 所预期的那样,我们可以 treceout(删除)第二个寄存器并将 Hadamard 应用于第一个寄存器。它给出
H ( |0> + |1> ) = |0>
常量情况
H ( |0> - |1> ) = |1>
平衡情况
你犯的错误是我们需要应用 Hadamard 然后测量的 第一个寄存器 不对应于你所说的 前两个值。我们需要回到 Dirac 符号,首先将全局状态分解为 2 个寄存器的张量积(Kronecker 积)。
我目前正在尝试编写 Deutsch 算法的代码,并且正在为如何测量 |x> 量子位而苦苦挣扎。阅读 example here 有帮助,但没有解决我的根本问题。
使用下图作为基础来展示我遇到的问题,在他们提出第二个 Hadamard 变换时,我仍然将我的信息编码为对应于 |00> 的概率向量, |01>、|10> 和 |11>。
我读过的所有内容都表明我所做的就是取前 2 个值(因为它们对应于第一个量子位)并应用 Hadamard 变换,然后查看它是零还是一,但事实并非如此。似乎不起作用。有没有人实施过这个并且对如何实际实现这个有任何建议?我目前正在使用 Numpy 在 Python 中编码,以下是我所拥有的:
x = np.array([[1], [0]])
y = np.array([[0], [1]])
h = calc_hadamard(1)
phi2 = np.kron(h.dot(x), h.dot(y))
constantF = np.array([[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]])
balancedF = np.array([[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
[0, 0, 1, 0]])
print(constantF.dot(phi2))
print(balancedF.dot(phi2))
那些打印函数输出的是
- (0.5, -0.5, 0.5, -0.5),
- (0.5, -0.5, -0.5, 0.5)
希望显而易见的是,这是预期的结果,但对前两个值执行后续的 Hadamard 变换会给出相同的答案。我在这里错过了什么?
Everything I've read suggests that all I do is take the top 2 values (as they correspond to the first qubit) and apply the Hadamard transform,
不,那不是你做的。您必须对顶对和底对应用 Hadamard 操作。等价地,您必须扩展 1 量子位 Hadamard 矩阵以将其张量与其他量子位的恒等运算一起应用于 2 量子位系统:
phi3 = constantF.dot(phi2) # or balancedF
h_on_1_for_2 = np.kron(np.eye(2), h)
phi4 = np.dot(h_on_1_for_2, phi3)
Where what is output by those print functions is
(0.5, -0.5, 0.5, -0.5), and (0.5, -0.5, -0.5, 0.5)
这确实是正确的。如果我们使用 Dirac 符号写出这些向量并分解 2 量子位状态,它给出:
1/2 ( |00> - |01> + |10> - |11> ) = 1/2 ( |0> + |1> ) ( |0> - |1> )
常量情况1/2 ( |00> - |01> - |10> + |11> ) = 1/2 ( |0> - |1> ) ( |0> - |1> )
平衡情况
正如 Deutsch 算法 (Wikipedia : Deutsch's algorithm) 所预期的那样,我们可以 treceout(删除)第二个寄存器并将 Hadamard 应用于第一个寄存器。它给出
H ( |0> + |1> ) = |0>
常量情况H ( |0> - |1> ) = |1>
平衡情况
你犯的错误是我们需要应用 Hadamard 然后测量的 第一个寄存器 不对应于你所说的 前两个值。我们需要回到 Dirac 符号,首先将全局状态分解为 2 个寄存器的张量积(Kronecker 积)。