Skip to content

Commit de6ca2d

Browse files
authored
Better decomposition of SWAP into ISWAP ** 0.5 (#2682)
* Better decomposition of SWAP into ISWAP ** 0.5 - Shortens length from 13 moments to 7 moments. - Decomposition courtesy of @john6060 via @mpharrigan . Fixes #2635
1 parent 575ae93 commit de6ca2d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

cirq/google/optimizers/convert_to_sqrt_iswap.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,21 @@ def swap_to_sqrt_iswap(a, b, turns):
262262
theta: The rotational angle that specifies the gate, where
263263
c = cos(π·t/2), s = sin(π·t/2), g = exp(i·π·t/2).
264264
"""
265+
if not isinstance(turns, sympy.Basic) and _near_mod_n(turns, 1.0, 2):
266+
# Decomposition for cirq.SWAP
267+
yield ops.Y(a)**0.5
268+
yield ops.Y(b)**0.5
269+
yield SQRT_ISWAP(a, b)
270+
yield ops.Y(a)**-0.5
271+
yield ops.Y(b)**-0.5
272+
yield SQRT_ISWAP(a, b)
273+
yield ops.X(a)**-0.5
274+
yield ops.X(b)**-0.5
275+
yield SQRT_ISWAP(a, b)
276+
yield ops.X(a)**0.5
277+
yield ops.X(b)**0.5
278+
return
279+
265280
yield ops.Z(a)**1.25
266281
yield ops.Z(b)**-0.25
267282
yield ops.ISWAP(a, b)**-0.5

cirq/google/optimizers/convert_to_sqrt_iswap_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _unitaries_allclose(circuit1, circuit2):
2222
[
2323
(cast(cirq.Gate, cirq.ISWAP), 7), # cast is for fixing mypy confusion
2424
(cirq.CZ, 8),
25-
(cirq.SWAP, 13),
25+
(cirq.SWAP, 7),
2626
(cirq.CNOT, 9),
2727
(cirq.ISWAP**0.5, 1),
2828
(cirq.ISWAP**-0.5, 1),

0 commit comments

Comments
 (0)