-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix: Allow subtraction of IdentityGate in PauliSum.__sub__ #7276
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
Open
RevanthGundala
wants to merge
9
commits into
quantumlib:main
Choose a base branch
from
RevanthGundala:fix-paulisum-identity-bug
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1da85cf
Fix: Allow subtraction of IdentityGate in PauliSum.__sub__
RevanthGundala 6b9ec8b
Manually resolve conflict and complete cherry-pick
RevanthGundala 7bae7dd
Add comprehensive tests for Pauli operator addition and subtraction, …
RevanthGundala 7df8392
Fixed linting erorrs
RevanthGundala e5e39ba
Updated lint + added issue number
RevanthGundala e860d08
fixed lints
RevanthGundala 5a1e6bc
Merge branch 'main' into fix-paulisum-identity-bug
RevanthGundala f9dee54
Added new line
RevanthGundala 603e696
Merge remote-tracking branch 'refs/remotes/origin/fix-paulisum-identi…
RevanthGundala 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
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
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 think
I+I
andI-I
will still fail here, for reasons described in the linked issue thread. If so, probably have to add a conditional check here to skip those cases.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.
Huh. Surprisingly
I+I
passes now even though it didn't in the linked issue and this PR didn't change__add__
. Any idea what changed?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.
My test wraps all gates in PauliString, so operations like PauliString(I(q)) + PauliString(I(q)) are handled correctly and the test passes. If you use raw I(q) + I(q) (without PauliString), it will fail, but that's not the intent of this test.
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.
Oh I see. But wouldn't those all also pass prior to your change? IIUC the change fixes unwrapped paulis by implicitly wrapping them during subtraction. So IIUC this test where they're explicitly being wrapped beforehand wouldn't actually test the fix. Am I missing something?
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.
No you were right. Those tests didn't test anything new. Just added new tests that should cover the changes. Let me know if that looks good.
In terms of the I+I, it's still not passing on my end.
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+I
being out of scope was discussed in the linked issue. It might not be that hard to create anIdentityGate.__add__/__sub__
that replacesself
with an empty PauliString first (or maybeDensePauliString
since it's a gate?). Now that I think of it, that approach might even remove the need for these instance checks inPauliSum.__add__/__sub__
? Or it may not work at all and/or break some other tests. Haven't tried.If you want to give that a shot and see if it works, go ahead. Otherwise, this looks good, just open up a separate issue to track the
I+I
case and mention the issue number in your unit test's comment about bypassing theI+I
case.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.
FYI,
check/format-incremental( --apply)
,check/pylint-changed-files
,check/pytest(-changed-files)
,check/mypy
,check/all
from the command line are useful for avoiding having to wait for CI just to find silly mistakes. https://github.com/quantumlib/Cirq/tree/main/checkThere 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.
Sounds good, thanks! Updated the new issue to #7280