Add SubtractFrom to subtract from a register in place#1158
Merged
charlesyuan314 merged 8 commits intoquantumlib:mainfrom Jul 19, 2024
Merged
Add SubtractFrom to subtract from a register in place#1158charlesyuan314 merged 8 commits intoquantumlib:mainfrom
SubtractFrom to subtract from a register in place#1158charlesyuan314 merged 8 commits intoquantumlib:mainfrom
Conversation
mpharrigan
reviewed
Jul 18, 2024
| def build_composite_bloq(self, bb: 'BloqBuilder', a: Soquet, b: Soquet) -> Dict[str, 'SoquetT']: | ||
| neg = Negate(self.dtype) | ||
| b = bb.add(neg, x=b) # a, -b | ||
| b, a = bb.add_t(Add(self.dtype_as_unsigned, self.dtype_as_unsigned), a=b, b=a) # a - b, -b |
Collaborator
There was a problem hiding this comment.
you can still use bb.add() in these cases
Contributor
Author
There was a problem hiding this comment.
Yes. My IDE type checker (Pylance) prefers that I use add_t though for the slightly finer grained information.
Collaborator
|
Makes sense to me. @tanujkhattar do you have any qualms with this approach? also cc @NoureldinYosri for your inventory of arithmetic bloqs |
anurudhp
reviewed
Jul 19, 2024
Co-authored-by: Anurudh Peduri <7265746+anurudhp@users.noreply.github.com>
anurudhp
approved these changes
Jul 19, 2024
Contributor
|
this could have been just an extra flag to |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add a new version of$|a\rangle|b\rangle \mapsto |a\rangle|a-b\rangle$ , takes it to $|a\rangle|b-a\rangle$ . This is essentially equivalent to the statement
Subtractthat instead of takingb -= a.The implementation uses an additional
Negate, which could likely be improved, but this is a first approach. For now, it only supportsaandbregister of equal dtype.The reason we need this for
Subtractbut not forAddis because addition is commutative and we could always swap the operands, but we can't for subtraction.