-
Notifications
You must be signed in to change notification settings - Fork 51
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
Optimize gate count of Subtract to n-1 Toffolis #1057
Conversation
would be useful to include in the description |
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.
docstring!
@NoureldinYosri can you make the requested changes |
@mpharrigan done, I was getting test failures when doing the classical simulation test because classical simulation tools couldn't handle negative values and both Add and Subtract bloqs had faulty classical action definitions for the case of signed inputs... I fixed all of these issues |
@mpharrigan ptal |
hN = N >> 1 | ||
return {'a': a, 'b': int(a + b + hN) % N - hN} |
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.
h is half? can you provide a line comment explaining the logic here and consider using a more meaningful name than hN
. Was the previous behavior using math.fmod
wrong? can you add a test that would have failed with the old logic?
|
||
This construction uses `XGate` and `AddK` to compute the twos-compliment of `b` before | ||
doing a standard `Add`. | ||
This construction uses the relation `a - b = ~(~a + b)` to turn the operation into addition. |
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.
are there any quantum references where this construction is used?
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.
@tanujkhattar you mentioned that this trick is used in some phase gradient papers, right?
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.
What happens if a_bitsize is equal to b_bitsize? This is a good example of a bloq that should support symbolic decomposition; at least for sizeof(a) == sizeof(b) |
@NoureldinYosri do take a look at #1161 and #1162, they would help simplify this decomposition |
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.
can you address @anurudhp 's comment and maybe open an issue to track
will do when the other PR is merged |
This uses the bit-magic
a-b = ~(~a + b)