-
Notifications
You must be signed in to change notification settings - Fork 984
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
Add a limited FSIM gateset #2804
Conversation
- This will be equivalent to combining the sqrt iswap and syc gatesets. - Combining these two gatesets will have the following advantages: -- This can allow for parameterization of the ISWAP**0 gate -- That allows circuits to drop out iSwaps and batch efficiently -- Also allows for expansion if other FSim variants become available
cirq/google/gate_sets.py
Outdated
MEASUREMENT_DESERIALIZER, | ||
WAIT_GATE_DESERIALIZER, | ||
]) | ||
document(SQRT_ISWAP_GATESET, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FSIM_GATESET
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
cirq/google/common_serializers.py
Outdated
serialized_name='theta', | ||
serialized_type=float, | ||
op_getter=(lambda op: cast(ops.ISwapPowGate, op.gate).exponent * | ||
np.pi / 2)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a minus sign here, because iswap**0.5 corresponds to fsim(-pi/4, 0).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I always screw up this convention.
|
||
@pytest.mark.parametrize(('gate', 'theta', 'phi'), [ | ||
(cirq.ISWAP**0.5, -np.pi / 4, 0), | ||
(cirq.ISWAP**-0.5, np.pi / 4, 0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain to me how does it work, since you didn't specify serializer for ISwapPowGate with exponent equal to -0.5?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The serializer checks for abs(exponent)==0.5 (mod 2pi)
return True | ||
# sqrt ISWAP and inverse sqrt ISWAP | ||
if _near_mod_2pi(abs(theta), np.pi / 4) and _near_mod_2pi(phi, 0): | ||
return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a subtlety here with periodicity and absolute value; we want to accept theta = pi/4 and -pi/4, but also theta = 7pi/4 (which is equal to -pi/4 mod 2pi). The current code will not accept that. I think we should do:
if (_near_mod_2pi(theta, np.pi / 4) or _near_mod_2pi(theta, -np.pi / 4)) and _near_mod_2pi(phi, 0):
...
Could also split these into separate if clauses and label them explicitly as sqrt iswap and inverse sqrt iswap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct! I tried to be too fancy for my own good. I just made all the checks separate and explicit and added tests for the -7pi/4 and 7pi/4
cirq/google/common_serializers.py
Outdated
op_getter=lambda e: 0) | ||
], | ||
can_serialize_predicate=(lambda op: _near_mod_n( | ||
abs(cast(ops.ISwapPowGate, op.gate).exponent), 0.5, 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here, too, need to check whether the exponent is close to 0.5 mod 4 or -0.5 mod 4; taking the absolute value misses exponent 3.5, which gives the same gate as -0.5.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
-- This can allow for parameterization of the ISWAP**0 gate
-- That allows circuits to drop out iSwaps and batch efficiently
-- Also allows for expansion if other FSim variants become available