cQASM: Single Gate Multiple-Qubits

Single Gate Multiple-Qubits

Sometimes it is necessary to apply the same gate to multiple qubits. Instead of writing a single line for each of the qubits, cQASM allows multiple qubits to be addressed in a single statement:

          version 1.0

qubits 8

prep_z q[0:7]
X q[0,2,3]
Y q[1,4]
Z q[0:3, 5:7]

There are three possibilities:

  • a range of qubit indices can be specified as the first and last qubit index separated by a colon: q[0:7] addresses qubits 0, 1, 2, 3, 4, 5, 6 and 7;
  • a list of qubit indices can be specified separated by commas: q[0,2,3] addresses qubits 0, 2 and 3;
  • a list of ranges can be specified: q[0:3, 5:7] addresses qubits 0, 1, 2, 3, 5, 6 and 7.

Parallel operation

It is possible to indicate that gates should be executed in parallel, by putting the gates between curly braces, separated by the pipe symbol. For example, on line 7 of this code, three gates are executed in parallel. In practice this is the same as putting barriers left and right of these gates.

          version 1.0

qubits 3

prep_z q[0:2]

{ X q[0] | Y q[1] | H q[2] }


Note that parallel execution may not always be possible on a hardware backend. In that case, the compiler may decide to execute the gates sequentially.

It is incorrect to request parallel execution of multiple gates on a single qubit.

cQASM v1.0 specification

Additional information can be found in cQASM v1.0: Towards a Common Quantum Assembly Language.