Barrier

The barrier instruction is an n-qubit instruction that prevents any optimization or commutation through the barrier (on the qubits involved). For example, if you would write:

        
          x q[0]
barrier q[0,1]
x q[1]
        
      

the scheduler would not be allowed to schedule the two X gates in parallel, because due to the barrier the first X gate must complete before the second is started.

Note that the Single-Gate-Multiple-Qubits syntax is used for this operation. This means that barrier q[0,1] expands to multiple single-qubit gates: instead of expanding to multiple single-qubit gates, the barrier is always interpreted as an n-qubit gate.

The barrier operation acting on a single-qubit can be regarded as a wait operation with zero duration. This can be used, for example, to prevent two consecutive gates, which would normally cancel eachother (like two consecutive X-gates), to cancel out. When you would also like to include some waiting time between the operations, the wait operation should be used instead. It should be emphasized hoewever, that the wait operation is a single-qubit operation.