def test_ZeroTcorr_hybrid_TDDMRG_TDH_emi(self, value): TDH.construct_Ham_vib(value[0], hybrid=True) nexciton = 1 niterations = 20 MPS, MPSdim, MPSQN, MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, ephtable, pbond = \ MPSsolver.construct_MPS_MPO_2(value[0], J, dmrg_procedure[0][0], nexciton) MPS, MPSQN, WFN, Etot = hybrid_TDDMRG_TDH.hybrid_DMRG_H_SCF(value[0], J, \ nexciton, dmrg_procedure, 20, DMRGthresh=1e-5, Hthresh=1e-5) iMPS = [MPS, MPSQN, len(MPS) - 1, 1] QNargs = [ephtable, False] dipoleMPO, dipoleMPOdim = MPSsolver.construct_onsiteMPO(value[0], pbond, "a", dipole=True, QNargs=QNargs) nsteps = 1000 dt = 30.0 iMPS = mpslib.MPSdtype_convert(iMPS, QNargs=QNargs) WFN = [wfn.astype(np.complex128) for wfn in WFN[:-1]] + [WFN[-1]] autocorr = hybrid_TDDMRG_TDH.ZeroTcorr_hybrid_TDDMRG_TDH(value[0], J, iMPS, dipoleMPO, \ WFN, nsteps, dt, ephtable,thresh=1e-3, TDDMRG_prop_method="C_RK4", QNargs=QNargs) with open(value[1], 'rb') as f: hybrid_ZTemi_prop_std = np.load(f)[:nsteps] self.assertTrue( np.allclose(autocorr, hybrid_ZTemi_prop_std, rtol=value[2]))
def test_Exact_Spectra_hybrid_TDDMRG_TDH(self, value): TDH.construct_Ham_vib(value[0], hybrid=True) nexciton = 1 niterations = 20 MPS, MPSdim, MPSQN, MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, ephtable, pbond = \ MPSsolver.construct_MPS_MPO_2(value[0], J, dmrg_procedure[0][0], nexciton) MPS, MPSQN, WFN, Etot = hybrid_TDDMRG_TDH.hybrid_DMRG_H_SCF(value[0], J, \ nexciton, dmrg_procedure, 20, DMRGthresh=1e-5, Hthresh=1e-5) dipoleMPO, dipoleMPOdim = MPSsolver.construct_onsiteMPO(value[0], pbond, "a", dipole=True) nsteps = 3000 dt = 30.0 MPS = mpslib.MPSdtype_convert(MPS) WFN = [wfn.astype(np.complex128) for wfn in WFN[:-1]] + [WFN[-1]] autocorr = hybrid_TDDMRG_TDH.Exact_Spectra_hybrid_TDDMRG_TDH("emi", value[0], J, MPS, \ dipoleMPO, WFN, nsteps, dt) with open(value[1], 'rb') as f: hybrid_ZTemi_exact_std = np.load(f) self.assertTrue( np.allclose(autocorr, hybrid_ZTemi_exact_std, rtol=value[2]))
def hybrid_TDDMRG_TDH(mol, J, MPS, WFN, dt, ephtable, thresh=0.,\ cleanexciton=None, QNargs=None, TDDMRG_prop_method="C_RK4", TDH_prop_method="unitary", normalize=1.0): ''' hybrid TDDMRG and TDH solver 1.gauge is g_k = 0 ''' # construct Hamiltonian if QNargs is None: MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, HAM, Etot = construct_hybrid_Ham( mol, J, MPS, WFN) else: MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, HAM, Etot = construct_hybrid_Ham( mol, J, MPS[0], WFN) MPO = [MPO, MPOQN, MPOQNidx, MPOQNtot] print "Etot", Etot # EOM of coefficient a WFN[-1] *= np.exp(Etot / 1.0j * dt) # EOM of TDDMRG tableau = RK.runge_kutta_explicit_tableau(TDDMRG_prop_method) propagation_c = RK.runge_kutta_explicit_coefficient(tableau) MPS = tMPS.tMPS(MPS, MPO, dt, ephtable, propagation_c, thresh=thresh, \ cleanexciton=cleanexciton, QNargs=QNargs, normalize=normalize) # EOM of TDH # here if TDH also use RK4, then the TDDMRG part should be changed to get # t=t_1, t=t_2... wfn and slope k if TDH_prop_method == "unitary": TDH.unitary_propagation(HAM, WFN, dt) return MPS, WFN
def test_1mol_ZTabs(self): nmols = 1 J = np.zeros([1,1]) mol = [] for imol in xrange(nmols): mol_local = obj.Mol(elocalex, nphs, dipole_abs) mol_local.create_ph(phinfo) mol.append(mol_local) TDH.construct_Ham_vib(mol) nexciton = 0 # TDH WFN, Etot = TDH.SCF(mol, J, nexciton) print "SCF Etot", Etot nsteps = 1000 dt = 30.0 fe, fv = 1, 2 WFN = [wfn.astype(np.complex128) for wfn in WFN[:-1]]+[WFN[-1]] E_offset = -mol[0].elocalex-mol[0].e0 WFN0 = copy.deepcopy(WFN) autocorr = TDH.linear_spectra("abs", mol, J, nexciton, WFN0, dt, nsteps, fe, fv, E_offset=E_offset, prop_method="unitary") with open("std_data/tMPS/1mol_ZTabs.npy", 'rb') as f: mol1_ZTabs_std = np.load(f) self.assertTrue(np.allclose(autocorr,mol1_ZTabs_std))
def test_DM_hybrid_TDDMRG_TDH(self, value): TDH.construct_Ham_vib(value[0], hybrid=True) T = 298. nexciton = 1 nsteps = 100 MPS, MPSdim, MPSQN, HMPO, HMPOdim, HMPOQN, HMPOQNidx, HMPOQNtot, ephtable, pbond = \ MPSsolver.construct_MPS_MPO_2(value[0], J, dmrg_procedure[0][0], nexciton) QNargs = [ephtable, False] #QNargs = None MPS, DMH = hybrid_TDDMRG_TDH.FT_DM_hybrid_TDDMRG_TDH(value[0], J, nexciton, T, \ nsteps, pbond, ephtable, thresh=1e-3, cleanexciton=1, QNargs=QNargs) if QNargs is not None: MPS = MPS[0] MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, HAM, Etot, A_el = \ hybrid_TDDMRG_TDH.construct_hybrid_Ham(value[0], J, MPS, DMH, debug=True) self.assertAlmostEqual(Etot, value[1]) occ_std = np.array(value[2]) self.assertTrue(np.allclose(A_el, occ_std))
def test_FT_spectra(self, value): T = 298. insteps = 50 nsteps = 300 dt = 30.0 fe, fv = 1, 6 if value[1] == "emi": E_offset = 2.28614053 / constant.au2ev nexciton = 1 elif value[1] == "abs": E_offset = -2.28614053 / constant.au2ev nexciton = 0 D_value = np.array(value[0]) mol = construct_mol(nlevels, D_value=D_value) TDH.construct_Ham_vib(mol) DM = TDH.FT_DM(mol, J, nexciton, T, insteps) autocorr = TDH.linear_spectra(value[1], mol, J, nexciton, DM, dt, nsteps, fe, fv, E_offset=E_offset, T=T) with open(value[2], 'rb') as f: std = np.load(f) self.assertTrue(np.allclose(autocorr, std))
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 test_FiniteT_spectra_TDDMRG_TDH(self, value): TDH.construct_Ham_vib(value[0], hybrid=True) T = 298. insteps = 50 dt = 30. nsteps = 300 if value[1] == "abs": E_offset = -2.28614053 / constant.au2ev nexciton = 0 else: E_offset = 2.28614053 / constant.au2ev nexciton = 1 MPS, MPSdim, MPSQN, HMPO, HMPOdim, HMPOQN, HMPOQNidx, HMPOQNtot, ephtable, pbond = \ MPSsolver.construct_MPS_MPO_2(value[0], J, dmrg_procedure[0][0], nexciton) QNargs = [ephtable, False] #QNargs = None autocorr = hybrid_TDDMRG_TDH.FiniteT_spectra_TDDMRG_TDH(value[1], T, value[0], J, nsteps, \ dt, insteps, pbond, ephtable, thresh=1e-3, ithresh=1e-3, E_offset=E_offset, QNargs=QNargs) with open(value[2], 'rb') as f: std = np.load(f) self.assertTrue(np.allclose(autocorr, std))
def test_hybrid_DMRG_H_SCF(self, value): TDH.construct_Ham_vib(value[0], hybrid=True) nexciton = 1 niterations = 20 MPS, MPSQN, WFN, Etot = hybrid_TDDMRG_TDH.hybrid_DMRG_H_SCF(value[0], J, \ nexciton, dmrg_procedure, 20, DMRGthresh=1e-5, Hthresh=1e-5) print "Etot", Etot self.assertAlmostEqual(Etot, value[1]) nexciton = 0 niterations = 20 MPS, MPSQN, WFN, Etot = hybrid_TDDMRG_TDH.hybrid_DMRG_H_SCF(value[0], J, \ nexciton, dmrg_procedure, 20, DMRGthresh=1e-5, Hthresh=1e-5) print "Etot", Etot self.assertAlmostEqual(Etot, 0.0)
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 test_FT_DM(self): TDH.construct_Ham_vib(mol) # TDH nexciton = 1 T = 298 insteps = 100 DM = TDH.FT_DM(mol, J, nexciton, T, insteps) fe, fv = 1, 6 HAM, Etot, A_el = TDH.construct_H_Ham(mol, J, nexciton, DM, fe, fv, particle="hardcore boson", debug=True) self.assertAlmostEqual(Etot, 0.0856330141528) occ_std = np.array([[0.20300487], [0.35305247], [0.44394266]]) self.assertTrue(np.allclose(A_el, occ_std))
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 test_SCF(self): TDH.construct_Ham_vib(mol) # EX nexciton= 1 WFN, Etot = TDH.SCF(mol, J, nexciton) self.assertAlmostEqual(Etot, 0.0843103276663) fe, fv = 1, 6 HAM, Etot, A_el = TDH.construct_H_Ham(mol, J, nexciton, WFN, fe, fv, debug=True) self.assertAlmostEqual(Etot, 0.0843103276663) occ_std = np.array([[0.20196397], [0.35322702],[0.444809]]) self.assertTrue(np.allclose(A_el, occ_std)) # GS nexciton= 0 WFN, Etot = TDH.SCF(mol, J, nexciton) self.assertAlmostEqual(Etot, 0.0) fe, fv = 1, 6 HAM, Etot, A_el = TDH.construct_H_Ham(mol, J, nexciton, WFN, fe, fv, debug=True) self.assertAlmostEqual(Etot, 0.0) occ_std = np.array([[0.0], [0.0],[0.0]]) self.assertTrue(np.allclose(A_el, occ_std))
def test_TDH_ZT_emi(self): TDH.construct_Ham_vib(mol) nexciton= 1 WFN, Etot = TDH.SCF(mol, J, nexciton) nsteps = 3000 dt = 30.0 fe, fv = 1, 6 WFN = [wfn.astype(np.complex128) for wfn in WFN[:-1]]+[WFN[-1]] WFN0 = copy.deepcopy(WFN) autocorr = TDH.linear_spectra("emi", mol, J, nexciton, WFN0, dt, nsteps, fe, fv, prop_method="unitary") with open("std_data/TDH/TDH_ZT_emi_prop1.npy", 'rb') as f: TDH_ZT_emi_prop1_std = np.load(f) self.assertTrue(np.allclose(autocorr,TDH_ZT_emi_prop1_std)) WFN0 = copy.deepcopy(WFN) autocorr = TDH.linear_spectra("emi", mol, J, nexciton, WFN0, dt, nsteps, fe, fv, prop_method="C_RK4") with open("std_data/TDH/TDH_ZT_emi_RK4.npy", 'rb') as f: TDH_ZT_emi_RK4_std = np.load(f) self.assertTrue(np.allclose(autocorr,TDH_ZT_emi_RK4_std))
def test_FT_dynamics_TDH(self): mol, J = parameter_PBI.construct_mol(4, nphs=10) TDH.construct_Ham_vib(mol, hybrid=False) nexciton = 0 T = 2000 insteps = 1 DM = TDH.FT_DM(mol, J, nexciton, T, insteps) Os = [] for imol in xrange(len(mol)): dipoleO = TDH.construct_onsiteO(mol, "a^\dagger a", dipole=False, sitelist=[imol]) Os.append(dipoleO) dipoleO = TDH.construct_onsiteO(mol, "a^\dagger", dipole=True, sitelist=[0]) DM[0] = dipoleO.dot(DM[0]) mflib.normalize(DM) nsteps = 300 dt = 10.0 fe, fv = 1, 40 data = TDH.dynamics_TDH(mol, J, 1, DM, dt, nsteps, fe, fv, property_Os=Os) with open("std_data/TDH/FT_occ10.npy", 'rb') as f: std = np.load(f) self.assertTrue(np.allclose(data, std))
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 test_1mol_Exact_Spectra_hybrid_TDDMRG_TDH(self, value): nmols = 1 J = np.zeros([1, 1]) if value[0] == "pure": nphs = 2 phinfo = [list(a) for a in zip(omega, D, nlevels)] mol = [] for imol in xrange(nmols): mol_local = obj.Mol(elocalex, nphs, dipole_abs) mol_local.create_ph(phinfo) mol.append(mol_local) elif value[0] == "hybrid": nphs = 1 nphs_hybrid = 1 phinfo_hybrid = [ list(a) for a in zip(omega[:nphs], D[:nphs], nlevels[:nphs]) ] phinfo = [ list(a) for a in zip(omega[nphs:], D[nphs:], nlevels[nphs:]) ] mol = [] for imol in xrange(nmols): mol_local = obj.Mol(elocalex, nphs, dipole_abs, nphs_hybrid=nphs_hybrid) mol_local.create_ph(phinfo) mol_local.create_ph(phinfo_hybrid, phtype="hybrid") mol.append(mol_local) TDH.construct_Ham_vib(mol, hybrid=True) nexciton = 0 dmrg_procedure = [[10, 0.4], [20, 0.2], [30, 0.1], [40, 0], [40, 0]] MPS, MPSdim, MPSQN, HMPO, HMPOdim, HMPOQN, HMPOQNidx, HMPOQNtot, ephtable, pbond \ = MPSsolver.construct_MPS_MPO_2(mol, J, dmrg_procedure[0][0], nexciton) MPS, MPSQN, WFN, Etot = hybrid_TDDMRG_TDH.hybrid_DMRG_H_SCF(mol, J, \ nexciton, dmrg_procedure, 20, DMRGthresh=1e-5, Hthresh=1e-5) dipoleMPO, dipoleMPOdim = MPSsolver.construct_onsiteMPO(mol, pbond, "a^\dagger", dipole=True) nsteps = 1000 dt = 30.0 MPS = mpslib.MPSdtype_convert(MPS) WFN = [wfn.astype(np.complex128) for wfn in WFN[:-1]] + [WFN[-1]] E_offset = -mol[0].elocalex - mol[0].e0 - mol[0].e0_hybrid autocorr = hybrid_TDDMRG_TDH.Exact_Spectra_hybrid_TDDMRG_TDH("abs", mol, J, MPS, \ dipoleMPO, WFN, nsteps, dt, E_offset=E_offset) with open("std_data/tMPS/1mol_ZTabs.npy", 'rb') as f: mol1_ZTabs_std = np.load(f) self.assertTrue(np.allclose(autocorr, mol1_ZTabs_std, rtol=1e-3))