-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Support even powers of SWAP gate in CliffordSimulator #3661
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
baa9bf8
Support even powers of SWAP gate
smitsanghavi fe46b03
Add test for has_stabilizer_effect
smitsanghavi f1d2294
Address comments
smitsanghavi cbf6b6b
Add not
smitsanghavi f16d6c4
Merge branch 'master' into swap2
smitsanghavi ef5621b
Merge branch 'master' into swap2
CirqBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,16 +85,32 @@ def _trace_distance_bound_(self) -> Optional[float]: | |
return None | ||
return abs(np.sin(self._exponent * 0.5 * np.pi)) | ||
|
||
def _has_stabilizer_effect_(self) -> Optional[bool]: | ||
if self._is_parameterized_(): | ||
return None | ||
return self.exponent % 1 == 0 | ||
|
||
def _act_on_(self, args): | ||
from cirq import ops, sim, protocols | ||
|
||
if isinstance(args, sim.ActOnStabilizerCHFormArgs) and self._exponent % 2 == 1: | ||
args.state.omega *= 1j ** (2 * self.global_shift * self._exponent) | ||
protocols.act_on(ops.CNOT, args) | ||
args.axes = args.axes[::-1] | ||
protocols.act_on(ops.CNOT, args) | ||
args.axes = args.axes[::-1] | ||
protocols.act_on(ops.CNOT, args) | ||
if isinstance(args, (sim.ActOnStabilizerCHFormArgs, sim.ActOnCliffordTableauArgs)): | ||
if not protocols.has_stabilizer_effect(self): | ||
return NotImplemented | ||
if isinstance(args, sim.ActOnStabilizerCHFormArgs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're already in a block that has done this check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be ActOnCliffordTableauArgs |
||
args.state.omega *= 1j ** (2 * self.global_shift * self._exponent) | ||
|
||
if self._exponent % 2 == 1: | ||
protocols.act_on(ops.CNOT, args) | ||
args.axes = args.axes[::-1] | ||
protocols.act_on(ops.CNOT, args) | ||
args.axes = args.axes[::-1] | ||
protocols.act_on(ops.CNOT, args) | ||
else: | ||
# Any fractional exponent SWAP gate should have been rejected | ||
# already. Any even exponent does not change anything except | ||
# the global phase above. | ||
assert self._exponent % 2 == 0 | ||
smitsanghavi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return True | ||
|
||
return NotImplemented | ||
|
This file contains hidden or 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 hidden or 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
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.
Specialize this instead of going through the general method.
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.
When you say specialize, do you mean to call the private method instead of protocol or inlining as you mentioned in the below comment?