2

当运行以下简单的量子程序以将 Hadamard 门应用于单个量子位时:

operation ApplyHadamard():()
{
    body
    {
        using (qubits  = Qubit[1])
        {
            H(qubits[0]);
        }
    }
}

我收到以下错误:

Microsoft.Quantum.Simulation.Simulators.Exceptions.ReleasedQubitsAreNotInZeroState:“释放的量子位不处于零状态。”

我正在使用Microsoft 的教程,其中没有提及使此类程序正常工作所需的任何其他内容。

我很感激 Q# 仍处于发布模式,但如果有人为此找到解决方案,那就太好了。

4

2 回答 2

2
于 2018-07-17T17:34:48.403 回答
2

The documentation has this information a few sections later, in Working with Qubits.

Target machines expect that qubits are in the |0⟩ state immediately before deallocation, so that they can be reused and offered to other using blocks for allocation.

Consider running a program on a quantum computer: the number of qubits is very limited, and you want to reuse the released qubits in other parts of the program. If they are not in zero state by that time, they can potentially be still entangled with the qubits which are not yet released, thus operations you perform on them can affect the state of other parts of the program.

Resetting the qubits to zero state automatically when they go outside the scope of their using block is dangerous as well: if they were entangled with others, measuring them to reset them can affect the state of the unreleased qubits, and thus change the results of the program - without the developer noticing this.

The requirement that the qubits should be in zero state before they can be released aims to remind the developer to double-check that all necessary information has been properly extracted from the qubits, and that they are not entangled with unreleased qubits any more.

Note that using Reset or ResetAll before releasing the qubits is not a hard requirement. For example, in Deutsch-Jozsa algorithm the last step of the algorithm is to measure all qubits except the last one. This means that for each of those qubits you already know that their state is either |0⟩ or |1⟩, and you can apply an X gate to the qubits in |1⟩ state to convert them to |0⟩ without calling Reset to measure them again. The last qubit is known to be in |-⟩ state, and you can convert it to |0⟩ by applying H and X gates.

于 2018-07-17T21:47:35.857 回答