def test_autocorr(scheme, mollist2): ph = Phonon.simple_phonon(Quantity(1), Quantity(1), 2) mol = Mol(Quantity(0), [ph]) mol_list1 = MolList([mol] * 5, Quantity(1), scheme) if mollist2: mol_list = MolList2.MolList_to_MolList2(mol_list1) else: mol_list = mol_list1 temperature = Quantity(50000, 'K') compress_config = CompressConfig(CompressCriteria.fixed, max_bonddim=24) evolve_config = EvolveConfig(EvolveMethod.tdvp_ps, adaptive=True, guess_dt=0.5, adaptive_rtol=1e-3) ievolve_config = EvolveConfig(EvolveMethod.tdvp_ps, adaptive=True, guess_dt=-0.1j) ac = TransportAutoCorr(mol_list, temperature, compress_config=compress_config, ievolve_config=ievolve_config, evolve_config=evolve_config) ac.evolve(nsteps=5, evolve_time=5) corr_real = ac.auto_corr.real exact_real = get_exact_autocorr(mol_list1, temperature, ac.evolve_times_array).real atol = 1e-2 # direct comparison may fail because of different sign assert np.allclose(corr_real, exact_real, atol=atol) or np.allclose( corr_real, -exact_real, atol=atol)
def __init__(self): super(Mps, self).__init__() # todo: tdh part with GPU backend self.wfns = [1] self.optimize_config: OptimizeConfig = OptimizeConfig() self.evolve_config: EvolveConfig = EvolveConfig()
def test_FT_dynamics_hybrid_TDDMRG_TDH(n_dmrg_phs, scheme): mol_list = parameter_PBI.construct_mol(4, n_dmrg_phs, 10 - n_dmrg_phs).switch_scheme(scheme) mpdm = MpDm.max_entangled_gs(mol_list) tentative_mpo = Mpo(mol_list) temperature = Quantity(2000, "K") tp = ThermalProp(mpdm, tentative_mpo, exact=True, space="GS") tp.evolve(None, 1, temperature.to_beta() / 2j) mpdm = ( Mpo.onsite(mol_list, r"a^\dagger", mol_idx_set={0}).apply(tp.latest_mps).normalize(1.0) ) mpdm.compress_config = CompressConfig(max_bonddim=12) mpdm.evolve_config = EvolveConfig(EvolveMethod.tdvp_ps) offset = mpdm.expectation(tentative_mpo) mpo = Mpo(mol_list, offset=Quantity(offset, "a.u.")) mpdm = mpdm.expand_bond_dimension(mpo) # do the evolution # nsteps = 90 # too many steps, may take hours to finish nsteps = 20 dt = 20.0 occ = [mpdm.e_occupations] for i in range(nsteps): mpdm = mpdm.evolve(mpo, dt) occ.append(mpdm.e_occupations) # make it compatible with std data occ = np.array(occ[:nsteps]).transpose() with open(os.path.join(cur_dir, "FT_occ" + str(n_dmrg_phs) + ".npy"), "rb") as f: std = np.load(f) assert np.allclose(occ[:, :nsteps], std[:, :2*nsteps:2], atol=1e-3, rtol=1e-3)
def test_ZeroTcorr_TDVP(method, evolve_dt, use_rk, rtol): # procedure = [[50, 0], [50, 0], [50, 0]] procedure = [[20, 0], [20, 0], [20, 0]] optimize_config = OptimizeConfig(procedure=procedure) mol_list = parameter.mol_list evolve_config = EvolveConfig(method, evolve_dt=evolve_dt, adaptive=False) evolve_config.tdvp_ps_rk4 = use_rk zero_t_corr = SpectraTwoWayPropZeroT( mol_list, "abs", optimize_config, evolve_config=evolve_config, offset=Quantity(2.28614053, "ev"), ) zero_t_corr.info_interval = 30 nsteps = 200 # nsteps = 1200 zero_t_corr.evolve(evolve_dt, nsteps) with open( os.path.join( cur_dir, "zero_t_%s.npy" % str(evolve_config.method).split(".")[1]), "rb", ) as f: ZeroTabs_std = np.load(f) assert np.allclose(zero_t_corr.autocorr[:nsteps], ZeroTabs_std[:nsteps], rtol=rtol)
def __init__(self, mol_list, temperature: Quantity, insteps: int = None, ievolve_config=None, compress_config=None, evolve_config=None, dump_dir: str = None, job_name: str = None): self.mol_list = mol_list self.h_mpo = Mpo(mol_list) self.j_oper = self._construct_flux_operator() self.temperature = temperature # imaginary time evolution config if ievolve_config is None: self.ievolve_config = EvolveConfig() if insteps is None: self.ievolve_config.adaptive = True # start from a small step self.ievolve_config.evolve_dt = temperature.to_beta() / 1e5j self.ievolve_config.d_energy = 1 else: self.ievolve_config = ievolve_config self.insteps = insteps if compress_config is None: logger.debug("using default compress config") self.compress_config = CompressConfig() else: self.compress_config = compress_config self.impdm = None super().__init__(evolve_config, dump_dir, job_name)
def __init__(self, mol_list, spectratype, temperature, freq_reg, m_max, eta, icompress_config=None, ievolve_config=None, insteps=None, method='1site', procedure_cv=None, dump_dir: str = None, job_name=None, cores=1): super().__init__(mol_list, spectratype, freq_reg, m_max, eta, method, procedure_cv, cores) self.temperature = temperature self.evolve_config = ievolve_config self.compress_config = icompress_config if self.evolve_config is None: self.evolve_config = \ EvolveConfig() if self.compress_config is None: self.compress_config = \ CompressConfig(CompressCriteria.fixed, max_bonddim=m_max) self.compress_config.set_bonddim(len(mol_list.pbond_list)) self.insteps = insteps self.job_name = job_name self.dump_dir = dump_dir
def __init__( self, mol_list, spectratype, temperature, insteps, offset, evolve_config=None, icompress_config=None, ievolve_config=None, gs_shift=0, dump_dir: str = None, job_name=None, ): self.temperature = temperature self.insteps = insteps self.gs_shift = gs_shift self.icompress_config = icompress_config self.ievolve_config = ievolve_config if self.icompress_config is None: self.icompress_config = CompressConfig() if self.ievolve_config is None: self.ievolve_config = EvolveConfig() self.dump_dir = dump_dir self.job_name = job_name super(SpectraFiniteT, self).__init__(mol_list, spectratype, temperature, evolve_config=evolve_config, offset=offset, dump_dir=dump_dir, job_name=job_name)
def test_pyr_4mode(multi_e, dvr): basis, ham_terms = construct_vibronic_model(multi_e, dvr) model = Model(basis, ham_terms) mpo = Mpo(model) logger.info(f"mpo_bond_dims:{mpo.bond_dims}") # same form whether multi_e is True or False init_condition = {"s2": 1} if dvr: for dof in model.v_dofs: idx = model.order[dof] init_condition[dof] = basis[idx].dvr_v[0] mps = Mps.hartree_product_state(model, condition=init_condition) compress_config = CompressConfig(CompressCriteria.fixed, max_bonddim=10) evolve_config = EvolveConfig(EvolveMethod.tdvp_ps) job = VibronicModelDynamics(model, mps0=mps, h_mpo=mpo, compress_config=compress_config, evolve_config=evolve_config, expand=True) time_step_fs = 2 job.evolve(evolve_dt=time_step_fs * fs2au, nsteps=60) from renormalizer.vibronic.tests.mctdh_data import mctdh_data assert np.allclose(mctdh_data[::round(time_step_fs / 0.5)][:61, 1:], job.e_occupations_array, atol=2e-2)
def test_thermal_prop(adaptive, evolve_method): model = parameter.holstein_model init_mps = MpDm.max_entangled_ex(model) mpo = Mpo(model) beta = Quantity(298, "K").to_beta() evolve_time = beta / 2j evolve_config = EvolveConfig(evolve_method, adaptive=adaptive, guess_dt=0.1 / 1j) if adaptive: nsteps = 1 else: nsteps = 100 if evolve_method == EvolveMethod.tdvp_mu_vmf: nsteps = 20 evolve_config.ivp_rtol = 1e-3 evolve_config.ivp_atol = 1e-6 evolve_config.reg_epsilon = 1e-8 init_mps.compress_config.bond_dim_max_value = 12 dbeta = evolve_time / nsteps tp = ThermalProp(init_mps, mpo, evolve_config=evolve_config) tp.evolve(evolve_dt=dbeta, nsteps=nsteps) # MPO, HAM, Etot, A_el = mps.construct_hybrid_Ham(mpo, debug=True) # exact A_el: 0.20896541050347484, 0.35240029674394463, 0.4386342927525734 # exact internal energy: 0.0853388060014744 etot_std = 0.0853388 + parameter.holstein_model.gs_zpe occ_std = [0.20896541050347484, 0.35240029674394463, 0.4386342927525734] rtol = 5e-3 assert np.allclose(tp.e_occupations_array[-1], occ_std, rtol=rtol) assert np.allclose(tp.energies[-1], etot_std, rtol=rtol)
def test_pyr_4mode(multi_e, translator): order, basis, vibronic_model = construct_vibronic_model(multi_e) if translator is ModelTranslator.vibronic_model: model = vibronic_model elif translator is ModelTranslator.general_model: model = vibronic_to_general(vibronic_model) else: assert False mol_list2 = MolList2(order, basis, model, model_translator=translator) mpo = Mpo(mol_list2) logger.info(f"mpo_bond_dims:{mpo.bond_dims}") mps = Mps.hartree_product_state(mol_list2, condition={"e_1": 1}) # for multi-e case the `expand bond dimension` routine is currently not working # because creation operator is not defined yet mps.use_dummy_qn = True mps.build_empty_qn() compress_config = CompressConfig(CompressCriteria.fixed, max_bonddim=10) evolve_config = EvolveConfig(EvolveMethod.tdvp_ps) job = VibronicModelDynamics(mol_list2, mps0=mps, h_mpo=mpo, compress_config=compress_config, evolve_config=evolve_config) time_step_fs = 2 job.evolve(evolve_dt=time_step_fs * fs2au, nsteps=59) from renormalizer.vibronic.tests.mctdh_data import mctdh_data assert np.allclose(mctdh_data[::round(time_step_fs / 0.5)][:, 1:], job.e_occupations_array, atol=5e-2)
def __init__(self, model: Model, temperature: Quantity, distance_matrix: np.ndarray = None, insteps: int=1, ievolve_config=None, compress_config=None, evolve_config=None, dump_dir: str=None, job_name: str=None, properties: Property = None): self.model = model self.distance_matrix = distance_matrix self.h_mpo = Mpo(model) logger.info(f"Bond dim of h_mpo: {self.h_mpo.bond_dims}") self._construct_current_operator() if temperature == 0: raise ValueError("Can't set temperature to 0.") self.temperature = temperature # imaginary time evolution config if ievolve_config is None: self.ievolve_config = EvolveConfig() if insteps is None: self.ievolve_config.adaptive = True # start from a small step self.ievolve_config.guess_dt = temperature.to_beta() / 1e5j insteps = 1 else: self.ievolve_config = ievolve_config self.insteps = insteps if compress_config is None: logger.debug("using default compress config") self.compress_config = CompressConfig() else: self.compress_config = compress_config self.properties = properties self._auto_corr = [] self._auto_corr_deomposition = [] super().__init__(evolve_config=evolve_config, dump_dir=dump_dir, job_name=job_name)
def test_thermal_equilibrium(periodic): if periodic: # define properties # periodic case prop_mpos = ops.e_ph_static_correlation(mol_list, periodic=True) prop_strs = list(prop_mpos.keys()) prop_strs.append("e_rdm") prop = Property(prop_strs, prop_mpos) else: # non-periodic case (though actually periodic) prop_mpos = {} for imol in range(nmols): prop_mpo = ops.e_ph_static_correlation(mol_list, imol=imol) prop_mpos.update(prop_mpo) prop_strs = list(prop_mpos.keys()) prop_strs.append("e_rdm") prop = Property(prop_strs, prop_mpos) beta = Quantity(1500., "K").to_beta() logger.info(f"beta:{beta}") nsteps = 1 dbeta = beta / nsteps / 2j evolve_config = EvolveConfig(method=EvolveMethod.prop_and_compress, adaptive=True, adaptive_rtol=1e-4, guess_dt=0.1/1j) init_mpdm = MpDm.max_entangled_ex(mol_list) #init_mpdm.compress_config.bond_dim_max_value=10 init_mpdm.compress_config.threshold = 1e-4 td = ThermalProp(init_mpdm, mpo, evolve_config=evolve_config, dump_dir=dump_dir, job_name=job_name, properties=prop) td.evolve(dbeta, nsteps=nsteps) if periodic: def combine(local_prop): res = [] for dis in range(nmols): res.append(local_prop.prop_res["S_"+str(dis)+"_0"][-1]) return res else: def combine(local_prop): e_ph_static_corr = [] for dis in range(nmols): res = 0. for i in range(nmols): res = res + np.array(local_prop.prop_res["S_"+str(i)+"_"+str((i+dis)%nmols)+"_0"][-1]) e_ph_static_corr.append(res) return e_ph_static_corr assert np.allclose(td.properties.prop_res["e_rdm"][-1], thermal_std["e_rdm"]) assert np.allclose(combine(td.properties), thermal_std["e_ph_static_corr"]) # directly calculate properties mpdm = td.latest_mps prop.calc_properties(mpdm, None) assert np.allclose(prop.prop_res["e_rdm"][-1], prop.prop_res["e_rdm"][-2])
def test_adaptive_zero_t(method): np.random.seed(0) evolve_config = EvolveConfig(method=method, guess_dt=0.1, adaptive=True) ct = ChargeTransport(band_limit_mol_list, evolve_config=evolve_config, stop_at_edge=True) ct.evolve(evolve_dt=5.) assert_band_limit(ct, 1e-2)
def test_bandlimit_zero_t(method, evolve_dt, nsteps, rtol, scheme): np.random.seed(0) evolve_config = EvolveConfig(method) ct = ChargeTransport(band_limit_mol_list.switch_scheme(scheme), evolve_config=evolve_config) ct.stop_at_edge = True ct.evolve(evolve_dt, nsteps) assert_band_limit(ct, rtol)
def test_dump(method, dt): mps = init_mps.copy() mps.evolve_config = EvolveConfig(method) # dump all matrices mps.compress_config = CompressConfig(CompressCriteria.fixed, dump_matrix_size=1) evolved_mps = check_result(mps, mpo, dt, 5) # check all matrices are actually dumped for mt in evolved_mps._mp: assert isinstance(mt, str)
def test_tdvp_vmf(init_state, with_mu, force_ovlp, atol): mps = init_state.copy() method = EvolveMethod.tdvp_mu_vmf if with_mu else EvolveMethod.tdvp_vmf mps.evolve_config = EvolveConfig(method, ivp_rtol=1e-4, ivp_atol=1e-7, force_ovlp=force_ovlp) mps.evolve_config.vmf_auto_switch = False check_result(mps, mpo, 0.5, 2, atol)
def test_thermal_prop(mol_list, etot_std, occ_std, nsteps, evolve_method, use_rk, rtol): init_mps = MpDm.max_entangled_ex(mol_list) mpo = Mpo(mol_list) beta = Quantity(298, "K").to_beta() evolve_time = beta / 2j if nsteps is None: evolve_config = EvolveConfig(evolve_method, adaptive=True, evolve_dt=beta / 100j) else: evolve_config = EvolveConfig(evolve_method) if evolve_method is EvolveMethod.tdvp_ps: evolve_config.tdvp_ps_rk4 = use_rk tp = ThermalProp(init_mps, mpo, evolve_config=evolve_config) tp.evolve(nsteps=nsteps, evolve_time=evolve_time) mps = tp.latest_mps MPO, HAM, Etot, A_el = mps.construct_hybrid_Ham(mpo, debug=True) assert np.allclose(Etot, etot_std, rtol=rtol) assert np.allclose(A_el, occ_std, rtol=rtol)
def __init__( self, model, spectratype, m_max, eta, temperature, h_mpo=None, method='1site', procedure_cv=None, rtol=1e-5, b_mps=None, cv_mps=None, icompress_config=None, ievolve_config=None, insteps=None, dump_dir: str = None, job_name=None, ): self.temperature = temperature self.evolve_config = ievolve_config self.compress_config = icompress_config if self.evolve_config is None: self.evolve_config = \ EvolveConfig() if self.compress_config is None: self.compress_config = \ CompressConfig(CompressCriteria.fixed, max_bonddim=m_max) self.compress_config.set_bonddim(len(model.pbond_list)) self.insteps = insteps self.job_name = job_name self.dump_dir = dump_dir super().__init__( model, spectratype, m_max, eta, h_mpo=h_mpo, method=method, procedure_cv=procedure_cv, rtol=rtol, b_mps=b_mps, cv_mps=cv_mps, ) self.cv_mpo = self.cv_mps self.b_mpo = self.b_mps self.a_oper = None
def test_sbm_zt(alpha): raw_delta = Quantity(1) raw_omega_c = Quantity(20) n_phonons = 3 mol_list = param2mollist(alpha, raw_delta, raw_omega_c, 5, n_phonons) evolve_config = EvolveConfig(method=EvolveMethod.tdvp_ps, adaptive=True, guess_dt=0.1) sbm = SpinBosonModel(mol_list, Quantity(0), evolve_config=evolve_config) sbm.evolve(nsteps=20, evolve_time=20) spin1 = sbm.sigma_z spin2 = get_exact_zt(mol_list[0], sbm.evolve_times) assert np.allclose(spin1, spin2, atol=1e-3)
def test_ft(): model = get_model() mpo = Mpo(model) impdm = MpDm.max_entangled_gs(model) impdm.compress_config = CompressConfig(threshold=1e-6) temperature = Quantity(3) evolve_config = EvolveConfig(adaptive=True, guess_dt=-0.001j) tp = ThermalProp(impdm, mpo, evolve_config=evolve_config) tp.evolve(nsteps=1, evolve_time=temperature.to_beta() / 2j) mpdm = tp.latest_mps mpdm = Mpo(model, Op("sigma_x", "spin")).contract(mpdm) mpdm.evolve_config = EvolveConfig(adaptive=True, guess_dt=0.1) time_series = [0] sigma_z_oper = Mpo(model, Op("sigma_z", "spin")) spin = [mpdm.expectation(sigma_z_oper)] for i in range(29): dt = mpdm.evolve_config.guess_dt mpdm = mpdm.evolve(mpo, evolve_dt=dt) time_series.append(time_series[-1] + dt) spin.append(mpdm.expectation(sigma_z_oper)) qutip_res = get_qutip_ft(model, temperature, time_series) assert np.allclose(qutip_res, spin, atol=1e-3)
def test_ft(): mol = get_mol() mol_list = MolList([mol], Quantity(0)) mpo = Mpo(mol_list) impdm = MpDm.max_entangled_gs(mol_list) impdm.compress_config = CompressConfig(threshold=1e-6) impdm.use_dummy_qn = True temperature = Quantity(3) evolve_config = EvolveConfig(adaptive=True, guess_dt=-0.001j) tp = ThermalProp(impdm, mpo, evolve_config=evolve_config) tp.evolve(nsteps=1, evolve_time=temperature.to_beta() / 2j) mpdm = tp.latest_mps mpdm = Mpo.onsite(mol_list, r"sigma_x").contract(mpdm) mpdm.evolve_config = EvolveConfig(adaptive=True, guess_dt=0.1) time_series = [0] spin = [1 - 2 * mpdm.e_occupations[0]] for i in range(30): dt = mpdm.evolve_config.guess_dt mpdm = mpdm.evolve(mpo, evolve_dt=dt) time_series.append(time_series[-1] + dt) spin.append(1 - 2 * mpdm.e_occupations[0]) exact = get_exact_ft(mol, temperature, time_series) assert np.allclose(exact, spin, atol=1e-3)
def test_holstein_kubo(scheme): ph = Phonon.simple_phonon(Quantity(1), Quantity(1), 2) mol = Mol(Quantity(0), [ph]) model = HolsteinModel([mol] * 5, Quantity(1), scheme) temperature = Quantity(50000, 'K') compress_config = CompressConfig(CompressCriteria.fixed, max_bonddim=24) evolve_config = EvolveConfig(EvolveMethod.tdvp_ps, adaptive=True, guess_dt=0.5, adaptive_rtol=1e-3) ievolve_config = EvolveConfig(EvolveMethod.tdvp_ps, adaptive=True, guess_dt=-0.1j) kubo = TransportKubo(model, temperature, compress_config=compress_config, ievolve_config=ievolve_config, evolve_config=evolve_config) kubo.evolve(nsteps=5, evolve_time=5) qutip_res = get_qutip_holstein_kubo(model, temperature, kubo.evolve_times_array) rtol = 5e-2 assert np.allclose(kubo.auto_corr, qutip_res, rtol=rtol)
def test_gaussian_bond_dim(): compress_config = CompressConfig( criteria=CompressCriteria.fixed, bonddim_distri=BondDimDistri.center_gauss, max_bonddim=10, ) evolve_config = EvolveConfig(guess_dt=0.1, adaptive=True) ct = ChargeTransport( band_limit_mol_list, compress_config=compress_config, evolve_config=evolve_config, ) ct.stop_at_edge = True ct.evolve(evolve_dt=2.) assert_band_limit(ct, 1e-2)
def test_ft_emi(model): with open(os.path.join(cur_dir, "emi_ft.npy"), "rb") as fin: standard_value = np.load(fin) # the standard value is plotted over np.arange(-0.11, -0.05, 5.e-4) freq_reg = np.arange(-0.11, -0.05, 5.e-4).tolist() test_freq = [freq_reg[52]] T = Quantity(298, unit='K') standard_value = [standard_value[52]] evolve_config = EvolveConfig(method=EvolveMethod.tdvp_ps) compress_config = CompressConfig(criteria=CompressCriteria.fixed, max_bonddim=10) spectra = SpectraFtCV(model, "emi", 10, 5.e-3, T, ievolve_config=evolve_config, icompress_config=compress_config, insteps=10, rtol=1e-3) result = batch_run(test_freq, 1, spectra) assert np.allclose(result, standard_value, rtol=1.e-2)
def compare(): dt_list = [0.01, 0.02, 0.05, 0.1, 0.2, 0.4] method_list = [EvolveMethod.prop_and_compress, EvolveMethod.tdvp_mu_vmf, EvolveMethod.tdvp_mu_cmf, EvolveMethod.tdvp_ps] all_values = [] for method in method_list: values = [] for dt in dt_list: mps = init_mps.copy() mps.compress_config = CompressConfig(CompressCriteria.fixed) mps.evolve_config = EvolveConfig(method) mps.evolve_config._adjust_bond_dim_counter = True mps.evolve_config.force_ovlp = True values.append(check_result(mps, mpo, dt, 2)) print(values) all_values.append(values) print(mps.bond_dims) print(all_values)
def test_sbm_zt(alpha): raw_delta = Quantity(1) raw_omega_c = Quantity(20) n_phonons = 3 mol_list = param2mollist(alpha, raw_delta, raw_omega_c, 5, n_phonons) compress_config = CompressConfig(threshold=1e-4) evolve_config = EvolveConfig(adaptive=True, evolve_dt=0.1) sbm = SpinBosonModel(mol_list, Quantity(0), compress_config=compress_config, evolve_config=evolve_config) sbm.evolve(evolve_time=20) spin1 = sbm.sigma_z spin2 = get_exact_zt(mol_list[0], sbm.evolve_times) assert np.allclose(spin1, spin2, atol=1e-3)
def __init__( self, mol_list, temperature: Quantity, j_oper: Mpo = None, insteps: int = 1, ievolve_config=None, compress_config=None, evolve_config=None, dump_dir: str = None, job_name: str = None, properties: Property = None, ): self.mol_list = mol_list self.h_mpo = Mpo(mol_list) logger.info(f"Bond dim of h_mpo: {self.h_mpo.bond_dims}") if j_oper is None: self.j_oper = self._construct_flux_operator() else: self.j_oper = j_oper self.temperature = temperature # imaginary time evolution config if ievolve_config is None: self.ievolve_config = EvolveConfig() if insteps is None: self.ievolve_config.adaptive = True # start from a small step self.ievolve_config.guess_dt = temperature.to_beta() / 1e5j insteps = 1 else: self.ievolve_config = ievolve_config self.insteps = insteps if compress_config is None: logger.debug("using default compress config") self.compress_config = CompressConfig() else: self.compress_config = compress_config self.properties = properties self._auto_corr = [] super().__init__(evolve_config=evolve_config, dump_dir=dump_dir, job_name=job_name)
def test_zt(): mol = get_mol() mol_list = MolList([mol], Quantity(0)) mps = Mps.gs(mol_list, False) mps.compress_config = CompressConfig(threshold=1e-6) mps.evolve_config = EvolveConfig(adaptive=True, guess_dt=0.1) mps.use_dummy_qn = True mpo = Mpo(mol_list) time_series = [0] spin = [1] for i in range(30): dt = mps.evolve_config.guess_dt mps = mps.evolve(mpo, evolve_dt=dt) time_series.append(time_series[-1] + dt) spin.append(1 - 2 * mps.e_occupations[0]) exact = get_exact_zt(mol, time_series) assert np.allclose(exact, spin, atol=1e-3)
def test_zt(): model = get_model() mps = Mps.ground_state(model, False) mps.compress_config = CompressConfig(threshold=1e-6) mps.evolve_config = EvolveConfig(adaptive=True, guess_dt=0.1) mps.use_dummy_qn = True mpo = Mpo(model) time_series = [0] spin = [1] sigma_z_oper = Mpo(model, Op("sigma_z", "spin")) for i in range(30): dt = mps.evolve_config.guess_dt mps = mps.evolve(mpo, evolve_dt=dt) time_series.append(time_series[-1] + dt) spin.append(mps.expectation(sigma_z_oper)) qutip_res = get_qutip_zt(model, time_series) assert np.allclose(qutip_res, spin, atol=1e-3)
def test_bogoliubov(): # REF: JCP, 2016, 145, 224101 evolve_config = EvolveConfig(EvolveMethod.tdvp_ps) # evolve_config = EvolveConfig() omega = 1 D = 1 nlevel = 10 T = Quantity(1) ph1 = Phonon.simple_phonon(Quantity(omega), Quantity(D), nlevel) mol1 = Mol(Quantity(0), [ph1]) mlist = MolList([mol1] * 2, Quantity(1), scheme=4) mpdm1 = MpDm.max_entangled_gs(mlist) mpdm1.evolve_config = evolve_config mpo1 = Mpo(mlist) tp = ThermalProp(mpdm1, mpo1, exact=True) tp.evolve(nsteps=20, evolve_time=T.to_beta() / 2j) mpdm2 = tp.latest_mps e1 = mpdm2.expectation(mpo1) mpdm3 = (Mpo.onsite(mlist, r"a^\dagger", False, {0}) @ mpdm2).expand_bond_dimension(mpo1) es1 = [mpdm3.e_occupations] for i in range(40): mpdm3 = mpdm3.evolve(mpo1, 0.1) es1.append(mpdm3.e_occupations) theta = np.arctanh(np.exp(-T.to_beta() * omega / 2)) ph2 = Phonon.simple_phonon(Quantity(omega), Quantity(D * np.cosh(theta)), nlevel) ph3 = Phonon.simple_phonon(Quantity(-omega), Quantity(-D * np.sinh(theta)), nlevel) mol2 = Mol(Quantity(0), [ph2, ph3]) mlist2 = MolList([mol2] * 2, Quantity(1), scheme=4) mps1 = Mps.gs(mlist2, False) mps1.evolve_config = evolve_config mpo2 = Mpo(mlist2) e2 = mps1.expectation(mpo2) mps2 = (Mpo.onsite(mlist2, r"a^\dagger", False, {0}) @ mps1).expand_bond_dimension(mpo2) es2 = [mps2.e_occupations] for i in range(20): mps2 = mps2.evolve(mpo2, 0.2) es2.append(mps2.e_occupations) assert np.allclose(es1[::2], es2, atol=5e-3)