Init instruction

In general, qubits are initialized in the \(|0\rangle\) state. Nonetheless, to explicitly initialize (particular) qubits in the \(|0\rangle\) state one can use the init instruction. The general form of an init instruction is as follows:

init qubit-argument

Grammar for init instruction

init-instruction:
init qubit-argument

qubit-argument:
qubit-variable
qubit-index

qubit-variable:
identifier

qubit-index:
index

Example

qubit q
init q
qubit[5] q
init q[2, 4]

Note

The init instruction accepts SGMQ notation, similar to gates.

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

version 3.0

qubit[2] q
bit[2] b

init q  // Initializes the qubits to |0>

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

b = measure q

In the code example above, the qubits are first declared and subsequently initialized. Note that the initialization of qubits needs to be done before any instruction (excluding a control instruction) is applied to them (see warning below). If one wishes to reset the state of the qubit to \(|0\rangle\) mid-circuit, one should use the reset instruction.

Warning

Initialization of a qubit can only be done immediately after declaration of the qubit, i.e., it is not possible to initialize a qubit, if prior to that an instruction was applied to the qubit (excluding a control instruction).

1
2
3
4
5
6
7
8
version 3.0

qubit[2] q

barrier q  // Control instructions may be applied to qubits before initialization
H q[1]

init q[1]  // Invalid use, since the H gate was applied to q[1] before initialization
1
2
3
4
5
6
7
8
version 3.0

qubit[2] q

barrier q  // Control instructions may be applied to qubits before initialization
H q[1]

init q[0]  // Valid use, because no instruction is applied to q[0] before initalization