Skip to content

Relabel applies wrong permutation for >=5 qubits #2077

Closed
@fedimser

Description

@fedimser

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

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).

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions