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

Document matrices for parity gates #3199

Merged
merged 3 commits into from
Aug 10, 2020

Conversation

viathor
Copy link
Collaborator

@viathor viathor commented Aug 10, 2020

Fixes #2806.

This is covered by tests, but I ran these checks to be sure:

In [1]: import cirq, numpy as np

In [2]: def mxx(t): 
   ...:     f = np.e**(1j*np.pi*t/2) 
   ...:     c = f * np.cos(np.pi*t/2) 
   ...:     s = -1j * f * np.sin(np.pi*t/2) 
   ...:     return np.array([[c, 0, 0, s], [0, c, s, 0], [0, s, c, 0], [s, 0, 0, c]]) 
   ...:     

In [3]: def myy(t): 
   ...:     f = np.e**(1j*np.pi*t/2) 
   ...:     c = f * np.cos(np.pi*t/2) 
   ...:     s = -1j * f * np.sin(np.pi*t/2) 
   ...:     return np.array([[c, 0, 0, -s], [0, c, s, 0], [0, s, c, 0], [-s, 0, 0, c]]) 
   ...:     

In [4]: np.allclose(cirq.unitary(cirq.XX**0.1), mxx(0.1))
Out[4]: True

In [5]: np.allclose(cirq.unitary(cirq.YY**0.1), myy(0.1))
Out[5]: True

NB: Global phase factors complicate documentation. I think we should prefer SU(n) gates (over trying to force one eigenvalue onto the real axis).

@googlebot googlebot added the cla: yes Makes googlebot stop complaining. label Aug 10, 2020
Copy link
Contributor

@balopat balopat left a comment

Choose a reason for hiding this comment

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

LGTM, I'm going to fix #3200 for the CI breakage

@balopat balopat added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Aug 10, 2020
@CirqBot
Copy link
Collaborator

CirqBot commented Aug 10, 2020

Automerge cancelled: A status check is failing.

@CirqBot CirqBot removed the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Aug 10, 2020
@balopat balopat added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Aug 10, 2020
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Aug 10, 2020
@CirqBot CirqBot merged commit 3c7fc5d into quantumlib:master Aug 10, 2020
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Aug 10, 2020
@viathor viathor deleted the matrices-for-parity-gates branch August 10, 2020 18:58
tonybruguier pushed a commit to tonybruguier/Cirq that referenced this pull request Aug 23, 2020
Fixes quantumlib#2806.

This is covered by tests, but I ran these checks to be sure:

```
In [1]: import cirq, numpy as np

In [2]: def mxx(t): 
   ...:     f = np.e**(1j*np.pi*t/2) 
   ...:     c = f * np.cos(np.pi*t/2) 
   ...:     s = -1j * f * np.sin(np.pi*t/2) 
   ...:     return np.array([[c, 0, 0, s], [0, c, s, 0], [0, s, c, 0], [s, 0, 0, c]]) 
   ...:     

In [3]: def myy(t): 
   ...:     f = np.e**(1j*np.pi*t/2) 
   ...:     c = f * np.cos(np.pi*t/2) 
   ...:     s = -1j * f * np.sin(np.pi*t/2) 
   ...:     return np.array([[c, 0, 0, -s], [0, c, s, 0], [0, s, c, 0], [-s, 0, 0, c]]) 
   ...:     

In [4]: np.allclose(cirq.unitary(cirq.XX**0.1), mxx(0.1))
Out[4]: True

In [5]: np.allclose(cirq.unitary(cirq.YY**0.1), myy(0.1))
Out[5]: True
```

NB: Global phase factors complicate documentation. I think we should prefer SU(n) gates (over trying to force one eigenvalue onto the real axis).
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.

Add matrix documentation for class YYPowGate
5 participants