-
Notifications
You must be signed in to change notification settings - Fork 72
Implement Negate
(two's complement)
#1144
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
# TODO use QInt once classical sim is fixed. | ||
# classical sim currently only supports unsigned. |
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.
Is this true? I thought classical simulation supports both signed and unsigned integers. Is there an open issue you are referring to?
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.
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.
Thanks, looks like it's bottlenecked by speed and #1142 should help fix it?
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.
Looking good. Question about classical sim currently only supportin unsigned types - is this true?
x: Any signed value stored in two's complement form. | ||
""" | ||
|
||
dtype: QDType |
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.
Should we assert that dtype
is a signed type ? So QInt
or QFxp(signed=True)
?
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.
It actually works for unsigned types as well, it's the unary minus operator in c++. Perhaps we can use the c++ naming convention?
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.
Thanks, we should at least have a link explaining the behavior for unsigned types in the docstring. I don't have strong opinions on naming convention.
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.
updated docstring to explain this
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.
will leave the Bloq as Negate
for now
|
||
|
||
@frozen | ||
class Negate(Bloq): |
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 it's also worth adding a Not(Bloq)
in arithmetic/bitwise.py
which simply computes the bitwise NOT via OnEach(self.dtype.num_qubits, XGate())
and is a natural choice for unsigned types
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.
yep this is useful! will add in a follow-up PR and cleanup this decomp then.
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.
LGTM. Please consider adding a bitwise Not
Bloq for OnEach(XGate(), self.bitsize)
to arithmetic/bitwise.py
. This can be done in a follow up PR so we can merge this.
No description provided.