After performing the computation on the Qubits, the Qubits need to be measured and their values stored in Classical bits. In this chapter of the OpenQASM Tutorial, you will be learning about how to measure a Qubit and store its value in a bit.
Like everywhere else, OpenQASM also performs measurements along the Z basis. Consequently, the state of the Qubit once measure is either |0>
or |1>
.
OpenQASM provides the optionality to measure and store the value of a single Qubit in the Quantum Register, or all the Qubits in the Quantum Register at once.
Measure a Qubit
The measurement of a single Qubit of a Quantum Register onto a single classical bit of the Classical Register can be performed by using the measure
keyword.
The following syntax is used for measuring the Qubit at given index of the Quantum Register onto the bit at given index of the Classical Register-
measure quantum_register[index] -> classical_register[index];
Example
Below is an example of measuring the first Qubit of Quantum Register qubits
onto the first bit of the Classical Register bits
.
measure qubits[0] -> bits[0];
Measure a Quantum Register
It is also possible to measure all the Qubits of a Quantum Register onto bits of a Classical Register at once. The measurement of a Quantum Register onto a Classical Register can be performed by using the measure
keyword.
The following syntax is used for measuring the Quantum Register onto a Classical Register-
measure quantum_register -> classical_register;
Example
Below is an example of measuring all Qubits of Quantum Register qubits
onto the bits of a Classical Register bits
.
measure qubits -> bits;
When all the Qubits of a Quantum Register are measured, their values are stored in respective indexes in the Classical Register. For example, for a 3 Qubit Quantum Register qubits
, the measured values of qubits[0]
, qubits[1]
, qubits[2]
will be stored in the Classical Register bits
as bits[0]
, bits[1]
, bits[2]
respectively.
Note– Notice that both measurements make use of the measure
keyword in different ways.