def test_inchworm_state(): """ test to check inchworm is contributing to the state list """ noise_param = { "SEED": 0, "MODEL": "FFT_FILTER", "TLEN": 250.0, # Units: fs "TAU": 1.0, # Units: fs } nsite = 10 e_lambda = 20.0 gamma = 50.0 temp = 140.0 (g_0, w_0) = bcf_convert_sdl_to_exp(e_lambda, gamma, 0.0, temp) loperator = np.zeros([10, 10, 10], dtype=np.float64) gw_sysbath = [] lop_list = [] for i in range(nsite): loperator[i, i, i] = 1.0 gw_sysbath.append([g_0, w_0]) lop_list.append(sp.sparse.coo_matrix(loperator[i])) gw_sysbath.append([-1j * np.imag(g_0), 500.0]) lop_list.append(loperator[i]) hs = np.zeros([nsite, nsite]) hs[0, 1] = 40 hs[1, 0] = 40 hs[1, 2] = 10 hs[2, 1] = 10 hs[2, 3] = 40 hs[3, 2] = 40 hs[3, 4] = 10 hs[4, 3] = 10 hs[4, 5] = 40 hs[5, 4] = 40 hs[5, 6] = 10 hs[6, 5] = 10 hs[6, 7] = 40 hs[7, 6] = 40 hs[7, 8] = 10 hs[8, 7] = 10 hs[8, 9] = 40 hs[9, 8] = 40 sys_param = { "HAMILTONIAN": np.array(hs, dtype=np.complex128), "GW_SYSBATH": gw_sysbath, "L_HIER": lop_list, "L_NOISE1": lop_list, "ALPHA_NOISE1": bcf_exp, "PARAM_NOISE1": gw_sysbath, } eom_param = {"EQUATION_OF_MOTION": "NORMALIZED NONLINEAR"} integrator_param = { "INTEGRATOR": "RUNGE_KUTTA", "INCHWORM": True, "INCHWORM_MIN": 5, } psi_0 = np.array([0.0] * nsite, dtype=np.complex) psi_0[2] = 1.0 psi_0 = psi_0 / np.linalg.norm(psi_0) hops_inchworm = HOPS( sys_param, noise_param=noise_param, hierarchy_param={"MAXHIER": 2}, eom_param=eom_param, integration_param=integrator_param, ) hops_inchworm.make_adaptive(1e-15, 1e-15) hops_inchworm.initialize(psi_0) state_list = hops_inchworm.state_list known_state_list = [1, 2, 3] assert tuple(state_list) == tuple(known_state_list) z_step = hops_inchworm._prepare_zstep(2.0, hops_inchworm.storage.z_mem) (state_update, aux_update) = hops_inchworm.basis.define_basis(hops_inchworm.phi, 2.0, z_step) # First inchworm step # ---------------------------------------------------------------------------------- state_update, aux_update, phi = hops_inchworm.inchworm_integrate( state_update, aux_update, 2.0) state_new = state_update[0] known = [0, 1, 2, 3, 4] assert np.array_equal(state_new, known) state_stable = state_update[1] known = [1, 2, 3] assert np.array_equal(state_stable, known) add_state = state_update[2] known = [0, 4] assert np.array_equal(add_state, known) # Second inchworm step # ---------------------------------------------------------------------------------- state_update, aux_update, phi = hops_inchworm.inchworm_integrate( state_update, aux_update, 2.0) state_new = state_update[0] known = [0, 1, 2, 3, 4, 5] assert np.array_equal(state_new, known) state_stable = state_update[1] known = [0, 1, 2, 3, 4] assert np.array_equal(state_stable, known) add_state = state_update[2] known = [5] assert np.array_equal(add_state, known) # Third inchworm step # ---------------------------------------------------------------------------------- state_update, aux_update, phi = hops_inchworm.inchworm_integrate( state_update, aux_update, 2.0) state_new = state_update[0] known = [0, 1, 2, 3, 4, 5, 6] assert np.array_equal(state_new, known) state_stable = state_update[1] known = [0, 1, 2, 3, 4, 5] assert np.array_equal(state_stable, known) add_state = state_update[2] known = [6] assert np.array_equal(add_state, known)
def test_inchworm_aux(): """ test for inchworm_integrate to make sure the aux are properly being added """ noise_param = { "SEED": 0, "MODEL": "FFT_FILTER", "TLEN": 250.0, # Units: fs "TAU": 1.0, # Units: fs } nsite = 2 e_lambda = 20.0 gamma = 50.0 temp = 140.0 (g_0, w_0) = bcf_convert_sdl_to_exp(e_lambda, gamma, 0.0, temp) loperator = np.zeros([2, 2, 2], dtype=np.float64) gw_sysbath = [] lop_list = [] for i in range(nsite): loperator[i, i, i] = 1.0 gw_sysbath.append([g_0, w_0]) lop_list.append(sp.sparse.coo_matrix(loperator[i])) gw_sysbath.append([-1j * np.imag(g_0), 500.0]) lop_list.append(loperator[i]) hs = np.zeros([nsite, nsite], dtype=np.float64) hs[0, 1] = 40 hs[1, 0] = 40 # hs[1, 2] = 10 # hs[2, 1] = 10 sys_param = { "HAMILTONIAN": np.array(hs, dtype=np.complex128), "GW_SYSBATH": gw_sysbath, "L_HIER": lop_list, "L_NOISE1": lop_list, "ALPHA_NOISE1": bcf_exp, "PARAM_NOISE1": gw_sysbath, } eom_param = {"EQUATION_OF_MOTION": "NORMALIZED NONLINEAR"} integrator_param = { "INTEGRATOR": "RUNGE_KUTTA", "INCHWORM": True, "INCHWORM_MIN": 5, } psi_0 = np.array([0.0] * nsite, dtype=np.complex) psi_0[1] = 1.0 psi_0 = psi_0 / np.linalg.norm(psi_0) hops_inchworm = HOPS( sys_param, noise_param=noise_param, hierarchy_param={"MAXHIER": 4}, eom_param=eom_param, integration_param=integrator_param, ) hops_inchworm.make_adaptive(1e-15, 1e-15) hops_inchworm.initialize(psi_0) aux_list = hops_inchworm.auxiliary_list known_aux_list = map_to_auxvec([(0, 0, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)]) assert set(aux_list) == set(known_aux_list) z_step = hops_inchworm._prepare_zstep(2.0, hops_inchworm.storage.z_mem) (state_update, aux_update) = hops_inchworm.basis.define_basis(hops_inchworm.phi, 2.0, z_step) # First inchworm # ---------------------------------------------------------------------------------- state_update, aux_update, phi = hops_inchworm.inchworm_integrate( state_update, aux_update, 2.0) aux_new = aux_update[0] known = map_to_auxvec([ (0, 0, 0, 0), (0, 0, 0, 1), (0, 0, 0, 2), (0, 0, 1, 0), (0, 0, 1, 1), (0, 0, 2, 0), (0, 1, 0, 0), (0, 1, 0, 1), (0, 1, 1, 0), (1, 0, 0, 0), (1, 0, 0, 1), (1, 0, 1, 0), ]) assert set(aux_new) == set(known) state_aux = aux_update[1] known = map_to_auxvec([(0, 0, 0, 1), (0, 0, 0, 0), (0, 0, 1, 0)]) assert set(state_aux) == set(known) add_aux = aux_update[2] known = map_to_auxvec([ (0, 0, 0, 2), (0, 0, 1, 1), (0, 0, 2, 0), (0, 1, 0, 0), (0, 1, 0, 1), (0, 1, 1, 0), (1, 0, 0, 0), (1, 0, 0, 1), (1, 0, 1, 0), ]) assert set(known) == set(add_aux) # Second inchworm # ---------------------------------------------------------------------------------- state_update, aux_update, phi = hops_inchworm.inchworm_integrate( state_update, aux_update, 2.0) aux_new = aux_update[0] known = map_to_auxvec([ (0, 0, 0, 0), (0, 0, 0, 1), (0, 0, 0, 2), (0, 0, 0, 3), (0, 0, 1, 0), (0, 0, 1, 1), (0, 0, 1, 2), (0, 0, 2, 0), (0, 0, 2, 1), (0, 0, 3, 0), (0, 1, 0, 0), (0, 1, 0, 1), (0, 1, 1, 0), (1, 0, 0, 0), (1, 0, 0, 1), (1, 0, 1, 0), (0, 1, 0, 2), (0, 1, 1, 0), (0, 1, 1, 1), (0, 1, 2, 0), (0, 2, 0, 0), (0, 2, 0, 1), (0, 2, 1, 0), (1, 0, 0, 0), (1, 0, 0, 1), (1, 0, 0, 2), (1, 0, 1, 0), (1, 0, 1, 1), (1, 0, 2, 0), (1, 1, 0, 0), (1, 1, 0, 1), (1, 1, 1, 0), (2, 0, 0, 0), (2, 0, 0, 1), (2, 0, 1, 0), ]) assert set(aux_new) == set(known) stable_aux = aux_update[1] known = map_to_auxvec([ (0, 0, 0, 0), (0, 0, 0, 1), (0, 0, 0, 2), (0, 0, 1, 0), (0, 0, 1, 1), (0, 0, 2, 0), (0, 1, 0, 0), (0, 1, 0, 1), (0, 1, 1, 0), (1, 0, 0, 0), (1, 0, 0, 1), (1, 0, 1, 0), ]) assert set(stable_aux) == set(known) add_aux = aux_update[2] known = map_to_auxvec([ (0, 0, 0, 3), (0, 0, 1, 2), (0, 0, 2, 1), (0, 0, 3, 0), (0, 1, 0, 2), (0, 1, 1, 1), (0, 1, 2, 0), (0, 2, 0, 0), (0, 2, 0, 1), (0, 2, 1, 0), (1, 0, 0, 2), (1, 0, 1, 1), (1, 0, 2, 0), (1, 1, 0, 0), (1, 1, 0, 1), (1, 1, 1, 0), (2, 0, 0, 0), (2, 0, 0, 1), (2, 0, 1, 0), ]) assert set(known) == set(add_aux) # Third inchworm # ---------------------------------------------------------------------------------- state_update, aux_update, phi = hops_inchworm.inchworm_integrate( state_update, aux_update, 2.0) aux_new = aux_update[0] known = map_to_auxvec([ (0, 0, 0, 0), (0, 0, 0, 1), (0, 0, 0, 2), (0, 0, 0, 3), (0, 0, 1, 0), (0, 0, 1, 1), (0, 0, 1, 2), (0, 0, 2, 0), (0, 0, 2, 1), (0, 0, 3, 0), (0, 1, 0, 0), (0, 1, 0, 1), (0, 1, 0, 2), (0, 1, 1, 0), (0, 1, 1, 1), (0, 1, 2, 0), (0, 2, 0, 0), (0, 2, 0, 1), (0, 2, 1, 0), (1, 0, 0, 0), (1, 0, 0, 1), (1, 0, 0, 2), (1, 0, 1, 0), (1, 0, 1, 1), (1, 0, 2, 0), (1, 1, 0, 0), (1, 1, 0, 1), (1, 1, 1, 0), (2, 0, 0, 0), (2, 0, 0, 1), (2, 0, 1, 0), (0, 0, 0, 4), (0, 0, 1, 3), (0, 0, 2, 2), (0, 0, 3, 1), (0, 0, 4, 0), (0, 1, 0, 3), (0, 1, 1, 2), (0, 1, 2, 1), (0, 1, 3, 0), (0, 2, 0, 2), (0, 2, 1, 1), (0, 2, 2, 0), (0, 3, 0, 0), (0, 3, 0, 1), (0, 3, 1, 0), (1, 0, 0, 3), (1, 0, 1, 2), (1, 0, 2, 1), (1, 0, 3, 0), (1, 1, 0, 2), (1, 1, 1, 1), (1, 1, 2, 0), (1, 2, 0, 0), (1, 2, 0, 1), (1, 2, 1, 0), (2, 0, 0, 2), (2, 0, 1, 1), (2, 1, 0, 0), (2, 1, 0, 1), (2, 1, 1, 0), (3, 0, 0, 0), (3, 0, 1, 0), (3, 0, 0, 1), (2, 0, 2, 0), ]) assert set(aux_new) == set(known) stable_aux = aux_update[1] known = map_to_auxvec([ (0, 0, 0, 0), (0, 0, 0, 1), (0, 0, 0, 2), (0, 0, 0, 3), (0, 0, 1, 0), (0, 0, 1, 1), (0, 0, 1, 2), (0, 0, 2, 0), (0, 0, 2, 1), (0, 0, 3, 0), (0, 1, 0, 0), (0, 1, 0, 1), (0, 1, 0, 2), (0, 1, 1, 0), (0, 1, 1, 1), (0, 1, 2, 0), (0, 2, 0, 0), (0, 2, 0, 1), (0, 2, 1, 0), (1, 0, 0, 0), (1, 0, 0, 1), (1, 0, 0, 2), (1, 0, 1, 0), (1, 0, 1, 1), (1, 0, 2, 0), (1, 1, 0, 0), (1, 1, 0, 1), (1, 1, 1, 0), (2, 0, 0, 0), (2, 0, 0, 1), (2, 0, 1, 0), ]) assert set(stable_aux) == set(known) add_aux = aux_update[2] known = map_to_auxvec([ (0, 0, 0, 4), (0, 0, 1, 3), (0, 0, 2, 2), (0, 0, 3, 1), (0, 0, 4, 0), (0, 1, 0, 3), (0, 1, 1, 2), (0, 1, 2, 1), (0, 1, 3, 0), (0, 2, 0, 2), (0, 2, 1, 1), (0, 2, 2, 0), (0, 3, 0, 0), (0, 3, 0, 1), (0, 3, 1, 0), (1, 0, 0, 3), (1, 0, 1, 2), (1, 0, 2, 1), (1, 0, 3, 0), (1, 1, 0, 2), (1, 1, 1, 1), (1, 1, 2, 0), (1, 2, 0, 0), (1, 2, 0, 1), (1, 2, 1, 0), (2, 0, 0, 2), (2, 0, 1, 1), (2, 1, 0, 0), (2, 1, 0, 1), (2, 1, 1, 0), (3, 0, 0, 0), (3, 0, 1, 0), (3, 0, 0, 1), (2, 0, 2, 0), ]) assert set(known) == set(add_aux)