qsharp-runtime
qsharp-runtime copied to clipboard
Inconsistent output for QuantumSimulator vs SparseSimulator
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)
but this output on SparseSimulator (basis state |1⟩ has zero amplitude)
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
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.
Should be fixed after https://github.com/microsoft/qsharp-runtime/pull/1092