Closed
Description
Describe the bug
Relabel operation doesn't work correctly.
To Reproduce
Run the following code:
operation Main(): Unit {
use q = Qubit[5]; // little-endian 5-bit integer.
X(q[1]); // q:=2.
Relabel(q, q[2..4]+q[0..1]); // Cyclic shift right by 3, q:=q<<3, must get q=16.
Message($"ans={MeasureInteger(q)}"); // prints 4, expected 16.
}
Expected behavior
State of qubits before relabel is [0,1,0,0,0]
. We would expect that after relabel state is [0,0,0,0,1]
. In particular, any use of q[4]
should refer to what was q[1]
. However, the state we get after relabel is [0,0,1,0,0]
.
Screenshots
N/A
System information
- qsharp version 1.11
- QDK version 1.12
- Note: I can also reproduce this in https://microsoft.github.io/qsharp/
Additional context
- I ran into this issue while trying to use Relabel to implement cyclic shift of an integer like this. When I ran tests for it, they failed for some inputs for n>=5 qubits.
- I found a workaround - write my own code to decompose permutation into swaps (aka transpositions), and then use Relabel to apply each swap individually (like this).