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

Unexpected conversion to Quil of inverse SWAP gate #5310

Closed
andreamari opened this issue Apr 29, 2022 · 1 comment · Fixed by #5341
Closed

Unexpected conversion to Quil of inverse SWAP gate #5310

andreamari opened this issue Apr 29, 2022 · 1 comment · Fixed by #5341
Labels
area/quil kind/bug-report Something doesn't seem to work. triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on

Comments

@andreamari
Copy link

Description of the issue

When converting the inverse of a SWAP gate to Quil the result seems wrong.

How to reproduce the issue

from cirq import Circuit, LineQubit, SWAP
from pyquil import Program
from pyquil.simulation.tools import program_unitary


cirq_circuit = cirq.inverse(Circuit(cirq.SWAP(*qreg)))
print("Cirq circuit:")
print(cirq_circuit)
print("Cirq unitary:\n", cirq_circuit.unitary())


quil_circuit = Program(inverse_swap_circuit.to_quil())
print("PyQuil circuit:")
print(quil_circuit)
print("PyQuil unitary:\n", np.round(program_unitary(quil_circuit, 2), 2))

Gives:

Cirq circuit:
0: ───×───
      │
1: ───×───
Cirq unitary:
 [[1.+0.j 0.+0.j 0.+0.j 0.+0.j]
 [0.+0.j 0.+0.j 1.+0.j 0.+0.j]
 [0.+0.j 1.+0.j 0.+0.j 0.+0.j]
 [0.+0.j 0.+0.j 0.+0.j 1.+0.j]]
PyQuil circuit:
PSWAP(-pi) 0 1

PyQuil unitary:
 [[ 1.+0.j  0.+0.j  0.+0.j  0.+0.j]
 [ 0.+0.j  0.+0.j -1.-0.j  0.+0.j]
 [ 0.+0.j -1.-0.j  0.+0.j  0.+0.j]
 [ 0.+0.j  0.+0.j  0.+0.j  1.+0.j]]

Cirq version

0.14.1
@andreamari andreamari added the kind/bug-report Something doesn't seem to work. label Apr 29, 2022
@verult verult added triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on area/quil labels Apr 29, 2022
CirqBot pushed a commit that referenced this issue May 10, 2022
`SWAP` is it's own self inverse. Fixes: #5310
@andreamari
Copy link
Author

Thanks @vtomole!

rht pushed a commit to rht/Cirq that referenced this issue May 1, 2023
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this issue Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/quil kind/bug-report Something doesn't seem to work. triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants