diff --git a/cirq-core/cirq/circuits/quil_output_test.py b/cirq-core/cirq/circuits/quil_output_test.py index d67094f6624..28986768be8 100644 --- a/cirq-core/cirq/circuits/quil_output_test.py +++ b/cirq-core/cirq/circuits/quil_output_test.py @@ -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 @@ -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), diff --git a/cirq-core/cirq/ops/swap_gates.py b/cirq-core/cirq/ops/swap_gates.py index 72b9a1c41ba..5d5fa0174d4 100644 --- a/cirq-core/cirq/ops/swap_gates.py +++ b/cirq-core/cirq/ops/swap_gates.py @@ -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]