-
Notifications
You must be signed in to change notification settings - Fork 1
Support measuring registers in pyqrack #174
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
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
|
Is there any type checking concern @Roger-luo with making instructions polymorphic like 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.
@cduck yes, the type hinting here is not correct. I've commented with a fix above below.
| qarg: ir.SSAValue = info.argument(QubitType | QRegType) | ||
| """qarg (Qubit): The qubit to measure.""" | ||
| carg: ir.SSAValue = info.argument(BitType) | ||
| carg: ir.SSAValue = info.argument(BitType | CRegType) |
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 need to add a def check_type(self) method to validate the type here because here your definition allows QubitType appear with CRegType.
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 added the type check test. FWIW, mixing the types would have already triggered a RuntimeError in the impl.
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 would be better to have the error at compile time compared to run time since in some cases you might not run the function with the simulator for awhile if at all.
src/bloqade/qasm2/_wrappers.py
Outdated
|
|
||
| @wraps(core.Measure) | ||
| def measure(qarg: Qubit, cbit: Bit) -> None: | ||
| def measure(qarg: Qubit | QReg, cbit: Bit | CReg) -> None: |
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.
so you can fix the type hinting by adding the following separately
from typing import overload
@overload
def measure(qarg: Qubit, cbit: Bit) -> None: ...
@overload
def measure(qarg: QReg, cbit: CReg) -> None: ...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.
@Roger-luo I had already done that following your message on slack. I just forgot to push the commit yesterday 😅
|
@Roger-luo CI now fails because I added a test for the |
weinbe58
left a comment
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 once the CI is fixed
| traits = frozenset({lowering.FromPythonCall()}) | ||
| qarg: ir.SSAValue = info.argument(QubitType) | ||
| qarg: ir.SSAValue = info.argument(QubitType | QRegType) | ||
| """qarg (Qubit): The qubit to measure.""" |
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.
Don't forget an out the doc strings!
|
right I didn't realize that was actually breaking. I'm cleaning this up in QuEraComputing/kirin#376 so it throws and validation error. We don't have a good way to raise a native exception while hiding python stacktrace at the moment because we we implementing this as custom error handler. |
|
I figured out a way to raise the exact error that you raise inside the interpreter - it might a bit evil but I think this is cleaner on user side. stay tuned for a new kirin release. |
|
but I think we should merge this PR given this is due to 0.16.8 actually breaking the convention a bit here. Can you fix the test based on QuEraComputing/kirin#376 first so we can merge this PR but we can cleanup the exception type a bit later? |
|
Mark the test as xfail |
|

Fixes #160