def test_povm(): """ Test if povm formulation works correctly by checking probabilities for the quantum state discrimination example """ coeff = (sqrt(2) / (1 + sqrt(2))) E_1 = coeff * ket2dm(basis(2, 1)) E_2 = coeff * ket2dm((basis(2, 0) - basis(2, 1)) / (sqrt(2))) E_3 = identity(2) - E_1 - E_2 M_1 = Qobj(scipy.linalg.sqrtm(E_1)) M_2 = Qobj(scipy.linalg.sqrtm(E_2)) M_3 = Qobj(scipy.linalg.sqrtm(E_3)) ket1 = basis(2, 0) ket2 = (basis(2, 0) + basis(2, 1)) / (sqrt(2)) dm1 = ket2dm(ket1) dm2 = ket2dm(ket2) M = [M_1, M_2, M_3] _, probabilities = measurement_statistics_povm(ket1, M) np.testing.assert_allclose(probabilities, [0, 0.293, 0.707], 0.001) _, probabilities = measurement_statistics_povm(ket2, M) np.testing.assert_allclose(probabilities, [0.293, 0, 0.707], 0.001) _, probabilities = measurement_statistics_povm(dm1, M) np.testing.assert_allclose(probabilities, [0, 0.293, 0.707], 0.001) _, probabilities = measurement_statistics_povm(dm2, M) np.testing.assert_allclose(probabilities, [0.293, 0, 0.707], 0.001)
def test_measurement_statistics_ind(ops, state): """ measurement_statistics_povm: projectors on basis states with targets. """ states1, probs1 = measurement_statistics_povm( state, [tensor(op, identity(2)) for op in ops]) states2, probs2 = measurement_statistics_povm(state, ops, targets=[0]) for a, b in zip(states1, states2): assert isequal(a, b) np.testing.assert_almost_equal(probs1, probs2)
def test_measure(ops, state): """measure_povm: test on basis states using different projectors """ collapsed_states, _ = measurement_statistics_povm(state, ops) for _ in range(10): index, final_state = measure_povm(state, ops) assert isequal(final_state, collapsed_states[index])
def test_measurement_statistics_povm(ops, state, final_states, probabilities): """ measurement_statistics_povm: projectors applied to basis states. """ collapsed_states, probs = measurement_statistics_povm(state, ops) for i, final_state in enumerate(final_states): collapsed_state = collapsed_states[i] if final_state: assert isequal(collapsed_state, final_state) else: assert collapsed_state is None np.testing.assert_almost_equal(probs, probabilities)