page_type | languages | products | description | urlFragment | ||
---|---|---|---|---|---|---|
sample |
|
|
This sample demonstrates the use of measurement operations to measure one or more qubits. |
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.
- The Microsoft Quantum Development Kit.
To run the sample, use the dotnet run
command from your terminal.
- Measurement.qs: Q# code preparing and measuring a few qubits.
- Measurement.csproj: Main Q# project for the sample.