def test_heom(fname=None): ph_dims = list(np.repeat(model.ph_dims, 2)) n_dims = ph_dims if model.bath_dims is None else ph_dims + model.bath_dims print(n_dims) root = tensor_train_template(rho_0, n_dims, rank=rank_heom) leaves = root.leaves() h_list = model.heom_h_list(leaves[0], leaves[1], leaves[2:], beta=beta) solver = MultiLayer(root, h_list) solver.ode_method = 'RK45' solver.cmf_steps = solver.max_ode_steps # use constant mean-field solver.ps_method = 'split' #solver.svd_err = 1.0e-14 # Define the obersevable of interest logger = Logger(filename=prefix + fname, level='info').logger logger2 = Logger(filename=prefix + "en_" + fname, level='info').logger for n, (time, r) in enumerate( solver.propagator( steps=count, ode_inter=dt_unit, split=True, )): # renormalized by the trace of rho norm = np.trace(np.reshape(np.reshape(r.array, (4, -1))[:, 0], (2, 2))) r.set_array(r.array / norm) if n % callback_interval == 0: t = Quantity(time).convert_to(unit='fs').value rho = np.reshape(r.array, (4, -1))[:, 0] logger.info("{} {} {} {} {}".format(t, rho[0], rho[1], rho[2], rho[3])) en = np.trace(np.reshape(rho, (2, 2)) @ model.h) logger2.info('{} {}'.format(t, en)) return
def test_train(fname=None): # Type settings corr = Correlation(k_max=max_terms) corr.symm_coeff = np.diag(corr_dict['s'].toarray()) corr.asymm_coeff = np.diag(corr_dict['a'].toarray()) corr.exp_coeff = np.diag(corr_dict['gamma'].toarray()) corr.delta_coeff = 0.0 # delta_coeff corr.print() n_dims = [max_tier] * max_terms heom = Hierachy(n_dims, H, V, corr) # Adopt TT tensor_train = tensor_train_template(rho_0, n_dims) root = tensor_train[0] leaves_dict = {leaf.name: leaf for leaf in root.leaves()} all_terms = [] for term in heom.diff(): all_terms.append([(leaves_dict[str(fst)], snd) for fst, snd in term]) solver = MultiLayer(root, all_terms) #solver = ProjectorSplitting(root, all_terms) solver.ode_method = 'RK45' solver.snd_order = False solver.atol = 1.e-7 solver.rtol = 1.e-7 solver.ps_method = 'split-unite' projector = np.zeros((max_tier, 1)) projector[0] = 1.0 logger = Logger(filename=fname, level='info').logger for n, (time, _) in enumerate( solver.propagator(steps=count, ode_inter=dt_unit, split=False)): if n % callback_interval == 0: head = root.array for t in tensor_train[1:]: spf = Tensor.partial_product(t.array, 1, projector, 0) head = Tensor.partial_product(head, head.ndim - 1, spf, 0) rho = np.reshape(head, (4, -1))[:, 0] logger.info("{} {} {} {} {}".format(time, rho[0], rho[1], rho[2], rho[3])) return
def test_train(fname=None): # HEOM metas corr.print() n_dims = [max_tier] * max_terms heom = Hierachy(n_dims, H, V, corr) # 2-site TT tensor_train = tensor_train_template(rho_0, n_dims, rank=1) root = tensor_train[0] leaves_dict = {leaf.name: leaf for leaf in root.leaves()} all_terms = [] for term in heom.diff(): all_terms.append([(leaves_dict[str(fst)], snd) for fst, snd in term]) solver = MultiLayer(root, all_terms) solver.ode_method = 'RK45' solver.snd_order = False solver.svd_err = 1.e-8 solver.svd_rank = max_tier solver.ps_method = 'unite' projector = np.zeros((max_tier, 1)) projector[0] = 1.0 logger = Logger(filename=fname, level='info').logger logger2 = Logger(filename=fname + '_norm', level='info').logger for n, (time, _) in enumerate(solver.propagator(steps=count, ode_inter=dt_unit, split=True)): #print('n = {}: '.format(n)) #for t in tensor_train: # print('{}: {}'.format(t, t.shape)) if n % callback_interval == 0: head = root.array for t in tensor_train[1:]: spf = Tensor.partial_product(t.array, 1, projector, 0) head = Tensor.partial_product(head, head.ndim - 1, spf, 0) rho = np.reshape(head, (4, -1))[:, 0] logger2.warning("{} {}".format(time, rho[0] + rho[3])) logger.info("{} {} {} {} {}".format(time, rho[0], rho[1], rho[2], rho[3])) return
def test_drude_train(): eta = 0.05 # reorganization energy (dimensionless) gamma_c = 0.05 # vibrational frequency (dimensionless) max_tier = 10 max_terms = 3 J = pyheom.Drudian(eta, gamma_c) corr_dict = pyheom.noise_decomposition( J, T=1, # temperature (dimensionless) type_LTC='PSD', n_PSD=max_terms - 1, type_PSD='N-1/N') s = corr_dict['s'].toarray() a = corr_dict['a'].toarray() gamma = corr_dict['gamma'].toarray() delta = 0 omega_1 = 0.05 omega_2 = 0.02 H = np.array([[omega_1, omega_2], [omega_2, 0]]) V = np.array([[0, 0], [0, 1]]) corr = Correlation(k_max=max_terms, beta=1) corr.symm_coeff = np.diag(s) corr.asymm_coeff = np.diag(a) corr.exp_coeff = np.diag(gamma) corr.delta_coeff = delta corr.print() heom = Hierachy([max_tier] * max_terms, H, V, corr) rho_0 = np.zeros((2, 2)) rho_0[0, 0] = 1 # TT HEOM tensor_train = tensor_train_template(rho_0, [max_tier] * max_terms, rank=max_tier) root = tensor_train[0] leaves_dict = {leaf.name: leaf for leaf in root.leaves()} all_terms = [] for term in heom.diff(): all_terms.append([(leaves_dict[str(fst)], snd) for fst, snd in term]) solver = MultiLayer(root, all_terms) solver.ode_method = 'RK45' solver.snd_order = False solver.max_ode_steps = 100000 # Define the obersevable of interest projector = np.zeros((max_tier, 1)) projector[0] = 1.0 dat = [] for n, (time, r) in enumerate(solver.propagator( steps=20000, ode_inter=0.01, )): head = root.array for t in tensor_train[1:]: spf = Tensor.partial_product(t.array, 1, projector, 0) head = Tensor.partial_product(head, head.ndim - 1, spf, 0) rho = np.reshape(head, (4, -1))[:, 0] flat_data = [time] + list(rho) dat.append(flat_data) print("Time {} | Pop_1 {} | Total {}".format(time, rho[0], rho[0] + rho[-1])) return np.array(dat)