This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add new MeasureIfAllZeros operation. #204
base: main
Are you sure you want to change the base?
Add new MeasureIfAllZeros operation. #204
Changes from 1 commit
ce387a4
8f34d28
44eb14f
91df3c9
a5d39eb
3c2f3e4
f7e4b10
af847b2
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
This behavior differs from that of
MeasureInteger
- any specific reason why? It seems more neat to be able to write "return MeasureIfAllZeros(register)" than to measure into a variable, then call ResetAll, then return that variable.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.
My intent was to match the semantics of other operations in the Microsoft.Quantum.Measurement namespace; the operations in Microsoft.Quantum.Arithmetic don't follow the same convention (they should be reconciled, but that's a slightly separate discussion).
For the usecase of returning after, I could imagine something like
ResetAfter<'T>(op : (Qubit[] => 'T), target : Qubit[]) : 'T { let returnValue = op(target); ResetAll(target); return returnValue; }
such that you could doreturn ResetAfter(MeasureIfAllZeros(register));
. That would be less efficient in terms of the number of measurements thanreturn All(ForEach(MResetZ, target))
, though.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.
In the last code snippet, did you mean something like
All(IsResultZero, ForEach(MResetZ, target))
?From the end user point of view, it might be still more convenient to stick with MeasureInteger than to use MeasureIfAllZeros with variable assignment or to chain together several operations from different namespaces...
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, thank you; that's the danger of writing code quickly on the way to a meeting, I suppose. Anyway, I think there's two distinct issues that are getting a bit conflated here: