def test_zero_t_abs(algorithm, compress_method, ph_info, rtol, switch_to_64backend): np.random.seed(0) # print "data", value procedure = [[1, 0], [1, 0], [1, 0]] optimize_config = OptimizeConfig() optimize_config.procedure = procedure mol_list = parameter.custom_mol_list(None, *ph_info) if algorithm == 1: SpectraZeroT = SpectraOneWayPropZeroT else: SpectraZeroT = SpectraTwoWayPropZeroT zero_t_corr = SpectraZeroT( mol_list.switch_scheme(2), "abs", optimize_config, offset=parameter.offset ) zero_t_corr.info_interval = 30 nsteps = 100 dt = 30.0 zero_t_corr.evolve(dt, nsteps) with open( os.path.join( cur_dir, "ZeroTabs_" + str(algorithm) + str(compress_method) + ".npy" ), "rb", ) as f: std = np.load(f) assert np.allclose(zero_t_corr.autocorr[:nsteps], std[:nsteps], rtol=rtol)
def test_zero_t_abs_mposcheme3( algorithm, compress_method, ph_info, rtol, switch_to_64backend ): np.random.seed(0) # print "data", value j_matrix = ( np.array([[0.0, -0.1, 0.0], [-0.1, 0.0, -0.3], [0.0, -0.3, 0.0]]) / constant.au2ev ) procedure = [[1, 0], [1, 0], [1, 0]] mol_list = parameter.custom_mol_list(j_matrix, *ph_info) nsteps = 50 dt = 30.0 if algorithm == 1: SpectraZeroT = SpectraOneWayPropZeroT else: SpectraZeroT = SpectraTwoWayPropZeroT optimize_config = OptimizeConfig() optimize_config.procedure = procedure zero_t_corr2 = SpectraZeroT( mol_list, "abs", optimize_config, offset=parameter.offset ) zero_t_corr2.evolve(dt, nsteps) zero_t_corr3 = SpectraZeroT( mol_list.switch_scheme(3), "abs", optimize_config, offset=parameter.offset ) zero_t_corr3.evolve(dt, nsteps) assert np.allclose(zero_t_corr2.autocorr, zero_t_corr3.autocorr, rtol=rtol)
def test_zero_t_abs(algorithm): np.random.seed(0) # print "data", value procedure = [[1, 0], [1, 0], [1, 0]] optimize_config = OptimizeConfig() optimize_config.procedure = procedure model = parameter.holstein_model if algorithm == 1: SpectraZeroT = SpectraOneWayPropZeroT else: SpectraZeroT = SpectraTwoWayPropZeroT zero_t_corr = SpectraZeroT(model.switch_scheme(2), "abs", optimize_config, offset=parameter.offset) zero_t_corr.info_interval = 30 nsteps = 100 dt = 30.0 zero_t_corr.evolve(dt, nsteps) with open( os.path.join(cur_dir, "ZeroTabs_" + str(algorithm) + "svd.npy"), "rb", ) as f: std = np.load(f) assert np.allclose(zero_t_corr.autocorr[:nsteps], std[:nsteps], rtol=1e-2)
def init_b_mps(self): # get the right hand site vector b, Ax=b # b = -eta * dipole * \psi_0 # only support Holstine model 0/1 exciton manifold if self.spectratype == "abs": nexciton = 0 dipoletype = r"a^\dagger" elif self.spectratype == "emi": nexciton = 1 dipoletype = "a" # procedure for ground state calculation if self.procedure_gs is None: self.procedure_gs = \ [[10, 0.4], [20, 0.2], [30, 0.1], [40, 0], [40, 0]] # ground state calculation mps = Mps.random( self.model, nexciton, self.procedure_gs[0][0], percent=1.0) mps.optimize_config = OptimizeConfig(procedure=self.procedure_gs) mps.optimize_config.method = "2site" energies, mps = gs.optimize_mps(mps, self.h_mpo) e0 = min(energies) dipole_mpo = \ Mpo.onsite( self.model, dipoletype, dipole=True ) b_mps = dipole_mpo.apply(mps.scale(-self.eta)) return b_mps, e0
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_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, model, spectratype, temperature=Quantity(0, "K"), optimize_config=None, offset=Quantity(0), ex_shift=0, gs_shift=0, ): # != 0 cases not tested assert ex_shift == gs_shift == 0 assert temperature == 0 if spectratype == "emi": self.space1 = "EX" self.space2 = "GS" self.shift1 = ex_shift self.shift2 = gs_shift if temperature != 0: assert len(model) == 1 else: assert len(model) == 1 self.space1 = "GS" self.space2 = "EX" self.shift1 = gs_shift self.shift2 = ex_shift if optimize_config is None: optimize_config = OptimizeConfig() self.optimize_config = optimize_config super(SpectraExact, self).__init__(model, spectratype, temperature, offset=offset) self.i_mps = self.latest_mps.ket_mps self.e_mean = self.i_mps.expectation(self.h_mpo)
def __init__( self, model, spectratype, optimize_config=None, evolve_config=None, offset=Quantity(0), ): if optimize_config is None: self.optimize_config = OptimizeConfig() else: self.optimize_config = optimize_config super(SpectraZeroT, self).__init__(model, spectratype, Quantity(0), evolve_config, offset)
def init_oper(self): if self.spectratype == "abs": self.nexciton = 0 dipoletype = r"a^\dagger" else: self.nexciton = 1 dipoletype = "a" dipole_mpo = \ Mpo.onsite( self.mol_list, dipoletype, dipole=True ) mps, self.mpo = \ construct_mps_mpo_2( self.mol_list, self.procedure_gs[0][0], self.nexciton ) # ground state calculation mps.optimize_config = OptimizeConfig(procedure=self.procedure_gs) mps.optimize_config.method = "2site" self.lowest_e = optimize_mps(mps, self.mpo) ket_mps = dipole_mpo.apply(mps, canonicalise=True) self.b_oper = ket_mps.scale(-self.eta)