Registers of n Qubits
A quantum register is a group of qubits treated as a single unit — the quantum analogue of a classical integer register. Understanding how to allocate registers and address individual qubits is the first step toward writing multi-qubit programs.
Allocating a register
Calling circuit(n) creates a fresh -qubit register, with every qubit initialised to .
The full starting state is the tensor product
For three qubits the state vector has amplitudes, one for each basis state . Only the amplitude of is non-zero at the start.
Qubit indexing
Qubits are indexed . In this platform qubit 0 is the most-significant bit (the leftmost position in the ket label). So for a 3-qubit register:
| Qubit | Position in ket | Bit value | |-------|-----------------|-----------| | 0 | leftmost | | | 1 | middle | | | 2 | rightmost | |
Applying to qubit 2 flips the least-significant bit, so . Applying to qubit 0 instead would give (decimal 4).
State vector after a single flip
After c.x(2) the register is in . In the length-8 state vector only amplitude index 1
is non-zero (decimal value of the bit string ):
More generally, flips the bit at position and shifts the non-zero amplitude to the corresponding new basis state.
Try it
Allocate a 3-qubit register and flip qubit 2. After running, inspect the state vector to confirm the amplitude is on (index 1).
Look at the simulator output: the single non-zero amplitude sits at index 1, confirming the state
is . Changing the x argument to 0 or 1 would move that amplitude to index 4
() or index 2 () respectively.
Sign in on the full site to ask questions and join the discussion.