Skip to content
Tutorials Center
My learning

Topics

Lesson 8 of 39 ยท Qubits and Superposition

Multi-Qubit States and the Tensor Product

Combine qubits with the tensor product, understand 2^n amplitudes, bit-string ordering, product versus entangled states, and measure a subset of qubits, all in NumPy.

One qubit is a vector of 2 amplitudes. Two qubits make a vector of 4, three qubits 8, and n qubits 2^n. How do the individual qubit states combine into the joint state? The operation is the tensor product, called the Kronecker product in NumPy (np.kron). It is the mathematical glue behind every multi-qubit circuit, and it is also where entanglement first becomes visible.

The tensor product of states

Given a state a = [a0, a1] of one qubit and b = [b0, b1] of another, the joint state is

a (x) b = [a0*b0, a0*b1, a1*b0, a1*b1]

Every amplitude is a product, so the probability of reading a pair of bits is the product of the individual probabilities, exactly as for independent coins. The result is written |a>|b> or |ab>.

The four entries are ordered as the bit strings 00, 01, 10, 11. In this course the leftmost bit is qubit 0, the first qubit in the tensor product, and the most significant bit of the index. (Some libraries, such as Qiskit, number qubits the other way around. Always check the convention of a tool before comparing results.)

Python Building two- and three-qubit states with kron

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Basis states and indices

The 2^n basis states of n qubits are the bit strings. Bit string b corresponds to the unit vector with a 1 at position int(b, 2). A general state is a superposition of them:

|psi> = sum over x of c[x] |x>, with the squared magnitudes adding to 1.

Two bits flipped between position and index is a classic bug source, so it pays to write small helpers that convert between the two views.

Python Helpers for bit strings and indices

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Product states versus entangled states

If a joint state can be written as a (x) b, it is a product state (or separable): each qubit has a well-defined state of its own. Most vectors of 4 amplitudes cannot be written this way. Those are entangled.

A practical test for two qubits: arrange the four amplitudes into a 2 by 2 matrix [[c00, c01], [c10, c11]]. The state is a product exactly when the determinant c00*c11 - c01*c10 is zero. (The matrix then has rank 1, meaning rows are multiples of each other, just as a (x) b produces.)

Python Product or entangled? The determinant test

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The states (|00> + |11>)/sqrt(2) and (|01> + |10>)/sqrt(2) are entangled: there are no two separate qubit states that multiply to give them. The next chapter makes these states the star of the show.

Measuring a subset of qubits

Suppose you measure only the first qubit of a two-qubit state. The rule has three steps:

  1. Probability of outcome b on that qubit is the sum of |amplitude|^2 over all basis states where it equals b.
  2. Keep only those amplitudes and set the rest to zero.
  3. Divide by the square root of the probability so the state is normalized again.

For a product state, the other qubit is untouched. For an entangled state, measuring one qubit changes what you know about the other, which is the heart of Bell States and Entanglement.

Python Partial measurement with collapse

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Reshaping the vector into [2] * n gives one axis per qubit. This trick, which we reuse in Building a Circuit Simulator, makes single-qubit operations simple to write.

Exponential growth is the point and the problem

The 2^n amplitudes are what let a quantum computer encode so much structure in so few physical qubits. They are also why classical simulation hits a wall near 50 qubits. Yet remember: you can only extract n classical bits per run. The art is in using the large state space as scratch space, then steering amplitudes so measurement reveals something useful.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does np.kron([1, 0], [0, 1]) represent as a two-qubit state?

    The first qubit is 0 and the second is 1, so the joint state is |01>, which is the unit vector [0, 1, 0, 0].
  2. 2. How many amplitudes describe 5 qubits?

    2^5 = 32.
  3. 3. Which two-qubit state is entangled?

    Its 2x2 amplitude matrix has non-zero determinant, so it cannot be written as a tensor product of two single-qubit states.
  4. 4. After measuring qubit 0 of (|00> + |11>)/sqrt(2) and getting 1, what is the state?

    Only the |11> term has qubit 0 equal to 1. After renormalizing, the state is |11>.

Summary

  • Joint states are built with the tensor (Kronecker) product, np.kron.
  • n qubits have 2^n amplitudes, indexed by bit strings (leftmost bit is qubit 0 here).
  • A state that is not a tensor product is entangled; for two qubits the determinant test detects it.
  • Measuring a subset of qubits sums probabilities, keeps matching amplitudes and renormalizes.
  • Reshaping the vector to [2] * n gives one axis per qubit.

Next: Single-Qubit Gates