liveBook · Manning

Multi-qubit state

As explained in Building Quantum Software with Python

A multi-qubit state is the quantum state of a system containing multiple qubits, represented by one complex amplitude for each possible outcome.

A multi-qubit state describes a system of n qubits with one complex amplitude for each possible measurement outcome. Because n binary digits produce 2^n outcomes, the state is naturally represented as a list of 2^n complex numbers. section 4.2 section 4.2.2

Use these rules when encoding a state in a simulator:

  • Match each list index k with the integer representation of an n-bit outcome, where 0 ≤ k < 2^n. section 4.2.2
  • Require a list length that is a power of two and amplitudes whose squared magnitudes sum to 1. section 4.2.2
  • Read each amplitude z_k = a_k + ib_k through its probability and direction, using |z_k|^2 for the probability. section 4.2.2
  • Initialize the default state with amplitude 1 at index 0 and 0 elsewhere. section 4.2.3

Applying a gate

A single-qubit gate transforms a multi-qubit state by recombining amplitude pairs. The target-qubit position determines which indices form pairs. Applying an X gate to target qubit 0 swaps each pair; the same operation on target qubit 2 produces a different pairing pattern. section 4.3 section 4.3.3

Listing 4.1 Function to check whether a list is a valid quantum state
from math import log2, ceil, floor
from util import is_close

def is_power_of_two(m):
    return ceil(log2(m)) == floor(log2(m))

def prepare_state(*a):
    state = [a[k] for k in range(len(a))]
    assert(is_power_of_two(len(state)))    #1
    assert (is_close(sum([abs(state[k]) ** 2 for k in range(len(state))]),
                     1.0))      #2
    return state    #3

Inspect the validation helper that checks power-of-two length and normalized amplitude magnitude before returning a simulator state. section 4.2.2

How Building Quantum Software with Python covers it

How deep it goes
Defines amplitudes, probabilities, indexing, validation, initialization, and gate-pair recombination without covering hardware state loading.
Examples
Uses eight-amplitude state tables, two-qubit default initialization, and X gates applied to target qubits in a three-qubit state.
What it assumes
Builds from single-qubit states and assumes basic complex-number and Python-list familiarity.
What you can do after
Build it from scratch as a Python list, validate it, initialize it, and simulate single-qubit gate transformations.
How it connects
Connects quantum states with quantum gates, quantum circuits, superposition, measurement outcomes, and the Fourier transform.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Quantum Software with Python. The section links point to the parts of the book it draws on.