Binary controlled single qubit gates can be performed by adding
c- in front of the single qubit gate.
All single qubit gates, except the
measure commands, can be controlled by the result of an earlier measurement. In the simplest form, the single qubit gate is executed only when the measurement result was 1. As an example, consider this simple cQASM program:
version 1.0 qubits 2 prep_z q[0:1] H q measure_z q c-X b, q measure q
Line 5 prepares the qubits, followed by the creation of a superposition on qubit 0. This qubit is measured in line 7, which will result in a 0 or 1 (each with 50% probability) to be stored in the classical register at index 0. Line 7 shows the binary-controlled X gate.
Only when the measurement of the qubit at index 0,
q on line 7 yielded 1 (and thus the bit at index 0,
b is 1) will the X gate be executed. If
b is 0, the X gate will not be applied.
Any single qubit gate can be prepended with
c- to execute that gate only when the classical argument is one. Furthermore, it is possible to specify more than one classical bit, in which case the gate is only executed if and only if all specified classical bits are 1:
version 1.0 qubits 3 prep_z q[0:2] X q measure_z q measure_z q c-Y b[0,1], q
In this example, the binary-controlled Y gate on line 9 will not apply (no Y rotation is carried out on
b will be 0.