Skip to content

Commit

Permalink
Add CZ to combined FSim gate set (#2875)
Browse files Browse the repository at this point in the history
* Add CZ to combined FSim gate set
  • Loading branch information
dstrain115 committed Mar 30, 2020
1 parent 3659c7f commit 4521a9b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cirq/google/common_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@ def _can_serialize_limited_fsim(theta: float, phi: float):
if ((_near_mod_2pi(theta, np.pi / 2) or isinstance(theta, sympy.Symbol)) and
(_near_mod_2pi(phi, np.pi / 6)) or isinstance(phi, sympy.Symbol)):
return True
# CZ
if ((_near_mod_2pi(theta, 0) or isinstance(theta, sympy.Symbol)) and
(_near_mod_2pi(phi, np.pi)) or isinstance(phi, sympy.Symbol)):
return True
return False


Expand Down Expand Up @@ -507,8 +511,22 @@ def _can_serialize_limited_iswap(exponent: float):
],
can_serialize_predicate=(lambda op: _can_serialize_limited_iswap(
cast(ops.ISwapPowGate, op.gate).exponent))),
op_serializer.GateOpSerializer(
gate_type=ops.CZPowGate,
serialized_gate_id='fsim',
args=[
op_serializer.SerializingArg(serialized_name='theta',
serialized_type=float,
op_getter=lambda e: 0),
op_serializer.SerializingArg(serialized_name='phi',
serialized_type=float,
op_getter=lambda e: np.pi)
],
can_serialize_predicate=lambda op: _near_mod_2(
cast(ops.CZPowGate, op.gate).exponent, 1.0))
]


LIMITED_FSIM_DESERIALIZER = op_deserializer.GateOpDeserializer(
serialized_gate_id='fsim',
gate_constructor=ops.FSimGate,
Expand Down
3 changes: 3 additions & 0 deletions cirq/google/common_serializers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,10 @@ def test_wait_gate():
(cirq.ISWAP**0.5, -np.pi / 4, 0),
(cirq.ISWAP**-0.5, np.pi / 4, 0),
(cirq.ISWAP**0.0, 0, 0),
(cirq.CZ, 0, np.pi),
(cirq.CZ**-1.0, 0, np.pi),
(cirq.FSimGate(theta=0, phi=0), 0, 0),
(cirq.FSimGate(theta=0, phi=np.pi), 0, np.pi),
(cirq.FSimGate(theta=np.pi / 4, phi=0), np.pi / 4, 0),
(cirq.FSimGate(theta=7 * np.pi / 4, phi=0), 7 * np.pi / 4, 0),
(cirq.FSimGate(theta=-np.pi / 4, phi=0), -np.pi / 4, 0),
Expand Down

0 comments on commit 4521a9b

Please sign in to comment.