-
Notifications
You must be signed in to change notification settings - Fork 82
Add SubtractFrom to subtract from a register in place
#1158
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
Conversation
| 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 |
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.
you can still use bb.add() in these 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.
Yes. My IDE type checker (Pylance) prefers that I use add_t though for the slightly finer grained information.
|
Makes sense to me. @tanujkhattar do you have any qualms with this approach? also cc @NoureldinYosri for your inventory of arithmetic bloqs |
Co-authored-by: Anurudh Peduri <[email protected]>
|
this could have been just an extra flag to |
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.