This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 179
Add new MeasureIfAllZeros operation. #204
Open
cgranade
wants to merge
8
commits into
main
Choose a base branch
from
cgranade/measure-if-all-zeros
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ce387a4
Add new MeasureIfAllZeros operation.
cgranade 8f34d28
Forgot message.
cgranade 44eb14f
Update Standard/src/Measurement/Registers.qs
91df3c9
Update Standard/src/Measurement/Registers.qs
a5d39eb
Merge branch 'master' into cgranade/measure-if-all-zeros
3c2f3e4
Merge branch 'master' into cgranade/measure-if-all-zeros
f7e4b10
Merge branch 'master' into cgranade/measure-if-all-zeros
af847b2
Merge branch 'main' into cgranade/measure-if-all-zeros
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Microsoft.Quantum.Measurement.Tests { | ||
open Microsoft.Quantum.Intrinsic; | ||
open Microsoft.Quantum.Canon; | ||
open Microsoft.Quantum.Measurement; | ||
open Microsoft.Quantum.Diagnostics; | ||
|
||
@Test("QuantumSimulator") | ||
operation CheckMeasureIfAllZeros() : Unit { | ||
using (qs = Qubit[3]) { | ||
Fact(MeasureIfAllZeros(qs), "MeasureIfAllZeros was false for |000⟩ state."); | ||
|
||
X(qs[1]); | ||
Fact(not MeasureIfAllZeros(qs), "MeasureIfAllZeros was true for |010⟩ state."); | ||
|
||
ResetAll(qs); | ||
} | ||
} | ||
|
||
} |
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.
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: