Skip to content
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

Merged
merged 3 commits into from
Mar 5, 2020
Merged

Conversation

dstrain115
Copy link
Collaborator

  • 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

- 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
@googlebot googlebot added the cla: yes Makes googlebot stop complaining. label Mar 4, 2020
MEASUREMENT_DESERIALIZER,
WAIT_GATE_DESERIALIZER,
])
document(SQRT_ISWAP_GATESET,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FSIM_GATESET

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

serialized_name='theta',
serialized_type=float,
op_getter=(lambda op: cast(ops.ISwapPowGate, op.gate).exponent *
np.pi / 2)),
Copy link
Contributor

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).

Copy link
Collaborator Author

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),
Copy link
Collaborator

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?

Copy link
Collaborator Author

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)

@dstrain115 dstrain115 requested a review from maffoo March 4, 2020 20:12
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
Copy link
Contributor

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.

Copy link
Collaborator Author

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

op_getter=lambda e: 0)
],
can_serialize_predicate=(lambda op: _near_mod_n(
abs(cast(ops.ISwapPowGate, op.gate).exponent), 0.5, 4
Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@dstrain115 dstrain115 requested a review from maffoo March 5, 2020 18:09
Copy link
Contributor

@maffoo maffoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dstrain115 dstrain115 merged commit 007f858 into quantumlib:master Mar 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants