Measure instruction

A measure instruction performs a measurement to its qubit argument and assigns the outcome to a bit variable.

The measure instruction can either

  • have no parameters measure, which corresponds to a measurement in the Z-basis, or
  • accept 3 floating-point parameters measure(0,0,1), which define the axis of the basis along which the measurement is to be performed.

Note

measure(0,0,1) is equal to the non-parameterized measure as \((0,0,1)\) defines the positive \(z\)-axis.

The general form of a measure instruction is as follows:

bit-argument = measure qubit-argument
bit-argument = measure(parameter-list) qubit-argument

Grammar for measure instruction

measure-instruction:
bit-argument = measure qubit-argument
bit-argument = measure parameters qubit-argument

bit-argument:
bit-variable
bit-index

bit-variable:
identifier

bit-index:
index

parameters:
( parameter-list )

parameter-list:
parameter
parameter-list , parameter

parameter:
floating-literal

qubit-argument:
qubit-variable
qubit-index

qubit-variable:
identifier

qubit-index:
index

Example

1
2
3
4
qubit q
bit b
b = measure q
b = measure(1,0,0) q
1
2
3
4
qubit[5] q
bit[2] b
b[0, 1] = measure q[2, 3]
b[1, 0] = measure(1,0,0) q[4, 3]

Note

The measure instruction accepts SGMQ notation, similar to gates.

The following code snippet shows how the measure instruction might be used in context.

1
2
3
4
5
6
7
8
9
version 3.0

qubit[2] q
bit[2] b

H q[0]
CNOT q[0], q[1]

b = measure q  // Measurement in the standard basis.

On the last line of this simple cQASM program, the respective states of both qubits in the qubit register are measured along the standard/computational basis.

To measure in the Hadamard basis (or X-basis) you can use the parameterized measure instruction to measure along the \(x\)-axis, defined by \((1,0,0)\).

1
2
3
4
5
6
7
8
version 3.0

qubit q
bit b

X q
H q
b = measure(1,0,0) q // Measurement in the Hadamard basis.

On the last line of the latter cQASM program the qubit is measured along the \(x\)-axis; the measurement outcome will (always) be 1, due to measuring the \(|1\rangle\) state in the X-basis.