Skip to content

Commit

Permalink
Better decomposition of SWAP into ISWAP ** 0.5 (#2682)
Browse files Browse the repository at this point in the history
* Better decomposition of SWAP into ISWAP ** 0.5

- Shortens length from 13 moments to 7 moments.
- Decomposition courtesy of @john6060 via @mpharrigan .

Fixes #2635
  • Loading branch information
dstrain115 committed Jan 16, 2020
1 parent 575ae93 commit de6ca2d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions cirq/google/optimizers/convert_to_sqrt_iswap.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,21 @@ def swap_to_sqrt_iswap(a, b, turns):
theta: The rotational angle that specifies the gate, where
c = cos(π·t/2), s = sin(π·t/2), g = exp(i·π·t/2).
"""
if not isinstance(turns, sympy.Basic) and _near_mod_n(turns, 1.0, 2):
# Decomposition for cirq.SWAP
yield ops.Y(a)**0.5
yield ops.Y(b)**0.5
yield SQRT_ISWAP(a, b)
yield ops.Y(a)**-0.5
yield ops.Y(b)**-0.5
yield SQRT_ISWAP(a, b)
yield ops.X(a)**-0.5
yield ops.X(b)**-0.5
yield SQRT_ISWAP(a, b)
yield ops.X(a)**0.5
yield ops.X(b)**0.5
return

yield ops.Z(a)**1.25
yield ops.Z(b)**-0.25
yield ops.ISWAP(a, b)**-0.5
Expand Down
2 changes: 1 addition & 1 deletion cirq/google/optimizers/convert_to_sqrt_iswap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _unitaries_allclose(circuit1, circuit2):
[
(cast(cirq.Gate, cirq.ISWAP), 7), # cast is for fixing mypy confusion
(cirq.CZ, 8),
(cirq.SWAP, 13),
(cirq.SWAP, 7),
(cirq.CNOT, 9),
(cirq.ISWAP**0.5, 1),
(cirq.ISWAP**-0.5, 1),
Expand Down

0 comments on commit de6ca2d

Please sign in to comment.