A source on a chip is supposed to prepare one fixed qubit state, and you want to know which. One basis never suffices: counts of 0 and 1 hide every phase. So the lab measures many copies in three different ways and keeps three tally sheets.
A one-qubit state is a pair [a, b], meaning a|0\rangle + b|1\rangle, with |a|^2 + |b|^2 = 1. Measuring it in a basis of two perpendicular unit vectors e_1, e_2 gives outcome e_k with probability |\langle e_k|\psi\rangle|^2, where \langle u|v\rangle = \sum_k \overline{u_k} v_k and \overline{u_k} is the complex conjugate. The three bases are
- Z: |0\rangle =
[1, 0]and |1\rangle =[0, 1]; - X: |+\rangle =
[1/sqrt(2), 1/sqrt(2)]and |-\rangle =[1/sqrt(2), -1/sqrt(2)]; - Y: |{+i}\rangle =
[1/sqrt(2), 1j/sqrt(2)]and |{-i}\rangle =[1/sqrt(2), -1j/sqrt(2)].
Each tally sheet is a pair of counts: z_counts = (count of 0, count of 1), x_counts = (count of +, count of -), y_counts = (count of +i, count of -i). From them come three observed frequencies: f_0 = share of 0 in the Z shots, f_+ = share of + in the X shots, f_{+i} = share of +i in the Y shots.
Any state \psi predicts three probabilities P_\psi(0), P_\psi(+) and P_\psi(+i). Because the counts are noisy, usually no state predicts the frequencies exactly. Write fit_state(z_counts, x_counts, y_counts) that returns the state \psi that makes
as small as possible. Any global phase is accepted: [1j, 0] is the same state as [1, 0].
Examples
Input: z_counts = (50, 50), x_counts = (50, 50), y_counts = (100, 0)
Output: [0.7071067811865476, 0.7071067811865476j]
Explanation: the state |+i> itself predicts exactly these frequencies, (0.5, 0.5, 1.0).
Input: z_counts = (100, 0), x_counts = (100, 0), y_counts = (50, 50)
Output: [0.9238795325112867, 0.3826834323650898]
Explanation: no state is both certainly 0 and certainly +; the best compromise
predicts 0.8535533905932737 for both, and 0.5 for +i.
Input: z_counts = (90, 10), x_counts = (70, 30), y_counts = (48, 52)
Output: [0.9730195535593158, 0.22957763283095992 - 0.02295776328309599j]
Constraints
- every pair of counts adds up to at least 1, and each count is at most
10**6 - the frequencies are never all close to one half: at least one of f_0, f_+, f_{+i} differs from 0.5 by more than 0.02, so the best state is unique
- states are compared with a tolerance of
1e-6, so a coarse search over angles is not accurate enough
Goals
- Predict a state's odds in the Z, X and Y bases and see they are linear in its Bloch point
- Turn a best-fit problem over all states into a projection onto the unit sphere
- Rebuild a qubit state, up to a global phase, from measurement counts alone