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_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 allclose(a, b, rtol=1.0e-5, atol=1.0e-8): if isinstance(a, Matrix): a = a.array else: a = np.asarray(a) if isinstance(b, Matrix): b = b.array else: b = np.asarray(b) return np.allclose(a, b, rtol=rtol, atol=atol)
def test_ft_abs(model): with open(os.path.join(cur_dir, "abs_ft.npy"), "rb") as fin: standard_value = np.load(fin) # the standard value is plotted over np.arange(0.05, 0.11, 5.e-4) freq_reg = np.arange(0.08, 0.10, 2.e-3).tolist() indx = [0, 2, 4, 6, 8] standard_value = standard_value[indx] test_freq = [freq_reg[idx] for idx in indx] T = Quantity(298, unit='K') # subtract zero point energy for better CG convergence h_mpo = Mpo(model, offset=Quantity(model.gs_zpe)) spectra = SpectraFtCV(model, "abs", 10, 5.e-3, T, h_mpo, rtol=1e-3) result = batch_run(test_freq, 1, spectra) assert np.allclose(result, standard_value, rtol=1.e-2)
def test_zt_abs(method): with open(os.path.join(cur_dir, "abs_zt.npy"), "rb") as fin: standard_value = np.load(fin) # the standard value is plotted over np.arange(0.05, 0.11, 5.e-5) freq_reg = np.arange(0.05, 0.11, 5.e-5).tolist() indx = [300, 680, 800, 900] test_freq = [freq_reg[idx] for idx in indx] standard_value = [ivalue[0][0] for ivalue in standard_value[indx]] spectra = SpectraZtCV(holstein_model, "abs", 10, 5.e-5, method=method, rtol=1e-3) result = batch_run(test_freq, 2, spectra) assert np.allclose(result, standard_value, rtol=1.e-2)
def nearly_zero(self): if backend.is_32bits: atol = 1e-10 else: atol = 1e-20 return np.allclose(self.array, np.zeros_like(self.array), atol=atol)
def check_property(mp): electron_occupation = np.zeros((mol_list.mol_num)) electron_occupation[mol_list.mol_num // 2] = 1 assert mp.norm == pytest.approx(1) assert np.allclose(mp.e_occupations, electron_occupation) assert np.allclose(mp.ph_occupations, np.zeros((mol_list.ph_modes_num)))
h1e = np.random.uniform(-1, 1, size=(spin_norbs, spin_norbs)) h2e = np.random.uniform(-1, 1, size=(spin_norbs, spin_norbs, spin_norbs, spin_norbs)) h1e = 0.5 * (h1e + h1e.T) h2e = 0.5 * (h2e + h2e.transpose((2, 3, 0, 1))) basis, ham_terms = h_qc.qc_model(h1e, h2e) model = Model(basis, ham_terms) mpo = Mpo(model) logger.info(f"mpo_bond_dims:{mpo.bond_dims}") nelec = 10 energy_list = {} M = 50 procedure = [[M, 0.4], [M, 0.2], [M, 0.1], [M, 0], [M, 0], [M, 0], [M, 0]] mps = Mps.random(model, nelec, M, percent=1.0) mps.optimize_config.procedure = procedure mps.optimize_config.method = "2site" energies, mps = gs.optimize_mps(mps.copy(), mpo) gs_e = min(energies) + nuc logger.info(f"lowest energy: {gs_e}") # fci result assert np.allclose(gs_e, -75.008697516450) end = time.time() logger.info(f"time cost {end - start}")