Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relabel applies wrong permutation for >=5 qubits #2077

Open
fedimser opened this issue Dec 24, 2024 · 1 comment
Open

Relabel applies wrong permutation for >=5 qubits #2077

fedimser opened this issue Dec 24, 2024 · 1 comment
Labels
bug Something isn't working needs triage

Comments

@fedimser
Copy link

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).
@fedimser fedimser added bug Something isn't working needs triage labels Dec 24, 2024
@sezna
Copy link
Contributor

sezna commented Dec 27, 2024

Proactively pinging @swernli on this one...

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

No branches or pull requests

2 participants