Skip to content

Commit

Permalink
Add ISWAP and its inverse to FSIM_GATESET (#3743)
Browse files Browse the repository at this point in the history
- Adding ISWAP to FSIM_GATESET as an allowed gate
for experimental usage.

This allows serialization of ISWAP and ISWAP ** -1 using
this gateset.  Note that this gate may not be available on
all processors and may not have good/any performance.
  • Loading branch information
dstrain115 committed Feb 10, 2021
1 parent 387ad42 commit 2aa20b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 14 additions & 2 deletions cirq/google/common_serializers.py
Expand Up @@ -486,8 +486,8 @@ def _convert_physical_z(op: ops.Operation, proto: v2.program_pb2.Operation):

#
# FSim serializer
# Only allows sqrt_iswap, its inverse, identity, and sycamore
#
# Only allows iswap, sqrt_iswap and their inverses, iswap, CZ, identity, and sycamore
# Note that not all combinations may not be available on all processors
def _can_serialize_limited_fsim(theta: float, phi: float):
# Symbols for LIMITED_FSIM are allowed, but may fail server-side
# if an incorrect run context is specified
Expand All @@ -503,6 +503,12 @@ def _can_serialize_limited_fsim(theta: float, phi: float):
# inverse sqrt ISWAP
if _near_mod_2pi(theta, np.pi / 4):
return True
# ISWAP
if _near_mod_2pi(theta, -np.pi / 2):
return True
# Inverse ISWAP
if _near_mod_2pi(theta, np.pi / 2):
return True
# Sycamore
if (
(_near_mod_2pi(theta, np.pi / 2) or isinstance(theta, sympy.Symbol))
Expand Down Expand Up @@ -531,6 +537,12 @@ def _can_serialize_limited_iswap(exponent: float):
# Inverse Sqrt ISWAP
if _near_mod_n(exponent, -0.5, 4):
return True
# ISWAP
if _near_mod_n(exponent, -1.0, 4):
return True
# Inverse ISWAP
if _near_mod_n(exponent, 1.0, 4):
return True
# Identity
if _near_mod_n(exponent, 0.0, 4):
return True
Expand Down
6 changes: 5 additions & 1 deletion cirq/google/common_serializers_test.py
Expand Up @@ -501,6 +501,8 @@ def test_wait_gate_multi_qubit():
[
(cirq.ISWAP ** 0.5, -np.pi / 4, 0),
(cirq.ISWAP ** -0.5, np.pi / 4, 0),
(cirq.ISWAP ** 1.0, -np.pi / 2, 0),
(cirq.ISWAP ** -1.0, np.pi / 2, 0),
(cirq.ISWAP ** 0.0, 0, 0),
(cirq.CZ, 0, np.pi),
(cirq.CZ ** -1.0, 0, np.pi),
Expand All @@ -509,6 +511,8 @@ def test_wait_gate_multi_qubit():
(cirq.FSimGate(theta=np.pi / 4, phi=0), np.pi / 4, 0),
(cirq.FSimGate(theta=7 * np.pi / 4, phi=0), -np.pi / 4, 0),
(cirq.FSimGate(theta=-np.pi / 4, phi=0), -np.pi / 4, 0),
(cirq.FSimGate(theta=np.pi / 2, phi=0), np.pi / 2, 0),
(cirq.FSimGate(theta=-np.pi / 2, phi=0), -np.pi / 2, 0),
(cirq.FSimGate(theta=-7 * np.pi / 4, phi=0), np.pi / 4, 0),
(cirq.google.SYC, np.pi / 2, np.pi / 6),
(cirq.FSimGate(theta=np.pi / 2, phi=np.pi / 6), np.pi / 2, np.pi / 6),
Expand Down Expand Up @@ -596,7 +600,7 @@ def test_serialize_deserialize_iswap_symbols():
'gate',
[
cirq.ISWAP ** 0.25,
cirq.ISWAP,
cirq.ISWAP ** 0.75,
cirq.FSimGate(theta=0.1, phi=0),
cirq.FSimGate(theta=0, phi=0.1),
cirq.FSimGate(theta=sympy.Symbol('t'), phi=0.1),
Expand Down

0 comments on commit 2aa20b3

Please sign in to comment.