Raw Amplitudes from the Chip Log

qubit · amplitude · Born rule · normalisation · probability

A test chip writes the state of its qubits to a log as a list of complex numbers, the amplitudes, but the logging firmware forgets to scale them: the list is right up to one positive factor. You need the odds of every measurement outcome.

A state of n qubits is a list of 2^n complex numbers, and amplitude i belongs to basis state i (for one qubit, [a, b] means a|0\rangle + b|1\rangle). A proper state is a unit vector: \sum_i |a_i|^2 = 1, where |a_i| is abs(a[i]). Measuring all the qubits gives outcome i with probability

p_i = |a_i|^2 \qquad \text{(the Born rule)}

so the probabilities of a unit vector add up to 1. A list that is not a unit vector describes the same state as the list divided by its length \sqrt{\sum_i |a_i|^2}.

Write outcome_odds(amps) that returns the list of the 2^n probabilities p_0, p_1, \dots of the state that amps describes.

Examples

Input:  amps = [3, 4j]
Output: [0.36, 0.64]
Explanation: the length is sqrt(9 + 16) = 5, so the state is [0.6, 0.8j],
and |0.6|^2 = 0.36, |0.8j|^2 = 0.64.

Input:  amps = [1, 1j]
Output: [0.5, 0.5]

Input:  amps = [1, 0, 0, -1]
Output: [0.5, 0.0, 0.0, 0.5]
Explanation: two qubits: only basis states 0 and 3 can come out, equally often.

Press Run with plot(range(len(p)), p, kind="bar") to see the odds.

Constraints

  • answers are compared with a tolerance of 1e-6

Goals

  • Turn a vector of complex amplitudes into measurement probabilities with the Born rule
  • Normalise first, so the probabilities add up to 1
  • See that the probability of an outcome depends only on the size of its amplitude
Starting Python…