microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1365fba5cb78ce29bb89f92fea9c0419a3a85a14

Branches

Tags

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

Clone

HTTPS

Download ZIP

samples/getting_started/Measurement.qs

34lines · modecode

1/// # Summary
2/// Measurement sample
3///
4/// # Description
5/// This Q# program demonstrates how to perform measurements in Z basis.
6///
7/// # Remarks
8/// Quantum measurement is an irreversible operation in which a quantum system
9/// is manipulated to yield a numerical result. Measuring a quantum system
10/// generally changes the quantum state that describes that system.
11operation Main() : (Result, Result[]) {
12 // Allocate a qubit. Qubit is in |0〉 state after allocation.
13 use q = Qubit();
14 // Flip the state. Qubit is in |1〉 state now.
15 X(q);
16
17 // The `MResetZ` operation performs a measurement of a single qubit in the
18 // computational basis, also known as the Pauli Z basis. Then it resets
19 // the qubit to |0〉 state. `MResetZ` may be more efficient than measuring
20 // a qubit and resetting it using two separate operations.
21 let result = MResetZ(q);
22
23 // Allocate a two-qubit array (or register).
24 use qs = Qubit[2];
25
26 // The `MResetEachZ` operation measures each qubit in an array in the
27 // computational basis and resets each qubit to |0〉 state. It returns
28 // an array of `Result` values.
29 let results = MResetEachZ(qs);
30
31 // Return all results. In Q#, the result of a measurement is a value
32 // of the type `Result`, that is, `One` or `Zero`.
33 (result, results)
34}
35