def test_SCF_exact(self): nexciton= 1 D_value = np.array([0.0, 0.0]) mol = construct_mol(nlevels, D_value=D_value) TDH.construct_Ham_vib(mol) # DMRG calculation procedure = [[40,0.4],[40,0.2],[40,0.1],[40,0],[40,0]] MPS, MPSdim, MPSQN, MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, ephtable, pbond = \ MPSsolver.construct_MPS_MPO_2(mol, J, procedure[0][0], nexciton) energy = MPSsolver.optimization(MPS, MPSdim, MPSQN, MPO, MPOdim, ephtable, pbond, nexciton, procedure, method="2site") dmrg_e = mpslib.dot(MPS, mpslib.mapply(MPO, MPS)) # print occupation dmrg_occ = [] for i in [0,1,2]: MPO, MPOdim = MPSsolver.construct_onsiteMPO(mol,pbond,"a^\dagger a",dipole=False,sitelist=[i]) dmrg_occ.append(mpslib.dot(MPS, mpslib.mapply(MPO, MPS))) print "dmrg_occ", dmrg_occ WFN, Etot = TDH.SCF(mol, J, nexciton) self.assertAlmostEqual(Etot, dmrg_e) fe, fv = 1, 6 HAM, Etot, A_el = TDH.construct_H_Ham(mol, J, nexciton, WFN, fe, fv, debug=True) self.assertAlmostEqual(Etot, dmrg_e) self.assertTrue(np.allclose(A_el.flatten(), dmrg_occ))
def Exact_Spectra_hybrid_TDDMRG_TDH(spectratype, mol, J, MPS, dipoleMPO, WFN, \ nsteps, dt, E_offset=0.): ''' exact spectra by hybrid TDDMRG/TDH approach for ZT abs and emi ''' assert spectratype in ["emi", "abs"] if spectratype == "emi": space = "GS" else: space = "EX" AketMPS = mpslib.mapply(dipoleMPO, MPS) factor = mpslib.norm(AketMPS) AketMPS = mpslib.scale(AketMPS, 1. / factor) AbraMPS = mpslib.add(AketMPS, None) WFN[-1] *= factor WFNbra = copy.deepcopy(WFN) MPOprop, HAM, Etot = ExactPropagator_hybrid_TDDMRG_TDH(mol, J, AketMPS, WFN, -1.0j * dt, space=space) print "TD Etot", Etot autocorr = [] t = 0. for istep in xrange(nsteps): if istep != 0: t += dt WFN[-1] *= np.exp(-1.0j * Etot * dt) AketMPS = mpslib.mapply(MPOprop, AketMPS) TDH.unitary_propagation(HAM, WFN, dt) ft = mpslib.dot(mpslib.conj(AbraMPS), AketMPS) ft *= np.conj(WFNbra[-1]) * WFN[-1] * np.exp(-1.0j * E_offset * t) for iwfn in xrange(len(WFN) - 1): ft *= np.vdot(WFNbra[iwfn], WFN[iwfn]) autocorr.append(ft) autocorr_store(autocorr, istep) return autocorr
def prop(DMMPO, DMH, dt): MPOprop, HAM, Etot = ExactPropagator_hybrid_TDDMRG_TDH(mol, J, \ DMMPO, DMH, -1.0j*dt, space="GS", QNargs=QNargs) DMMPO = mpslib.mapply(DMMPO, MPOprop, QNargs=QNargs) DMH[-1] *= np.exp(-1.0j * Etot * dt) for iham, hamprop in enumerate(HAM): w, v = scipy.linalg.eigh(hamprop) DMH[iham] = DMH[iham].dot(v).dot(np.diag(np.exp(-1.0j * dt * w))).dot(v.T) DMMPO, DMH = hybrid_TDDMRG_TDH(mol, J, DMMPO, DMH, \ -dt, ephtable, thresh=thresh, QNargs=QNargs, TDDMRG_prop_method=TDDMRG_prop_method, normalize=1.0) return DMMPO, DMH
def test_FT_dynamics_hybrid_TDDMRG_TDH(self, value): mol, J = parameter_PBI.construct_mol(4, nphs=value[0]) TDH.construct_Ham_vib(mol, hybrid=True) nexciton = 0 dmrg_procedure = [[20, 0.5], [20, 0.3], [10, 0.2], [5, 0], [1, 0]] MPS, MPSdim, MPSQN, MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, ephtable, pbond = \ MPSsolver.construct_MPS_MPO_2(mol, J, dmrg_procedure[0][0], nexciton) QNargs = [ephtable, False] T = 2000. insteps = 1 iMPS, WFN = hybrid_TDDMRG_TDH.FT_DM_hybrid_TDDMRG_TDH(mol, J, nexciton, T, \ insteps, pbond, ephtable, thresh=1e-3, cleanexciton=nexciton,\ QNargs=QNargs, space="GS") dipoleMPO, dipoleMPOdim = MPSsolver.construct_onsiteMPO(mol, pbond, "a^\dagger",\ QNargs=QNargs, sitelist=[0]) iMPS = mpslib.mapply(dipoleMPO, iMPS, QNargs=QNargs) norm = mpslib.norm(iMPS, QNargs=QNargs) WFN[-1] *= norm iMPS = mpslib.scale(iMPS, 1. / norm, QNargs=QNargs) iMPS = mpslib.MPSdtype_convert(iMPS, QNargs=QNargs) WFN = [wfn.astype(np.complex128) for wfn in WFN[:-1]] + [WFN[-1]] nsteps = 90 dt = 10.0 MPOs = [] for imol in xrange(len(mol)): dipoleMPO, dipoleMPOdim = MPSsolver.construct_onsiteMPO(mol, pbond, "a^\dagger a",\ QNargs=QNargs, sitelist=[imol]) MPOs.append(dipoleMPO) data = hybrid_TDDMRG_TDH.dynamics_hybrid_TDDMRG_TDH(mol, J, iMPS, \ WFN, nsteps, dt, ephtable,thresh=1e-3, \ TDDMRG_prop_method="C_RK4", QNargs=QNargs, property_MPOs=MPOs) with open("std_data/hybrid_TDDMRG_TDH/FT_occ" + str(value[0]) + ".npy", 'rb') as f: std = np.load(f) self.assertTrue(np.allclose(data, std))
def ZeroTcorr_hybrid_TDDMRG_TDH(mol, J, iMPS, dipoleMPO, WFN0, nsteps, dt, ephtable,\ thresh=0., TDDMRG_prop_method="C_RK4", E_offset=0., cleanexciton=None, QNargs=None): ''' ZT linear spectra ''' AketMPS = mpslib.mapply(dipoleMPO, iMPS, QNargs=QNargs) factor = mpslib.norm(AketMPS, QNargs=QNargs) AketMPS = mpslib.scale(AketMPS, 1. / factor, QNargs=QNargs) AbraMPS = mpslib.add(AketMPS, None, QNargs=QNargs) WFN0[-1] *= factor WFNket = copy.deepcopy(WFN0) WFNbra = copy.deepcopy(WFN0) autocorr = [] t = 0.0 for istep in xrange(nsteps): if istep != 0: t += dt if istep % 2 == 1: AketMPS, WFNket = hybrid_TDDMRG_TDH(mol, J, AketMPS, WFNket,\ dt, ephtable, thresh=thresh, cleanexciton=cleanexciton, QNargs=QNargs, \ TDDMRG_prop_method=TDDMRG_prop_method, TDH_prop_method="unitary") else: AbraMPS, WFNbra = hybrid_TDDMRG_TDH(mol, J, AbraMPS, WFNbra,\ -dt, ephtable, thresh=thresh, cleanexciton=cleanexciton, QNargs=QNargs, \ TDDMRG_prop_method=TDDMRG_prop_method, TDH_prop_method="unitary") ft = mpslib.dot(mpslib.conj(AbraMPS, QNargs=QNargs), AketMPS, QNargs=QNargs) ft *= np.conj(WFNbra[-1]) * WFNket[-1] * np.exp(-1.0j * E_offset * t) for iwfn in xrange(len(WFN0) - 1): ft *= np.vdot(WFNbra[iwfn], WFNket[iwfn]) autocorr.append(ft) autocorr_store(autocorr, istep) return autocorr
def FT_DM_hybrid_TDDMRG_TDH(mol, J, nexciton, T, nsteps, pbond, ephtable, \ thresh=0., TDDMRG_prop_method="C_RK4", cleanexciton=None, QNargs=None, space=None): ''' construct the finite temperature density matrix by hybrid TDDMRG/TDH method ''' # initial state infinite T density matrix # TDDMRG if nexciton == 0: DMMPS, DMMPSdim = tMPS.Max_Entangled_GS_MPS(mol, pbond, norm=True, QNargs=QNargs) DMMPO = tMPS.hilbert_to_liouville(DMMPS, QNargs=QNargs) elif nexciton == 1: DMMPO, DMMPOdim = tMPS.Max_Entangled_EX_MPO(mol, pbond, norm=True, QNargs=QNargs) DMMPO = mpslib.MPSdtype_convert(DMMPO, QNargs=QNargs) # TDH DMH = [] nmols = len(mol) for imol in xrange(nmols): for iph in xrange(mol[imol].nphs_hybrid): dim = mol[imol].ph_hybrid[iph].H_vib_indep.shape[0] DMH.append(np.diag([1.0] * dim, k=0)) # the coefficent a DMH.append(1.0) mflib.normalize(DMH) beta = constant.T2beta(T) / 2.0 dbeta = beta / float(nsteps) for istep in xrange(nsteps): if space is None: DMMPO, DMH = hybrid_TDDMRG_TDH(mol, J, DMMPO, DMH, dbeta/1.0j, ephtable, \ thresh=thresh, cleanexciton=cleanexciton, QNargs=QNargs, \ TDDMRG_prop_method=TDDMRG_prop_method, normalize=1.0) else: MPOprop, HAM, Etot = ExactPropagator_hybrid_TDDMRG_TDH(mol, J, \ DMMPO, DMH, -1.0*dbeta, space=space, QNargs=QNargs) DMH[-1] *= np.exp(-1.0 * Etot * dbeta) TDH.unitary_propagation(HAM, DMH, dbeta / 1.0j) DMMPO = mpslib.mapply(MPOprop, DMMPO, QNargs=QNargs) # DMMPO is not normalize in the imaginary time domain MPOnorm = mpslib.norm(DMMPO, QNargs=QNargs) DMMPO = mpslib.scale(DMMPO, 1. / MPOnorm, QNargs=QNargs) DMH[-1] *= MPOnorm # normlize the dm (physical \otimes ancilla) mflib.normalize(DMH) # divided by np.sqrt(partition function) DMH[-1] = 1.0 return DMMPO, DMH
def FiniteT_spectra_TDDMRG_TDH(spectratype, T, mol, J, nsteps, dt, insteps, pbond, ephtable,\ thresh=0., ithresh=1e-4, TDDMRG_prop_method="C_RK4", E_offset=0., QNargs=None): ''' FT linear spectra ''' assert spectratype in ["abs", "emi"] dipoleMPO, dipoleMPOdim = MPSsolver.construct_onsiteMPO(mol, pbond, "a^\dagger", dipole=True, QNargs=QNargs) # construct initial thermal equilibrium density matrix and apply dipole matrix if spectratype == "abs": nexciton = 0 DMMPO, DMH = FT_DM_hybrid_TDDMRG_TDH(mol, J, nexciton, T, insteps, pbond, ephtable, \ thresh=ithresh, TDDMRG_prop_method=TDDMRG_prop_method, QNargs=QNargs, space="GS") DMMPOket = mpslib.mapply(dipoleMPO, DMMPO, QNargs=QNargs) else: nexciton = 1 DMMPO, DMH = FT_DM_hybrid_TDDMRG_TDH(mol, J, nexciton, T, insteps, pbond, ephtable, \ thresh=ithresh, TDDMRG_prop_method=TDDMRG_prop_method, QNargs=QNargs, space=None) if QNargs is not None: dipoleMPO[1] = [[0] * len(impsdim) for impsdim in dipoleMPO[1]] dipoleMPO[3] = 0 DMMPOket = mpslib.mapply(DMMPO, dipoleMPO, QNargs=QNargs) factor = mpslib.norm(DMMPOket, QNargs=QNargs) DMMPOket = mpslib.scale(DMMPOket, 1. / factor, QNargs=QNargs) DMMPObra = mpslib.add(DMMPOket, None, QNargs=QNargs) DMH[-1] *= factor DMHket = copy.deepcopy(DMH) DMHbra = copy.deepcopy(DMH) autocorr = [] t = 0.0 def prop(DMMPO, DMH, dt): MPOprop, HAM, Etot = ExactPropagator_hybrid_TDDMRG_TDH(mol, J, \ DMMPO, DMH, -1.0j*dt, space="GS", QNargs=QNargs) DMMPO = mpslib.mapply(DMMPO, MPOprop, QNargs=QNargs) DMH[-1] *= np.exp(-1.0j * Etot * dt) for iham, hamprop in enumerate(HAM): w, v = scipy.linalg.eigh(hamprop) DMH[iham] = DMH[iham].dot(v).dot(np.diag(np.exp(-1.0j * dt * w))).dot(v.T) DMMPO, DMH = hybrid_TDDMRG_TDH(mol, J, DMMPO, DMH, \ -dt, ephtable, thresh=thresh, QNargs=QNargs, TDDMRG_prop_method=TDDMRG_prop_method, normalize=1.0) return DMMPO, DMH print("Real time dynamics starts!") for istep in xrange(nsteps): print("istep=", istep) if istep != 0: t += dt if istep % 2 == 0: DMMPObra, DMHbra = prop(DMMPObra, DMHbra, dt) else: DMMPOket, DMHket = prop(DMMPOket, DMHket, -dt) ft = mpslib.dot(mpslib.conj(DMMPObra, QNargs=QNargs), DMMPOket, QNargs=QNargs) ft *= np.conj(DMHbra[-1]) * DMHket[-1] for idm in xrange(len(DMH) - 1): ft *= np.vdot(DMHbra[idm], DMHket[idm]) if spectratype == "emi": ft = np.conj(ft) # for emi bra and ket is conjugated ft *= np.exp(-1.0j * E_offset * t) autocorr.append(ft) autocorr_store(autocorr, istep) return autocorr