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

Inconsistent output for QuantumSimulator vs SparseSimulator #1081

Closed
tcNickolas opened this issue Aug 27, 2022 · 3 comments
Closed

Inconsistent output for QuantumSimulator vs SparseSimulator #1081

tcNickolas opened this issue Aug 27, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@tcNickolas
Copy link
Member

tcNickolas commented Aug 27, 2022

Describe the bug

The same code produces different output when executed on QuantumSimulator vs SparseSimulator.
It appears that the basis states are labeled in little endian for QuantumSimulator, but for SparseSimulator they are sometimes labeled in big endian.

To Reproduce

The following code:

use qs = Qubit[2] {
    H(qs[0]);
    Controlled Rx([qs[0]], (1.56, qs[1]));
    DumpMachine();
    ResetAll(qs);
}

produces this output on QuantumSimualtor (basis state |2⟩ has zero amplitude)

image

but this output on SparseSimulator (basis state |1⟩ has zero amplitude)

image

Oddly enough, for simpler examples (such as just applying an H gate to the first qubit without following it with Controlled Ry) the output of both simulators is the same.

Expected behavior

I expect both simulators to have consistent output (up to omitting basis states with zero amplitude).

System information

  • OS: Windows 11
  • .NET Core Version: 6.0.400
  • QDK version: 0.24.201332, 0.25.222597
@tcNickolas tcNickolas added bug Something isn't working needs triage An initial review by a maintainer is needed labels Aug 27, 2022
@bettinaheim bettinaheim removed the needs triage An initial review by a maintainer is needed label Sep 7, 2022
@DmitryVasilevsky
Copy link
Contributor

Current numbering of qubits in the sparse simulator depends on the size of the state seen. For example, the following code

use qs = Qubit[10] {
    H(qs[0]);
    Message("Before:");
    DumpMachine();

    H(qs[8]);
    H(qs[8]);
    Message("After:");
    DumpMachine();

    ResetAll(qs);
}

Will result in the following output:

Before:
|0⟩      0.707107 +  0.000000 i  ==     **********           [ 0.500000 ]     --- [  0.00000 rad ]
|1⟩      0.707107 +  0.000000 i  ==     **********           [ 0.500000 ]     --- [  0.00000 rad ]
After:
|0⟩      0.707107 +  0.000000 i  ==     **********           [ 0.500000 ]     --- [  0.00000 rad ]
|256⟩    0.707107 +  0.000000 i  ==     **********           [ 0.500000 ]     --- [  0.00000 rad ]

I believe we want both sections to be the same. Investigating.

@DmitryVasilevsky
Copy link
Contributor

Should be fixed after #1092

@weucode
Copy link

weucode commented Apr 22, 2023

Here is another simple example illustrating the different behavior between QuantumSimulator and SparseSimulator. By the way, if using DumpRegister to show states of qubits, the result is right, which means that this behavior only occurred when outputs states of all qubits. Hope this example is helpful!

namespace NameSpace {
    open Microsoft.Quantum.Diagnostics;
    open Microsoft.Quantum.Intrinsic;


    @EntryPoint()
    operation main() : Unit {
        use qubits = Qubit[2];
        H(qubits[1]);
        DumpMachine();
        // DumpRegister((), qubits);
        ResetAll(qubits);        
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants