如果我正确理解您的描述,量子开发套件随附的资源估算器会准确报告您的操作未使用任何量子比特或量子指令。这是因为 Q# 操作使用的量子位正是那些与using
orborrowing
语句一起显式使用的量子位,以及任何其他调用的操作使用的量子位。
例如,如果您在 Q# 中编写一个传送操作,您可能会执行以下操作:
operation PrepareEntangledPair(left : Qubit, right : Qubit) : Unit {
body (...) {
H(left);
CNOT(left, right);
}
adjoint auto;
}
operation ApplyCorrection(here : Qubit, msg : Qubit, there : Qubit) : Unit {
if (M(msg) == One) { Z(there); }
if (M(here) == One) { X(there); }
}
operation TeleportMessage(msg : Qubit, there : Qubit) : Unit {
using (here = Qubit()) {
// Create some entanglement that we can use to send our message.
PrepareEntangledPair(here, there);
// Move our message into the entangled pair by using a Bell
// measurement.
Adjoint PrepareEntangledPair(msg, here);
// Measure out the entanglement.
ApplyCorrection(here, msg, there);
// Reset our "here" qubit before releasing it.
Reset(here);
}
}
operation TeleportClassicalFlag() : Unit {
using ((msg, there) = (Qubit(), Qubit())) {
X(msg);
TeleportMessage(msg, there);
ApplyToEach(Reset, [msg, there]);
}
}
在此运行资源估计器报告使用了三个量子位(两个由TeleportClassicalFlag
直接调用,一个由TeleportMessage
调用,由 调用TeleportClassicalFlag
):

相比之下,经典逻辑始终保持经典。这旨在使经典逻辑和量子逻辑的混合变得容易,例如在实现迭代相位估计算法时。在上面的示例中,使用的if
语句和==
运算符用于ApplyCorrection
描述隐形传输算法的经典部分。