Measuring Qubits

This sample demonstrates:

  • The use of measurement operations to measure one or more qubits, getting classical data back that can be used in classical logic.
  • How to use assertions to build tests for expected behaviour of operations that involve measurements.
  • Resetting previously allocated qubits.

In Q#, the most basic measurement operation is the M operation, which measures a single qubit in the computational basis (sometimes also called the 𝑍-basis). In this sample, we show how M can be used to sample random numbers, and to measure registers of qubits.


Running the Sample

To run the sample, use the dotnet run command from your terminal.


Further resources