-
Notifications
You must be signed in to change notification settings - Fork 177
Add new MeasureIfAllZeros operation. #204
base: main
Are you sure you want to change the base?
Changes from 2 commits
ce387a4
8f34d28
44eb14f
91df3c9
a5d39eb
3c2f3e4
f7e4b10
af847b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,4 +72,27 @@ namespace Microsoft.Quantum.Measurement { | |
return ForEach(M, targets); | ||
} | ||
|
||
/// # Summary | ||
/// Measures a register of qubits is in the all-zeros state. | ||
/// | ||
/// # Description | ||
/// Given a register of qubits, measures if that register is in the state | ||
cgranade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// $\ket{00 \cdots 0}$ by performing a computational basis (i.e.: | ||
/// `PauliZ`) measurement on each individual qubit in the register. | ||
/// | ||
/// # Input | ||
/// ## register | ||
/// The register of qubits to be measured. | ||
/// | ||
/// # Output | ||
/// `true` if and only if the register is measured to be in the | ||
/// $\ket{00 \cdots 0}$ state. | ||
/// | ||
/// # Remarks | ||
/// This operation does not reset its qubits, but projects them to a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This behavior differs from that of There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the last code snippet, did you mean something like 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 commentThe 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:
|
||
/// computational basis state. | ||
operation MeasureIfAllZeros(register : Qubit[]) : Bool { | ||
return All(IsResultZero, ForEach(M, register)); | ||
} | ||
|
||
} |
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); | ||
} | ||
} | ||
|
||
} |
Uh oh!
There was an error while loading. Please reload this page.