量子跟踪模拟器Quantum Trace Simulator

Microsoft 量子计算机跟踪模拟器执行量子程序,而无需实际模拟量子计算机的状态。The Microsoft quantum computer trace simulator executes a quantum program without actually simulating the state of a quantum computer. 出于此原因,跟踪模拟器可以执行使用数千个量子位的量子程序。For this reason, the trace simulator can execute quantum programs that use thousands of qubits. 它适用于两个主要目的:It is useful for two main purposes:

  • 调试属于量子程序的一部分的典型代码。Debugging classical code that is part of a quantum program.
  • 估计在量子计算机上运行量子程序给定实例所需的资源。Estimating the resources required to run a given instance of a quantum program on a quantum computer.

必须执行度量时,跟踪模拟器依赖于用户提供的其他信息。The trace simulator relies on additional information provided by the user when measurements must be performed. 有关详细信息,请参阅提供度量结果的概率部分。See Section Providing the probability of measurement outcomes for more details on this.

提供度量结果的概率Providing the Probability of Measurement Outcomes

量子算法中出现两种类型的度量。There are two kinds of measurements that appear in quantum algorithms. 第一种类型起到辅助作用,用户通常从中了解结果的概率。The first kind plays an auxiliary role where the user usually knows the probability of the outcomes. 在这种情况下,用户可以编写 Microsoft.Quantum.Intrinsic 命名空间中的 AssertProb 来表达此知识。In this case the user can write AssertProb from the Microsoft.Quantum.Intrinsic namespace to express this knowledge. 以下示例对此进行了说明:The following example illustrates this:

operation TeleportQubit(source : Qubit, target : Qubit) : Unit {
    using (qubit = Qubit()) {
        H(qubit);
        CNOT(qubit, target);
        CNOT(source, qubit);
        H(source);

        AssertProb([PauliZ], [source], Zero, 0.5, "Outcomes must be equally likely", 1e-5);
        AssertProb([PauliZ], [q], Zero, 0.5, "Outcomes must be equally likely", 1e-5);

        if (M(source) == One)  { Z(target); X(source); }
        if (M(q) == One) { X(target); X(q); }
    }
}

当跟踪模拟器执行 AssertProb 时,它将在 source 上记录测量 PauliZ,并且应向 q 提供 Zero 的结果,其概率为 0.5。When the trace simulator executes AssertProb it will record that measuring PauliZ on source and q should be given an outcome of Zero with probability 0.5. 当模拟器稍后执行 M 时,它将找到结果概率的记录值,并且 M 将返回 ZeroOne,其概率为 0.5。When the simulator executes M later, it will find the recorded values of the outcome probabilities and M will return Zero or One with probability 0.5. 在跟踪量子状态的模拟器上执行相同的代码时,此类模拟器将检查 AssertProb 中提供的概率是否正确。When the same code is executed on a simulator that keeps track of the quantum state, such a simulator will check that the provided probabilities in AssertProb are correct.

使用量子计算机跟踪模拟器运行程序Running your Program with the Quantum Computer Trace Simulator

量子计算机跟踪模拟器可以被视为另一台目标计算机。The quantum computer trace simulator may be viewed as just another target machine. 使用该模拟器的 C# 驱动程序与任何其他量子模拟器的 C# 驱动程序非常相似:The C# driver program for using it is very similar to the one for any other quantum Simulator:

using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;
using Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators;

namespace Quantum.MyProgram
{
    class Driver
    {
        static void Main(string[] args)
        {
            QCTraceSimulator sim = new QCTraceSimulator();
            var res = MyQuantumProgram.Run().Result;
            System.Console.WriteLine("Press any key to continue...");
            System.Console.ReadKey();
        }
    }
}

请注意,如果至少有一个度量未使用 AssertProb 进行批注,则模拟器将从 Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators 命名空间引发 UnconstrainedMeasurementExceptionNote that if there is at least one measurement not annotated using AssertProb, the simulator will throw UnconstrainedMeasurementException from the Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators namespace. 请参阅有关 UnconstrainedMeasurementException 的 API 文档以了解更多详细信息。See the API documentation on UnconstrainedMeasurementException for more details.

除了运行量子程序之外,跟踪模拟器还附带了五个用于检测程序中的 bug 和执行量子程序资源估计的组件:In addition to running quantum programs, the trace simulator comes with five components for detecting bugs in programs and performing quantum program resource estimates:

其中每个组件都可以通过在 QCTraceSimulatorConfiguration 中设置相应的标志来启用。Each of these components may be enabled by setting appropriate flags in QCTraceSimulatorConfiguration. 相应的引用文件中提供了有关使用其中每个组件的更多详细信息。More details about using each of these components are provided in the corresponding reference files. 请参阅有关 QCTraceSimulatorConfiguration 的 API 文档以了解特定详细信息。See the API documentation on QCTraceSimulatorConfiguration for specific details.

另请参阅See also

量子计算机跟踪模拟器 C# 参考The quantum computer trace simulator C# reference