microsoft / QuantumLibraries

Q# libraries for the Quantum Development Kit

Home Page:https://docs.microsoft.com/quantum

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ToffoliSimulator outputs different result when executing `Adjoint ApplyAnd`

weucode opened this issue · comments

Describe the bug
When running the following Q# program, the result of running on ToffoliSimulator is different from running on QuantumSimulator and SparseSimulator.

This behavior might be due to the different implementations among the three simulators. Since ToffoliSimulator does not support H gate, a specific version of ApplyAnd is designed on this page. However, when the values of t1, t2, qs are |1>, |1>, |0>, the return value of CCNOT(t1, t2, qs) is |1>, |1>, |1>, which violate the initial input rule that qs must be |0>, resulting in different outputs among three simulators.

To Reproduce

namespace Project {
    open Microsoft.Quantum.Intrinsic;
    open Microsoft.Quantum.Diagnostics;
    open Microsoft.Quantum.Canon;
    open Microsoft.Quantum.Measurement;
    open Microsoft.Quantum.Math;

    @EntryPoint()
    operation RunProgram() : Unit {
        use t1 = Qubit();
        X(t1);
        use t2 = Qubit();
        X(t2);
        use qs = Qubit();
        Adjoint ApplyAnd(t1, t2, qs);
        DumpMachine();
        ResetAll([t1,t2,qs]);
    }
}

Outputs
The output of QuantumSimulator and SparseSimulator:

|3⟩ 1.000000 + 0.000000 i == ******************** [ 1.000000 ] --- [ 0.00000 rad ]

The output of ToffoliSimulator:

Offset State Data
======== ==========
00000000 111

System information

  • OS: Windows10 & Ubuntu18.04
  • DotNet version : 7.0.100
  • QDK : 0.28.277227