def check_measurement_statistics(op, state, pairs, probabilities): evs, ess_or_projs, probs = measurement_statistics(op, state) assert_array_equal(evs, pairs.eigenvalues) if state.isket: ess = ess_or_projs assert_(len(ess), len(pairs.eigenstates)) for a, b in zip(ess, pairs.eigenstates): assert_(isequal(a, b)) else: projs = ess_or_projs assert_(len(projs), len(pairs.projectors)) for a, b in zip(projs, pairs.projectors): assert_(isequal(a, b)) assert_almost_equal(probs, probabilities)
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_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_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)
def test_measurement_statistics_observable_ind(op, state): """ measurement_statistics_observable: observables on basis states with targets. """ evs1, ess_or_projs1, probs1 = measurement_statistics_observable( state, tensor(op, identity(2))) evs2, ess_or_projs2, probs2 = measurement_statistics_observable( state, op, targets=[0]) np.testing.assert_almost_equal(evs1, evs2) for a, b in zip(ess_or_projs1, ess_or_projs2): assert isequal(a, b) np.testing.assert_almost_equal(probs1, probs2)
def test_terminator(self, combine): Q = sigmaz() op = -2 * spre(Q) * spost(Q.dag()) + spre(Q.dag() * Q) + spost( Q.dag() * Q) bath = DrudeLorentzPadeBath( Q=Q, lam=0.025, T=1 / 0.95, Nk=1, gamma=0.05, combine=combine, ) delta, terminator = bath.terminator() assert np.abs(delta - (0.0 / 4.0)) < 1e-8 assert isequal(terminator, -(0.0 / 4.0) * op, tol=1e-8)
def istp(self): """ QuTiP istp check is too strcit. """ tmp = self.choi.ptrace([0]) ide = qt.identity(tmp.shape[0]) return qt.isequal(tmp, ide, tol=1e-6)
def iscomplete(self): return qt.isequal(sum(self._povm_elements), qt.identity(self.dim), tol=1e-12)