Ind*_*jee 5 quantum-computing q#
如标题所述,如何在Q#中实现Grover扩散算子?我知道它的定义是任意数量的qubit的统一状态2 ?s|s? - I在哪里|s?。这可以进一步用夹在一对H门之间的Z0(称为U0)门来定义。我无法在量子图元和佳能文档中找到任何以可能的名称(例如Grover,diff等)开头的函数。
我不想使用该函数,AmpAmpByOracle因为它是非常高级的实现,并且不清楚我的理解。我想实现一个函数,它采用一个oracle Uf(我不知道是我想知道的)和它所需要的qubit数(N),并通过简单遵循Grover's Algorithm |中给出的电路来执行Grover算法。Wikipedia并通过在r = rox(2 ^(N / 2))迭代结束时测量所有N个量子位来测量所需状态。
小智 4
扩散操作有点棘手。我发现最简单的方法是将其分解为几部分:
这一切都变成了:
// 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
}
Run Code Online (Sandbox Code Playgroud)
这是未编译的代码,因此可能存在一些拼写错误......
| 归档时间: |
|
| 查看次数: |
257 次 |
| 最近记录: |