Skip to content

Commit

Permalink
Handle inverse for Quil's SWAP gate (#5341)
Browse files Browse the repository at this point in the history
`SWAP` is it's own self inverse. Fixes: #5310
  • Loading branch information
vtomole authored May 10, 2022
1 parent 13de219 commit 4ba730b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cirq-core/cirq/circuits/quil_output_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def test_all_operations():
CPHASE({np.pi / 2}) 0 1
RY({np.pi / 2}) 1
SWAP 0 1
SWAP 1 0
PSWAP({3 * np.pi / 4}) 0 1
H 2
CCNOT 0 1 2
Expand Down Expand Up @@ -324,6 +325,7 @@ def _all_operations(q0, q1, q2, q3, q4, include_measurements=True):
cirq.CNOT(q0, q1),
cirq.CNOT(q0, q1) ** 0.5, # Requires 2-qubit decomposition
cirq.SWAP(q0, q1),
cirq.SWAP(q1, q0) ** -1,
cirq.SWAP(q0, q1) ** 0.75, # Requires 2-qubit decomposition
cirq.CCZ(q0, q1, q2),
cirq.CCX(q0, q1, q2),
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/ops/swap_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _qasm_(self, args: 'cirq.QasmArgs', qubits: Tuple['cirq.Qid', ...]) -> Optio
def _quil_(
self, qubits: Tuple['cirq.Qid', ...], formatter: 'cirq.QuilFormatter'
) -> Optional[str]:
if self._exponent == 1:
if self._exponent % 2 == 1:
return formatter.format('SWAP {0} {1}\n', qubits[0], qubits[1])
return formatter.format(
'PSWAP({0}) {1} {2}\n', self._exponent * np.pi, qubits[0], qubits[1]
Expand Down

0 comments on commit 4ba730b

Please sign in to comment.