def test_reduced_density_matrix( mol_num, j_constant_value, elocalex_value, ph_info, ph_phys_dim, evolve_dt, nsteps, temperature, ): ph_list = [ Phonon.simple_phonon(Quantity(omega, "cm^{-1}"), Quantity(displacement, "a.u."), ph_phys_dim) for omega, displacement in ph_info ] mol_list = MolList([Mol(Quantity(elocalex_value, "a.u."), ph_list)] * mol_num, Quantity(j_constant_value, "eV"), scheme=3) ct = ChargeTransport(mol_list, temperature=Quantity(temperature, "K"), stop_at_edge=False, rdm=True) ct.evolve(evolve_dt, nsteps) for rdm, e in zip(ct.reduced_density_matrices, ct.e_occupations_array): # best we can do? assert np.allclose(np.diag(rdm), e)
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_band_limit_finite_t( mol_num, j_constant_value, elocalex_value, ph_info, ph_phys_dim, evolve_dt, nsteps, scheme, ): ph_list = [ Phonon.simple_phonon(Quantity(omega, "cm^{-1}"), Quantity(displacement, "a.u."), ph_phys_dim) for omega, displacement in ph_info ] mol_list = MolList( [Mol(Quantity(elocalex_value, "a.u."), ph_list)] * mol_num, Quantity(j_constant_value, "eV"), scheme=scheme, ) ct1 = ChargeTransport(mol_list, stop_at_edge=False) ct1.evolve(evolve_dt, nsteps) ct2 = ChargeTransport(mol_list, temperature=low_t, stop_at_edge=False) ct2.evolve(evolve_dt, nsteps) assert ct1.is_similar(ct2)
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_zt_init_state(): ph = Phonon.simple_phonon(Quantity(1), Quantity(1), 10) mol_list = MolList([Mol(Quantity(0), [ph])], Quantity(0), scheme=3) mpo = Mpo(mol_list) mps = Mps.random(mol_list, 1, 10) optimize_mps(mps, mpo) ct = ChargeTransport(mol_list) assert mps.angle(ct.latest_mps) == pytest.approx(1)
def test_similar(mol_num, j_constant_value, elocalex_value, ph_info, ph_phys_dim, evolve_dt, nsteps): ph_list = [ Phonon.simple_phonon(Quantity(omega, "cm^{-1}"), Quantity(displacement, "a.u."), ph_phys_dim) for omega, displacement in ph_info ] mol_list = MolList([Mol(Quantity(elocalex_value, "a.u."), ph_list)] * mol_num, Quantity(j_constant_value, "eV"), scheme=3) ct1 = ChargeTransport(mol_list) ct1.evolve(evolve_dt, nsteps) ct2 = ChargeTransport(mol_list) ct2.evolve(evolve_dt + 1e-5, nsteps) assert ct1.is_similar(ct2)
def test_ft_init_state(): ph = Phonon.simple_phonon(Quantity(1), Quantity(1), 10) mol_list = MolList([Mol(Quantity(0), [ph])], Quantity(0), scheme=3) temperature = Quantity(0.1) mpo = Mpo(mol_list) init_mpdm = MpDm.max_entangled_ex(mol_list) tp = ThermalProp(init_mpdm, mpo, space="EX", exact=True) tp.evolve(nsteps=20, evolve_time=temperature.to_beta() / 2j) ct = ChargeTransport(mol_list, temperature=temperature) tp_mpdm = MpDmFull.from_mpdm(tp.latest_mps) ct_mpdm = MpDmFull.from_mpdm(ct.latest_mps) assert tp_mpdm.angle(ct_mpdm) == pytest.approx(1)
def test_scheme4_finite_t(mol_num, j_constant_value, elocalex_value, ph_info, ph_phys_dim, evolve_dt, nsteps): temperature = Quantity(1, "a.u.") ph_list = [ Phonon.simple_phonon(Quantity(omega, "cm^{-1}"), Quantity(displacement, "a.u."), ph_phys_dim) for omega, displacement in ph_info ] mol_list = MolList([Mol(Quantity(elocalex_value, "a.u."), ph_list)] * mol_num, Quantity(j_constant_value, "eV")) ct1 = ChargeTransport(mol_list.switch_scheme(3), temperature=temperature, stop_at_edge=False) ct1.evolve(evolve_dt, nsteps) ct2 = ChargeTransport(mol_list.switch_scheme(4), temperature=temperature, stop_at_edge=False) ct2.evolve(evolve_dt, nsteps) assert ct1.is_similar(ct2, rtol=1e-2)
def test_reduced_density_matrix( mol_num, j_constant_value, elocalex_value, ph_info, ph_phys_dim, evolve_dt, nsteps, temperature, ): ph_list = [ Phonon.simple_phonon(Quantity(omega, "cm^{-1}"), Quantity(displacement, "a.u."), ph_phys_dim) for omega, displacement in ph_info ] mol_list3 = MolList( [Mol(Quantity(elocalex_value, "a.u."), ph_list)] * mol_num, Quantity(j_constant_value, "eV"), scheme=3, ) ct3 = ChargeTransport(mol_list3, temperature=Quantity(temperature, "K"), stop_at_edge=False, rdm=True) ct3.evolve(evolve_dt, nsteps) mol_list4 = mol_list3.switch_scheme(4) ct4 = ChargeTransport(mol_list4, temperature=Quantity(temperature, "K"), stop_at_edge=False, rdm=True) ct4.evolve(evolve_dt, nsteps) for rdm3, rdm4, e in zip(ct3.reduced_density_matrices, ct4.reduced_density_matrices, ct3.e_occupations_array): assert np.allclose(rdm3, rdm4, atol=1e-3) assert np.allclose(np.diag(rdm3), e)
lams = hr_factors * omegas_au phonons = [ Phonon.simplest_phonon(Quantity(o), Quantity(l), lam=True) for o, l in zip(omegas_au, lams) ] j_matrix_au = j_matrix_cm * cm2au mlist = [] for j in np.diag(j_matrix_au): m = Mol(Quantity(j), phonons) mlist.append(m) # starts from 1 mol_arangement = np.array([7, 5, 3, 1, 2, 4, 6]) - 1 mol_list = MolList(list(np.array(mlist)[mol_arangement]), j_matrix_au[mol_arangement][:, mol_arangement]) evolve_dt = 40 evolve_config = EvolveConfig(evolve_dt=evolve_dt) compress_config = CompressConfig(CompressCriteria.fixed, max_bonddim=16) ct = ChargeTransport(mol_list, evolve_config=evolve_config, compress_config=compress_config) ct.dump_dir = "./fmo" ct.job_name = 'hybrid' ct.stop_at_edge = False ct.evolve(evolve_dt=evolve_dt, nsteps=10) new_evolve_config = EvolveConfig(EvolveMethod.tdvp_mctdh_new) ct.latest_mps.evolve_config = ct.evolve_config = new_evolve_config ct.evolve(evolve_dt=evolve_dt, nsteps=100000)
if __name__ == "__main__": if len(sys.argv) != 2: print("No or more than one parameter file are provided, abort") exit(1) parameter_path = sys.argv[1] with open(parameter_path) as fin: param = yaml.safe_load(fin) log.register_file_output( os.path.join(param["output dir"], param["fname"] + ".log"), "w") mol_list, temperature = load_from_dict(param, 3, False) compress_config = CompressConfig(threshold=1e-4) evolve_config = EvolveConfig(adaptive=True, evolve_dt=2) ct = ChargeTransport( mol_list, temperature=temperature, compress_config=compress_config, evolve_config=evolve_config, rdm=False, ) # ct.stop_at_edge = True # ct.memory_limit = 2 ** 30 # 1 GB # ct.memory_limit /= 10 # 100 MB ct.dump_dir = param["output dir"] ct.job_name = param["fname"] ct.custom_dump_info["comment"] = param["comment"] # ct.latest_mps.compress_add = True logger.debug(f"ground energy of the Hamiltonian: {ct.mpo_e_lbound:g}") ct.evolve(param.get("evolve dt"), param.get("nsteps"), param.get("evolve time")) # ct.evolve(evolve_dt, 100, param.get("evolve time"))
hr_factors *= TOTAL_HR / hr_factors.sum() lams = hr_factors * omegas_au phonons = [ Phonon.simplest_phonon(Quantity(o), Quantity(l), lam=True) for o, l in zip(omegas_au, lams) ] j_matrix_au = j_matrix_cm * cm2au mlist = [] for j in np.diag(j_matrix_au): m = Mol(Quantity(j), phonons) mlist.append(m) # starts from 1 mol_arangement = np.array([7, 5, 3, 1, 2, 4, 6]) - 1 mol_list = MolList(list(np.array(mlist)[mol_arangement]), j_matrix_au[mol_arangement][:, mol_arangement]) evolve_dt = 160 evolve_config = EvolveConfig(EvolveMethod.tdvp_ps, guess_dt=evolve_dt) compress_config = CompressConfig(CompressCriteria.fixed, max_bonddim=32) ct = ChargeTransport(mol_list, evolve_config=evolve_config, compress_config=compress_config, init_electron=InitElectron.fc) ct.dump_dir = "./" ct.job_name = 'fmo' ct.stop_at_edge = False ct.evolve(evolve_dt=evolve_dt, evolve_time=40000)
def test_evolve(mol_num, j_constant_value, elocalex_value, ph_info, ph_phys_dim, evolve_dt, nsteps): ph_list = [ Phonon.simple_phonon(Quantity(omega, "cm^{-1}"), Quantity(displacement, "a.u."), ph_phys_dim) for omega, displacement in ph_info ] mol_list = MolList( [Mol(Quantity(elocalex_value, "a.u."), ph_list)] * mol_num, Quantity(j_constant_value, "eV"), scheme=3, ) ct1 = ChargeTransport(mol_list, stop_at_edge=False) half_nsteps = nsteps // 2 ct1.evolve(evolve_dt, half_nsteps) ct1.evolve(evolve_dt, nsteps - half_nsteps) ct2 = ChargeTransport(mol_list, stop_at_edge=False) ct2.evolve(evolve_dt, nsteps) assert ct1.is_similar(ct2) assert_iterable_equal(ct1.get_dump_dict(), ct2.get_dump_dict()) # test dump ct2.dump_dir = "." ct2.job_name = "test" ct2.dump_dict() os.remove("test.npz")
def test_32backend(switch_to_32backend): evolve_config = EvolveConfig(evolve_dt=4, adaptive=True) ct = ChargeTransport(band_limit_mol_list, evolve_config=evolve_config) ct.stop_at_edge = True ct.evolve() assert_band_limit(ct, 1e-2)
def test_compress_add(mol_num, j_constant_value, elocalex_value, ph_info, ph_phys_dim, evolve_dt, nsteps): ph_list = [ Phonon.simple_phonon(Quantity(omega, "cm^{-1}"), Quantity(displacement, "a.u."), ph_phys_dim) for omega, displacement in ph_info ] mol_list = MolList([Mol(Quantity(elocalex_value, "a.u."), ph_list)] * mol_num, Quantity(j_constant_value, "eV"), scheme=3) ct1 = ChargeTransport(mol_list, temperature=Quantity(298, "K")) ct1.reduced_density_matrices = None ct1.evolve(evolve_dt, nsteps) ct2 = ChargeTransport(mol_list, temperature=Quantity(298, "K")) ct2.reduced_density_matrices = None ct2.latest_mps.compress_add = True ct2.evolve(evolve_dt, nsteps) assert ct1.is_similar(ct2, rtol=1e-2)