def test_br_term_mult(): "BR Tools : br_term_mult" #secular tests for kk in range(10): N = 10 H = rand_herm(N, 0.5) Hf = H.full('f') t = 1.0 a = rand_herm(N, 0.5) A = a.full('f') vec = np.ones(N**2, dtype=complex) out = np.zeros(N**2, dtype=complex) use_secular = 1 atol = 1e-12 spec = lambda w: 1.0 H_diag = H.transform(H.eigenstates()[1]) L_diag = liouvillian(H_diag) R = (bloch_redfield_tensor( H, [[a, spec]], c_ops=[], use_secular=use_secular)[0] - L_diag) ans = R.data.dot(vec) evals = np.zeros(N, dtype=float) evecs = _test_zheevr(Hf, evals) _test_br_term_mult(t, A, evecs, evals, vec, out, use_secular, 0.1, atol) assert_(np.allclose(ans, out)) #non-secular tests for kk in range(10): N = 10 H = rand_herm(N, 0.5) Hf = H.full('f') t = 1.0 a = rand_herm(N, 0.5) A = a.full('f') vec = np.ones(N**2, dtype=complex) out = np.zeros(N**2, dtype=complex) use_secular = 0 atol = 1e-12 spec = lambda w: 1.0 H_diag = H.transform(H.eigenstates()[1]) L_diag = liouvillian(H_diag) R = (bloch_redfield_tensor( H, [[a, spec]], c_ops=[], use_secular=use_secular)[0] - L_diag) ans = R.data.dot(vec) evals = np.zeros(N, dtype=float) evecs = _test_zheevr(Hf, evals) _test_br_term_mult(t, A, evecs, evals, vec, out, use_secular, 0.1, atol) assert_(np.allclose(ans, out))
def test_br_term_mult(secular): "BR Tools : br_term_mult" dimension = 10 time = 1.0 atol = 1e-12 for _ in range(10): H = qutip.rand_herm(dimension, 0.5) basis = H.eigenstates()[1] L_diagonal = qutip.liouvillian(H.transform(basis)) evals = np.empty((dimension,), dtype=np.float64) evecs = _test_zheevr(H.full('F'), evals) operator = qutip.rand_herm(dimension, 0.5) a_ops = [[operator, lambda w: 1.0]] vec = np.ones((dimension*dimension,), dtype=np.complex128) br_tensor, _ = qutip.bloch_redfield_tensor(H, a_ops, use_secular=secular) target = (br_tensor - L_diagonal).data.dot(vec) calculated = np.zeros_like(target) _test_br_term_mult(time, operator.full('F'), evecs, evals, vec, calculated, secular, 0.1, atol) assert np.allclose(target, calculated)