microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.0.10-rc

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

samples/algorithms/Measurement.qs

30lines · modecode

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