A register of n qubits starts in the pure state state (a normalised list of 2^n amplitudes). On its way to the next station, qubit qubit alone passes through a noisy wire: a one-qubit channel with Kraus operators kraus (a list of 2\times2 matrices, lists of rows, with \sum_k K_k^\dagger K_k = I, where K^\dagger is the conjugate transpose). The register arrives as the density matrix
where K^{(q)} is K acting on qubit q only: on a state vector it maps the pair of amplitudes whose indices differ only in bit q, (\psi_{\dots0\dots}, \psi_{\dots1\dots}), to K times that pair. Basis state |b_0 b_1 \dots b_{n-1}\rangle has index int("b0b1...", 2): qubit 0 is the leftmost bit (in 3 qubits, |001\rangle is index 1 and differs from |000\rangle only in qubit 2).
How much damage was done? The fidelity of the pure state |\psi\rangle with a density matrix \rho' is
a number from 0 to 1 (no square root is taken); it is 1 exactly when the noise left the state unchanged.
Write fidelity_after(state, qubit, kraus) that returns F as a real number.
Examples
Input: state = [0.7071067811865476, 0, 0, 0.7071067811865476], qubit = 1,
kraus = [[[0.8, 0], [0, 0.8]], [[0.6, 0], [0, -0.6]]]
Output: 0.64
Explanation: the Bell state (|00> + |11>)/sqrt(2); Z on either qubit turns it into
(|00> - |11>)/sqrt(2), which has no overlap with the original.
Input: state = [0.7071067811865476, 0.7071067811865476], qubit = 0,
kraus = [[[1, 0], [0, 0.8]], [[0, 0.6], [0, 0]]]
Output: 0.9
Explanation: amplitude damping with gamma = 0.36 on |+>.
Input: state = [0.7071067811865476, 0.7071067811865476, 0, 0, 0, 0, 0, 0], qubit = 2,
kraus = [[[0.8, 0], [0, 0.8]], [[0, 0.6], [0.6, 0]]]
Output: 1.0
Explanation: the state is |0>|0>|+>, and X on qubit 2 leaves |+> as it is.
Constraints
- 1 to 6 qubits;
0 <= qubit <= n - 1; 1 to 4 Kraus operators. - The answer is compared with a tolerance of
1e-6.
Goals
- Apply a one-qubit channel to one qubit of an n-qubit register
- Measure the damage with the fidelity $F = \langle\psi|\rho|\psi\rangle$