Quantum measurement is a critical operation in quantum computing that translates the qubit states into classical bits we can interpret. This chapter will guide you through the measurement syntax in OpenQASM and show you how to capture the states of qubits in classical registers.
Quantum measurements in OpenQASM default to the computational (Z) basis, collapsing the qubit state to either \( |0\rangle \) or \( |1\rangle \) upon observation. This process is analogous to reading out a classical bit with a definite value of 0 or 1. OpenQASM simplifies measuring individual qubits or an entire quantum register with ease.
Measuring a single qubit's state involves the measure
command. Here's the syntax for measuring a particular qubit from a quantum register and storing its state in a classical register:
measure <quantum_register>[<qubit_index>] -> <classical_register>[<bit_index>];
To illustrate this, we'll measure a single qubit from our quantum register1234:
Diagram
OPENQASM 2.0; // Define the OpenQASM version [^1] include "qelib1.inc"; // Include the standard library [^2] // Declaration of quantum and classical registers qreg qubit[1]; // Single-qubit quantum register [^3] creg bit[1]; // Single-bit classical register [^3] // Measure the qubit and save the result in the classical bit measure qubit[0] -> bit[0]; // Measurement command [^4]
Translation
Powered by Perceval, Qiskit, PyZX
Not run yet
Simulation
Not run yet
This experiment produces a classical bit that corresponds to the measured state of our quantum register's qubit.
For simultaneous measurement of all qubits in a quantum register, the same measure
keyword is used:
measure <quantum_register> -> <classical_register>;
Let's extend our measurement to an entire register1234:
Diagram
OPENQASM 2.0; // Define the OpenQASM version [^1] include "qelib1.inc"; // Include the standard library [^1] // Declare quantum and classical registers with matching sizes qreg qubits[2]; // Quantum register with two qubits [^3] creg bits[2]; // Classical register with two bits [^3] // Execute measurements on all qubits and store the results measure qubits -> bits; // Measurement command for all qubits [^4]
Translation
Powered by Perceval, Qiskit, PyZX
Not run yet
Simulation
Not run yet
In this scenario, each qubit from the qubits
register has its measured state stored in the corresponding bit of the bits
register. For instance, qubits[0]
's state would be stored in bits[0]
, and so on.
Note: The measure
command in OpenQASM is versatile, accommodating measurements of single qubits or entire registers depending on your program's needs.
The ability to measure qubits and store their outcomes as classical information is a fundamental feature of OpenQASM, bridging the gap between quantum operations and traditional computing.