microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
logo

Branches

Tags

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

Clone

HTTPS

Download ZIP

samples/getting_started/Measurement.qs

34lines · modeblame

c97c05a1DmitryVasilevsky1 years ago1/// # 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.
13use q = Qubit();
14// Flip the state. Qubit is in |1〉 state now.
15X(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.
21let result = MResetZ(q);
22
23// Allocate a two-qubit array (or register).
24use 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.
29let 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}