Working Backwards from a Tally Sheet

Born rule · estimation · counts · bit strings · amplitude

A lab notebook lists the counts from many shots of the same n-qubit state: a dict that maps a bit string to how often it came out. Outcomes that never came out are missing from the dict. You want to know what the counts say about the state.

Measuring gives outcome i with probability |a_i|^2, where a_i is amplitude i of the state (the Born rule). Turned around, the share of the shots that gave outcome i estimates |a_i|^2, so its square root estimates the size |a_i| of the amplitude. Counts never tell you the complex phase of an amplitude: [0.6, 0.8], [0.6, -0.8] and [0.6, 0.8j] give the same odds.

Outcome i is written as i in binary with n digits and leading zeros, and qubit 0 is the leftmost bit: in 3 qubits, outcome 3 is "011".

Write amplitude_sizes(counts, n) that returns the list of the 2^n estimated sizes, entry i for outcome i, with 0.0 for outcomes not in counts.

Examples

Input:  counts = {'0': 36, '1': 64}, n = 1
Output: [0.6, 0.8]
Explanation: 36 of 100 shots gave 0, and sqrt(0.36) = 0.6.

Input:  counts = {'11': 5, '00': 15}, n = 2
Output: [0.8660254037844386, 0.0, 0.0, 0.5]
Explanation: 15 of 20 shots gave '00' (index 0) and 5 gave '11' (index 3);
'01' and '10' never came out.

Constraints

  • every key has exactly n characters, each '0' or '1'; every count is at least 1
  • answers are compared with a tolerance of 1e-6

Goals

  • Estimate each outcome's probability by its share of the shots
  • Turn estimated probabilities back into amplitude sizes with a square root
  • Index outcomes by their bit strings, qubit 0 leftmost, and fill in the ones never seen
Starting Python…