-
Notifications
You must be signed in to change notification settings - Fork 986
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
Make cirq.FREDKIN
gate self-inverse
#6135
Merged
tanujkhattar
merged 4 commits into
quantumlib:master
from
tanujkhattar:fredkin_self_inverse
Jun 11, 2023
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d067135
Make FREDKIN gate self-inverse
tanujkhattar ca04ea6
Fix formatting
tanujkhattar 9b41dea
Merge branch 'master' of https://github.com/quantumlib/cirq into fred…
tanujkhattar 086679f
Simplify test to check CSWAP matrix is self inverse
tanujkhattar File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't think we need the call to
map_eigevalues
:Mathematical reason is that the eigenvalues of FREDKIN are all$\pm 1$ , so $\lambda=\lambda^{-1}$ . Pythonic reason is that AFAICT we should have equality
cirq.FREDKIN**-1 == cirq.FREDKIN
, before we even callcirq.unitary
. Perhaps that is a better (or additional) thing to assert (though perhaps not insidetest_unitary
, not sure what a better suited test is). Any potential extra assert is up to you.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.
Yeah, I agree we should add a
assert cirq.FREDKIN ** -1 == cirq.FREDKIN
. The reason I used this approach for the test here is to assert that the unitary matrix itself is self inverse, and not the object. Self inverse nature of the unitary matrix can be figured out using the math, but here the goal was to test that math.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 simplest way to do this is
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.
Simplified the test for self-inverse as recommended. Also, note that
assert cirq.FREDKIN ** -1 == cirq.FREDKIN
is already covered in my original PR under the equality testeq.add_equality_group(cirq.CSWAP(a, b, c), cirq.FREDKIN(a, b, c), cirq.FREDKIN(a, b, c) ** -1)
. Merging now.