Which Two Bits Made This Pair?

Bell states · entanglement · global phase · inner product

A pair source on a chip makes two-qubit states from two classical bits b0 and b1. It prepares the basis state |b_0 b_1\rangle, applies the Hadamard gate H=\tfrac{1}{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix} to qubit 0, then CNOT with control qubit 0 and target qubit 1 (CNOT flips qubit 1 in every basis state where qubit 0 reads 1). The four possible outputs are the four Bell states

|\Phi^\pm\rangle=\tfrac{1}{\sqrt2}(|00\rangle\pm|11\rangle),\qquad |\Psi^\pm\rangle=\tfrac{1}{\sqrt2}(|01\rangle\pm|10\rangle).

A two-qubit state is a list of 4 amplitudes for |00\rangle, |01\rangle, |10\rangle, |11\rangle. Bit order: basis state |b_0 b_1\rangle has index int("b0b1", 2), so qubit 0 is the leftmost bit: |01\rangle is index 1 (qubit 0 reads 0, qubit 1 reads 1) and |10\rangle is index 2.

A receiver gets a normalised state state and wants to know which bits went in. Write which_bits(state) that returns the pair (b0, b1) whose output equals state up to a global phase (a common factor e^{i\phi} on all four amplitudes), or None if state is not one of the four outputs. Every test state is either one of the four up to a global phase (to within rounding, 1e-9), or clearly far from all of them.

Examples

Input:  state = [0.7071067811865475, 0, 0, 0.7071067811865475]
Output: (0, 0)

Input:  state = [0, 0.7071067811865475, 0.7071067811865475, 0]
Output: (0, 1)

Input:  state = [0, 0.7071067811865475j, -0.7071067811865475j, 0]
Output: (1, 1)
Explanation: this is i times (|01> - |10>)/sqrt(2); the factor i is a global phase.

Input:  state = [0.7071067811865475, 0, 0, 0.7071067811865475j]
Output: None
Explanation: the i sits on one amplitude only, a relative phase, so this is none of the four.

Goals

  • Follow two basis inputs through H on qubit 0 and CNOT(0, 1)
  • Recognise a Bell state up to a global phase with an inner product
  • Keep the bit order straight: the first input bit is qubit 0, the leftmost
Starting Python…