-
Notifications
You must be signed in to change notification settings - Fork 107
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
Lint rule: When qubit reuse is not supported, prefer MResetZ
over M
#1473
Comments
Good questions - this originally came from @swernli so I'll let him weigh in. |
HI @Manvi-Agrawal, I definitely have thoughts on these questions.
Yes, definitely.
These two are a little special... they support passing an array of qubits but will return a single measurement result, effectively doing a parity measurement that may only partially collapse the state of the qubits in the array. Given that, these are fine when they have multiple inputs but when the input is an array with a single qubit they would be better replaced. I'm not sure how easy it is to differentiate that in lints (array sizes are not known at compile time) so it might be better left for a follow up refinement.
That is mentioned in the remarks section of the docs on that API, though it could be more prominently featured in the summary. To have a non-resetting version you could use something like |
@minestarks , I would like to work on this issue. |
@swernli do we have any precedence for looking up the |
Ah, that's a good point. We avoided that in the past in part because a compilation may not us the stdlib at all, so it's not guaranteed to be there. I think to get the right resolutions identified we could cheat a bit and have a bit of code that as a prerequisite compiles just the expression |
We should add a rule to the linter that suggests that calls to
M
are replaced byMResetZ
when the currently selected target's capabilities don't includeQubitReuse
.Playground link
In this code, the linter could display a warning under
M
to the effect of "the currently chosen target does not support qubit use after measurement, prefer MResetZ".CONTRIBUTORS PLEASE READ
Getting started
Welcome! Please take a look through our README to orient yourself in the repo and find instructions on how to build.
For this issue you'll want to have a working knowledge of Rust and compilers.
For documentation on how to add lints, see:
https://github.com/microsoft/qsharp/blob/main/compiler/qsc_linter/src/lib.rs
For examples of existing lints, see:
qsharp/compiler/qsc_linter/src/lints/ast.rs
Lines 10 to 12 in ed2a8fc
qsharp/compiler/qsc_linter/src/lints/hir.rs
Line 8 in ed2a8fc
Testing
You can demonstrate that the lint works by running the playground locally (see the code example in the issue description).
Please add unit tests verifying the functionality you implemented.
Before you submit a pull request please run
python ./build.py
to ensure the project builds cleanly. See README for details.Reviews
Once you have published your PR, the codeowners will automatically get tagged and we'll review shortly.
If you need clarification on an issue please tag @minestarks with your questions.
The text was updated successfully, but these errors were encountered: