Asking One Qubit Out of Many

Born rule · marginal probability · qubit register · bit order

A register of n qubits is in the state state, a list of 2^n complex amplitudes with \sum_i |a_i|^2 = 1. Measuring the whole register gives basis state i with probability |a_i|^2 (the Born rule; |a_i| is abs(state[i])).

Bit order: basis state |b_0 b_1 \dots b_{n-1}\rangle has index int("b0b1...", 2), so qubit 0 is the leftmost bit, the most significant. In 3 qubits, |011\rangle is index 3, where qubit 0 reads 0 and qubits 1 and 2 read 1.

Often only one qubit is read. Write prob_one(state, k) that returns the probability that qubit k reads 1: the total probability of all basis states whose bit for qubit k is 1.

Press Run with plot(list(range(n)), [prob_one(state, k) for k in range(n)], kind="bar") to see every qubit's chance of reading 1.

Examples

Input:  state = [0, 1, 0, 0], k = 1
Output: 1.0
Explanation: the register is in |01>, index 1: qubit 0 reads 0, qubit 1 reads 1.

Input:  state = [0, 1, 0, 0], k = 0
Output: 0.0

Input:  state = [0.5, 0.5, 0.7071067811865476j, 0], k = 0
Output: 0.5
Explanation: qubit 0 reads 1 in |10> and |11> (indices 2 and 3): 0.5 + 0 = 0.5.

Constraints

  • the answer is compared with a tolerance of 1e-6

Goals

  • Find the probability that one qubit of a register reads 1
  • Pick out the basis states whose bit for qubit k is 1, with qubit 0 the leftmost bit
Starting Python…