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

Handle inverse for Quil's SWAP gate #5341

Merged
merged 3 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 == 1 or self._exponent == -1:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is _exponent restricted in any way? If not, I think this should be any odd power. i.e. if self._exponent % 2 == 1:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it's restricted but your suggestion makes this more robust so i did it anyway.

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