def test_discrete_mean(self): xpos, ephcoup = discrete_mean(spectral_density_Lorentzian, \ (eta, gamma, omega_v), 0.0, omega_c, 10) print "discrete", xpos, ephcoup dipole_abs = 1.0 nmols = 1 elocalex = 100000. * constant.cm2au J = np.array([[0.]]) * constant.cm2au omega_value = xpos * constant.cm2au omega = [{0: x, 1: x} for x in omega_value] D = [{ 0: 0.0, 1: ephcoup[i] * np.sqrt(2. / omega_value[i]) } for i in range(len(ephcoup))] nphs = len(xpos) nlevels = [10] * nphs 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) nexciton = 0 procedure = [[20, 0.1], [10, 0], [1, 0]] iMPS, iMPSdim, iMPSQN, HMPO, HMPOdim, HMPOQN, HMPOQNidx, HMPOQNtot, ephtable, pbond = \ MPSsolver.construct_MPS_MPO_2(mol, J, procedure[0][0], nexciton) MPSsolver.optimization(iMPS, iMPSdim, iMPSQN, HMPO, HMPOdim, ephtable, pbond,\ nexciton, procedure, method="2site") # if in the EX space, MPO minus E_e to reduce osillation for ibra in xrange(pbond[0]): HMPO[0][0, ibra, ibra, 0] -= elocalex iMPS = [iMPS, iMPSQN, len(iMPS) - 1, 0] QNargs = [ephtable, False] HMPO = [HMPO, HMPOQN, HMPOQNidx, HMPOQNtot] dipoleMPO, dipoleMPOdim = MPSsolver.construct_onsiteMPO(mol, pbond, \ "a^\dagger", dipole=True, QNargs=QNargs) iMPS = mpslib.MPSdtype_convert(iMPS, QNargs=QNargs) nsteps = 1000 dt = 30. autocorr = tMPS.ZeroTCorr(iMPS, HMPO, dipoleMPO, nsteps, dt, ephtable, \ thresh=1.0e-4, cleanexciton=1-nexciton, algorithm=2, compress_method="svd", QNargs=QNargs) with open("std_data/discretization/mean.npy", 'rb') as f: mean_std = np.load(f) self.assertTrue(np.allclose(autocorr, mean_std, rtol=1.e-3))
def test_ZeroTcorr(self, value): print "data", value nexciton = 0 procedure = [[1, 0], [1, 0], [1, 0]] mol = construct_mol(*value[3]) iMPS, iMPSdim, iMPSQN, HMPO, HMPOdim, HMPOQN, HMPOQNidx, HMPOQNtot, ephtable, pbond = \ MPSsolver.construct_MPS_MPO_2(mol, J, procedure[0][0], nexciton) MPSsolver.optimization(iMPS, iMPSdim, iMPSQN, HMPO, HMPOdim, ephtable, pbond,\ nexciton, procedure, method="2site") # if in the EX space, MPO minus E_e to reduce osillation for ibra in xrange(pbond[0]): HMPO[0][0, ibra, ibra, 0] -= 2.28614053 / constant.au2ev if value[2] != None: iMPS = [iMPS, iMPSQN, len(iMPS) - 1, 0] QNargs = [ephtable, False] HMPO = [HMPO, HMPOQN, HMPOQNidx, HMPOQNtot] else: QNargs = None dipoleMPO, dipoleMPOdim = MPSsolver.construct_onsiteMPO(mol, pbond, "a^\dagger", dipole=True, QNargs=QNargs) iMPS = mpslib.MPSdtype_convert(iMPS, QNargs=QNargs) nsteps = 100 dt = 30.0 autocorr = tMPS.ZeroTCorr(iMPS, HMPO, dipoleMPO, nsteps, dt, ephtable, thresh=1.0e-3, cleanexciton=1 - nexciton, algorithm=value[0], compress_method=value[1], QNargs=QNargs) autocorr = np.array(autocorr) with open( "std_data/tMPS/ZeroTabs_" + str(value[0]) + str(value[1]) + ".npy", 'rb') as f: ZeroTabs_std = np.load(f) self.assertTrue(np.allclose(autocorr, ZeroTabs_std, rtol=value[4]))
def test_ZeroTcorr(self, value): nexciton = 0 procedure = [[20, 0.5], [10, 0.1], [5, 0], [1, 0]] mol = construct_mol(*value[0]) Chain = chainmap.Chain_Map_discrete(mol) mol = chainmap.Chain_Mol(Chain, mol) iMPS, iMPSdim, iMPSQN, HMPO, HMPOdim, HMPOQN, HMPOQNidx, HMPOQNtot, ephtable, pbond = \ MPSsolver.construct_MPS_MPO_2(mol, J, procedure[0][0], nexciton,\ rep="chain") MPSsolver.optimization(iMPS, iMPSdim, iMPSQN, HMPO, HMPOdim, ephtable, pbond,\ nexciton, procedure, method="2site") # if in the EX space, MPO minus E_e to reduce osillation for ibra in xrange(pbond[0]): HMPO[0][0, ibra, ibra, 0] -= 2.28614053 / constant.au2ev iMPS = [iMPS, iMPSQN, len(iMPS) - 1, 0] QNargs = [ephtable, False] HMPO = [HMPO, HMPOQN, HMPOQNidx, HMPOQNtot] dipoleMPO, dipoleMPOdim = MPSsolver.construct_onsiteMPO(mol, pbond, "a^\dagger", dipole=True, QNargs=QNargs) iMPS = mpslib.MPSdtype_convert(iMPS, QNargs=QNargs) nsteps = 100 dt = 10.0 autocorr = tMPS.ZeroTCorr(iMPS, HMPO, dipoleMPO, nsteps, dt, ephtable, thresh=1.0e-3, cleanexciton=1 - nexciton, algorithm=2, compress_method="svd", QNargs=QNargs) autocorr = np.array(autocorr) with open("std_data/quasiboson/0Tabs_std.npy", 'rb') as f: ZeroTabs_std = np.load(f) self.assertTrue(np.allclose(autocorr, ZeroTabs_std, rtol=value[1]))
def test_ZeroTcorr_TDVP(self, value): nexciton = 0 procedure = [[50, 0], [50, 0], [50, 0]] iMPS, iMPSdim, iMPSQN, HMPO, HMPOdim, HMPOQN, HMPOQNidx, HMPOQNtot, ephtable, pbond = \ MPSsolver.construct_MPS_MPO_2(mol, J, procedure[0][0], nexciton) MPSsolver.optimization(iMPS, iMPSdim, iMPSQN, HMPO, HMPOdim, ephtable, pbond,\ nexciton, procedure, method="2site") # if in the EX space, MPO minus E_e to reduce osillation for ibra in xrange(pbond[0]): HMPO[0][0, ibra, ibra, 0] -= 2.28614053 / constant.au2ev dipoleMPO, dipoleMPOdim = MPSsolver.construct_onsiteMPO(mol, pbond, "a^\dagger", dipole=True) iMPS = mpslib.MPSdtype_convert(iMPS) nsteps = 200 dt = value[2] for f in glob.glob("TDVP_PS*.npy"): os.remove(f) autocorr = tMPS.ZeroTCorr(iMPS, HMPO, dipoleMPO, nsteps, dt, ephtable, thresh=1.0e-7, cleanexciton=1 - nexciton, algorithm=value[1], compress_method="variational", scheme=value[0]) with open("std_data/tMPS/ZeroTabs_" + value[0] + ".npy", 'rb') as f: ZeroTabs_std = np.load(f) self.assertTrue( np.allclose(autocorr, ZeroTabs_std[:len(autocorr)], rtol=value[3]))
def test_ZeroTcorr_MPOscheme3(self, value): print "data", value J = np.array([[0.0, -0.1, 0.0], [-0.1, 0.0, -0.3], [0.0, -0.3, 0.0] ]) / constant.au2ev nexciton = 0 procedure = [[1, 0], [1, 0], [1, 0]] mol = construct_mol(*value[3]) iMPS, iMPSdim, iMPSQN, HMPO, HMPOdim, HMPOQN, HMPOQNidx, HMPOQNtot, ephtable, pbond = \ MPSsolver.construct_MPS_MPO_2(mol, J, procedure[0][0], nexciton, MPOscheme=2) MPSsolver.optimization(iMPS, iMPSdim, iMPSQN, HMPO, HMPOdim, ephtable, pbond,\ nexciton, procedure, method="2site") # if in the EX space, MPO minus E_e to reduce osillation for ibra in xrange(pbond[0]): HMPO[0][0, ibra, ibra, 0] -= 2.28614053 / constant.au2ev if value[2] != None: iMPS = [iMPS, iMPSQN, len(iMPS) - 1, 0] QNargs = [ephtable, False] HMPO = [HMPO, HMPOQN, HMPOQNidx, HMPOQNtot] else: QNargs = None dipoleMPO, dipoleMPOdim = MPSsolver.construct_onsiteMPO(mol, pbond, "a^\dagger", dipole=True, QNargs=QNargs) iMPS = mpslib.MPSdtype_convert(iMPS, QNargs=QNargs) nsteps = 50 dt = 30.0 autocorr = tMPS.ZeroTCorr(iMPS, HMPO, dipoleMPO, nsteps, dt, ephtable, thresh=1.0e-4, cleanexciton=1 - nexciton, algorithm=value[0], compress_method=value[1], QNargs=QNargs) autocorr = np.array(autocorr) # scheme3 iMPS3, iMPSdim3, iMPSQN3, HMPO3, HMPOdim3, HMPOQN3, HMPOQNidx3, HMPOQNtot3, ephtable3, pbond3 = \ MPSsolver.construct_MPS_MPO_2(mol, J, procedure[0][0], nexciton, MPOscheme=3) MPSsolver.optimization(iMPS3, iMPSdim3, iMPSQN3, HMPO3, HMPOdim3, ephtable3, pbond3,\ nexciton, procedure, method="2site") # if in the EX space, MPO minus E_e to reduce osillation for ibra in xrange(pbond3[0]): HMPO3[0][0, ibra, ibra, 0] -= 2.28614053 / constant.au2ev if value[2] != None: iMPS3 = [iMPS3, iMPSQN3, len(iMPS3) - 1, 0] QNargs3 = [ephtable3, False] HMPO3 = [HMPO3, HMPOQN3, HMPOQNidx3, HMPOQNtot3] else: QNargs3 = None dipoleMPO, dipoleMPOdim = MPSsolver.construct_onsiteMPO(mol, pbond, "a^\dagger", dipole=True, QNargs=QNargs3) iMPS3 = mpslib.MPSdtype_convert(iMPS3, QNargs=QNargs) nsteps = 50 dt = 30.0 autocorr3 = tMPS.ZeroTCorr(iMPS3, HMPO3, dipoleMPO, nsteps, dt, ephtable3,\ thresh=1.0e-4, cleanexciton=1-nexciton, algorithm=value[0], compress_method=value[1], QNargs=QNargs3) autocorr3 = np.array(autocorr3) self.assertTrue(np.allclose(autocorr, autocorr3, rtol=value[4]))