Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

ToffoliSimulator outputs different result when executing Adjoint ApplyAnd #677

Open
@weucode

Description

@weucode

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Kind-BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions