-
Notifications
You must be signed in to change notification settings - Fork 96
/
Measurement.qs
28 lines (25 loc) · 943 Bytes
/
Measurement.qs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/// # Sample
/// Measurement
///
/// # Description
/// Quantum measurement is an irreversible operation in which a quantum system
/// is manipulated to yield a numerical result. Measuring a quantum system
/// generally changes the quantum state that describes that system.
///
/// In Q#, the result of a measurement is a value of the type `Result`, that is,
/// `One` or `Zero`.
///
/// This Q# program exemplifies different types of measurements.
import Std.Measurement.*;
operation Main() : (Result, Result[]) {
// The `M` operation performs a measurement of a single qubit in the
// computational basis, also known as the Pauli Z basis.
use q = Qubit();
let result = M(q);
Reset(q);
// The `MeasureEachZ` operation measures each qubit in an array in the
// computational basis and returns an array of `Result` values.
use qs = Qubit[2];
let results = MeasureEachZ(qs);
return (result, results);
}