正如标题所说,如何在Q#中实现Grover的扩散算子?我知道它被定义为2 ⟨s|s⟩ - I,其中|s⟩是任意数量的量子位的一致状态。这可以进一步定义为Z0 (它被称为U0),它被一对H门夹在一起。我无法在量子原语和佳能文档中找到任何函数,从Grover、diff等可能的名称开始。
我不想使用函数AmpAmpByOracle,因为它是非常高级别的实现,并且不清楚我的理解。我想实现一个函数,它需要一个oracle (我不知道)和它所需的量子位数(N),并执行Grover的算法,只需遵循Grover算法中给出的电路,并通过在r=大约x(2^(N/2))迭代结束时测量所有的N个量子位来测量所需的状态。
发布于 2018-08-08 17:12:05
扩散操作有点棘手。我发现最容易把它分解成碎片:
这一切都变成:
// register is the Qubit[] that we want to apply the diffusion operation to
using (ancillae = Qubit[1])
{
let ancilla = ancillae[0];
X(ancilla); // Puts the ancilla into the |1> state
H(ancilla); // And now into the |-> state
ApplyToEach(H, register); // Put the register qubits into the X basis
ApplyToEach(X, register); // Flip 0->1 and 1->0
(Controlled X)(register, ancilla); // Do the controlled flip of the ancilla
ApplyToEach(X, register); // Undo the flip
ApplyToEach(H, register); // Undo the basis change
H(ancilla); // Put the ancilla back into |1>
X(ancilla); // And back to |0> so we can return it
}这是未编译的代码,所以可能会有一些排印.
https://stackoverflow.com/questions/51190773
复制相似问题