Пример #1
0
    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_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]))
Пример #3
0
    def test_ZeroExactEmi(self, value):

        print "data", value
        nexciton = 1
        procedure = [[10, 0.4], [20, 0.2], [30, 0.1], [40, 0], [40, 0]]

        mol = construct_mol(*value[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",
                                                                dipole=True)
        nsteps = 3000
        dt = 30.0
        temperature = 0
        autocorr = tMPS.Exact_Spectra("emi", mol, pbond, iMPS, dipoleMPO, \
                nsteps, dt, temperature)
        autocorr = np.array(autocorr)
        with open("std_data/tMPS/ZeroExactEmi.npy", 'rb') as f:
            ZeroExactEmi_std = np.load(f)

        self.assertTrue(np.allclose(autocorr, ZeroExactEmi_std, rtol=value[1]))
Пример #4
0
    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)

        nexciton = 0
        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, procedure[0][0], nexciton)

        MPSsolver.optimization(MPS, MPSdim, MPSQN, HMPO, HMPOdim, ephtable, pbond,\
                nexciton, procedure, method="2site")

        dipoleMPO, dipoleMPOdim = MPSsolver.construct_onsiteMPO(mol,
                                                                pbond,
                                                                "a^\dagger",
                                                                dipole=True)

        nsteps = 1000
        dt = 30.0
        temperature = 0
        autocorr = tMPS.Exact_Spectra("abs", mol, pbond, MPS, dipoleMPO,
                                      nsteps, dt, temperature)
        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))
Пример #5
0
    def test_Csvd(self):
        MPS, MPSdim, MPSQN, MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, ephtable, pbond = \
            MPSsolver.construct_MPS_MPO_2(mol, J, procedure[0][0], nexciton, MPOscheme=2)
        energy = MPSsolver.optimization(MPS,
                                        MPSdim,
                                        MPSQN,
                                        MPO,
                                        MPOdim,
                                        ephtable,
                                        pbond,
                                        nexciton,
                                        procedure,
                                        method="2site")

        MPSnew1 = mpslib.compress(MPS,
                                  'l',
                                  trunc=1.e-6,
                                  check_canonical=False,
                                  QR=False,
                                  QNargs=None)

        QNargs = [ephtable, False]
        MPS = [MPS, MPSQN, len(MPS) - 1, 1]
        MPSnew2 = mpslib.compress(MPS,
                                  'l',
                                  trunc=1.e-6,
                                  check_canonical=False,
                                  QR=False,
                                  QNargs=QNargs)
        self.assertAlmostEqual(mpslib.distance(MPSnew1, MPSnew2[0]), 0.0)
Пример #6
0
 def test_multistate(self):
     MPS, MPSdim, MPSQN, MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, ephtable, pbond = \
         MPSsolver.construct_MPS_MPO_2(mol, J, procedure[0][0], nexciton,
                 MPOscheme=2)
     energy1 = MPSsolver.optimization(MPS,
                                      MPSdim,
                                      MPSQN,
                                      MPO,
                                      MPOdim,
                                      ephtable,
                                      pbond,
                                      nexciton,
                                      procedure,
                                      method="1site",
                                      nroots=5)
     energy2 = MPSsolver.optimization(MPS,
                                      MPSdim,
                                      MPSQN,
                                      MPO,
                                      MPOdim,
                                      ephtable,
                                      pbond,
                                      nexciton,
                                      procedure,
                                      method="2site",
                                      nroots=5)
     print energy1[-1], energy2[-1]
     energy_std = [0.08401412, 0.08449771, 0.08449801, 0.08449945]
     self.assertTrue(np.allclose(energy1[-1][:4], energy_std))
     self.assertTrue(np.allclose(energy2[-1][:4], energy_std))
    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]))
Пример #8
0
def hybrid_DMRG_H_SCF(mol,
                      J,
                      nexciton,
                      dmrg_procedure,
                      niterations,
                      DMRGthresh=1e-5,
                      Hthresh=1e-5):
    '''
    The ground state SCF procedure of hybrid DMRG and Hartree(-Fock) approach
    '''
    nmols = len(mol)
    # initial guess
    # DMRG part
    MPS, MPSdim, MPSQN, MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, ephtable, pbond = \
        MPSsolver.construct_MPS_MPO_2(mol, J, dmrg_procedure[0][0], nexciton)

    energy = MPSsolver.optimization(MPS, MPSdim, MPSQN, MPO, MPOdim,\
        ephtable, pbond, nexciton, dmrg_procedure)

    # Hartre part
    WFN = []
    for imol in xrange(nmols):
        for iph in xrange(mol[imol].nphs_hybrid):
            vw, vv = scipy.linalg.eigh(a=mol[imol].ph_hybrid[iph].H_vib_indep)
            WFN.append(vv[:, 0])

    # loop to optimize both parts
    for itera in xrange(niterations):
        print "Loop:", itera
        MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, HAM, Etot = construct_hybrid_Ham(
            mol, J, MPS, WFN)
        print "Etot=", Etot

        MPS_old = mpslib.add(MPS, None)
        energy = MPSsolver.optimization(MPS, MPSdim, MPSQN, MPO, MPOdim,
                                        ephtable, pbond, nexciton,
                                        dmrg_procedure)

        WFN_old = WFN
        WFN = []
        for iham, ham in enumerate(HAM):
            w, v = scipy.linalg.eigh(a=ham)
            WFN.append(v[:, 0])

        # check convergence
        angle = np.absolute(mpslib.dot(mpslib.conj(MPS_old), MPS))

        res = [scipy.linalg.norm(np.tensordot(WFN[iwfn],WFN[iwfn],axes=0) \
         -np.tensordot(WFN_old[iwfn], WFN_old[iwfn], axes=0)) for iwfn in xrange(len(WFN))]

        if np.all(np.array(res) < Hthresh) and abs(angle - 1.) < DMRGthresh:
            print "SCF converge!"
            break

    # append the coefficient a
    WFN.append(1.0)

    return MPS, MPSQN, WFN, Etot
Пример #9
0
    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))
Пример #10
0
    def test_FiniteT_spectra_emi(self, value):
        print "data", value
        nexciton = 1
        procedure = [[10, 0.4], [20, 0.2], [30, 0.1], [40, 0], [40, 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)

        # 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:
            QNargs = [ephtable, False]
            HMPO = [HMPO, HMPOQN, HMPOQNidx, HMPOQNtot]
        else:
            QNargs = None

        dipoleMPO, dipoleMPOdim = MPSsolver.construct_onsiteMPO(mol,
                                                                pbond,
                                                                "a",
                                                                dipole=True,
                                                                QNargs=QNargs)
        nsteps = 30
        dt = 30.0
        EXMPO, EXMPOdim = tMPS.Max_Entangled_EX_MPO(mol,
                                                    pbond,
                                                    norm=True,
                                                    QNargs=QNargs)
        EXMPO = mpslib.MPSdtype_convert(EXMPO, QNargs=QNargs)

        insteps = 50
        autocorr = tMPS.FiniteT_spectra("emi",
                                        mol,
                                        pbond,
                                        EXMPO,
                                        HMPO,
                                        dipoleMPO,
                                        nsteps,
                                        dt,
                                        ephtable,
                                        insteps,
                                        thresh=1.0e-3,
                                        temperature=298,
                                        algorithm=value[0],
                                        compress_method=value[1],
                                        QNargs=QNargs)

        autocorr = np.array(autocorr)
        with open(
                "std_data/tMPS/TTemi_" + str(value[0]) + str(value[1]) +
                ".npy", 'rb') as f:
            TTemi_std = np.load(f)
        self.assertTrue(
            np.allclose(autocorr, TTemi_std[0:nsteps], rtol=value[4]))
Пример #11
0
    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]))
Пример #12
0
    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]))
Пример #13
0
    def test_construct_MPO(self):
        Mmax = 10
        MPS1, MPSdim1, MPSQN1, MPO1, MPOdim1, MPOQN1, MPOQNidx1, MPOQNtot1, ephtable1, pbond1 = \
            MPSsolver.construct_MPS_MPO_2(mol, J, Mmax, nexciton, MPOscheme=1)
        MPS2, MPSdim2, MPSQN2, MPO2, MPOdim2, MPOQN2, MPOQNidx2, MPOQNtot2, ephtable2, pbond2 = \
            MPSsolver.construct_MPS_MPO_2(mol, J, Mmax, nexciton, MPOscheme=2)

        self.assertEqual(ephtable1, ephtable2)
        self.assertEqual(pbond1, pbond2)
        self.assertAlmostEqual( \
            mpslib.dot(MPO1, mpslib.conj(MPO1)) + \
            mpslib.dot(MPO2, mpslib.conj(MPO2)) - \
            mpslib.dot(MPO1, mpslib.conj(MPO2)) - \
            mpslib.dot(MPO2, mpslib.conj(MPO1)), 0.0)
Пример #14
0
 def test_construct_MPO_scheme3(self):
     Mmax = 10
     J = np.array([[0.0, -0.1, 0.0], [-0.1, 0.0, -0.3], [0.0, -0.3, 0.0]
                   ]) / constant.au2ev
     MPS2, MPSdim2, MPSQN2, MPO2, MPOdim2, MPOQN2, MPOQNidx2, MPOQNtot2, ephtable2, pbond2 = \
         MPSsolver.construct_MPS_MPO_2(mol, J, Mmax, nexciton, MPOscheme=2)
     MPS3, MPSdim3, MPSQN3, MPO3, MPOdim3, MPOQN3, MPOQNidx3, MPOQNtot3, ephtable3, pbond3 = \
         MPSsolver.construct_MPS_MPO_2(mol, J, Mmax, nexciton, MPOscheme=3)
     self.assertEqual(ephtable3, ephtable2)
     self.assertEqual(pbond3, pbond2)
     self.assertAlmostEqual( \
         mpslib.dot(MPO3, mpslib.conj(MPO3)) + \
         mpslib.dot(MPO2, mpslib.conj(MPO2)) - \
         mpslib.dot(MPO3, mpslib.conj(MPO2)) - \
         mpslib.dot(MPO2, mpslib.conj(MPO3)), 0.0)
    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_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))
Пример #17
0
    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))
Пример #18
0
    def test_FiniteT_spectra_emi(self, value):
        nexciton = 1
        procedure = [[10, 0.4], [20, 0.2], [30, 0.1], [40, 0], [40, 0]]

        iMPS, iMPSdim, iMPSQN, HMPO, HMPOdim, HMPOQN, HMPOQNidx, HMPOQNtot, ephtable, pbond = \
            MPSsolver.construct_MPS_MPO_2(mol, J, procedure[0][0], nexciton)

        # 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",
                                                                dipole=True)
        nsteps = value[1]
        dt = value[2]
        EXMPO, EXMPOdim = tMPS.Max_Entangled_EX_MPO(mol, pbond, norm=True)
        EXMPO = mpslib.MPSdtype_convert(EXMPO)

        for f in glob.glob("TDVP_PS*.npy"):
            os.remove(f)

        insteps = 50
        autocorr = tMPS.FiniteT_spectra("emi",
                                        mol,
                                        pbond,
                                        EXMPO,
                                        HMPO,
                                        dipoleMPO,
                                        nsteps,
                                        dt,
                                        ephtable,
                                        insteps,
                                        thresh=1.0e-3,
                                        temperature=298,
                                        compress_method="variational",
                                        scheme=value[0])

        with open("std_data/tMPS/TTemi_2svd" + value[4] + ".npy", 'rb') as f:
            TTemi_std = np.load(f)
        self.assertTrue(
            np.allclose(autocorr, TTemi_std[0:nsteps], rtol=value[3]))
Пример #19
0
    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]))
Пример #20
0
    def test_nonlinear_omega_1(self):
        
        nmols = 1
        J = np.zeros([1,1])
        nlevels =  [10,10]
        mol = []
        phinfo = [list(a) for a in zip(omega, D, nlevels)]
        for imol in xrange(nmols):
            mol_local = obj.Mol(elocalex, nphs, dipole_abs)
            mol_local.create_ph(phinfo)
            mol.append(mol_local)
        
        MPS, MPSdim, MPSQN, MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, ephtable, pbond = \
            MPSsolver.construct_MPS_MPO_2(mol, J, procedure[0][0], nexciton, MPOscheme=2)
        energy = MPSsolver.optimization(MPS, MPSdim, MPSQN, MPO, MPOdim, 
                ephtable, pbond, nexciton, procedure, method="2site")

        print "omega_diff_std", omega_diff/constant.cm2au
        print "omega_diff_cal", (np.min(energy)-elocalex)/constant.cm2au*2  
        self.assertAlmostEqual((np.min(energy)-elocalex)*2, omega_diff)
Пример #21
0
    def test_optimization(self, value):
        MPS, MPSdim, MPSQN, MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, ephtable, pbond = \
            MPSsolver.construct_MPS_MPO_2(mol, J, procedure[0][0], nexciton,
                    MPOscheme=value[0])
        energy = MPSsolver.optimization(MPS,
                                        MPSdim,
                                        MPSQN,
                                        MPO,
                                        MPOdim,
                                        ephtable,
                                        pbond,
                                        nexciton,
                                        procedure,
                                        method="2site")
        self.assertAlmostEqual(np.min(energy) * constant.au2ev, 2.28614053133)

        energy = MPSsolver.optimization(MPS,
                                        MPSdim,
                                        MPSQN,
                                        MPO,
                                        MPOdim,
                                        ephtable,
                                        pbond,
                                        nexciton,
                                        procedure,
                                        method="1site")
        self.assertAlmostEqual(np.min(energy) * constant.au2ev, 2.28614053133)

        MPSnew = MPSsolver.clean_MPS("L", MPS, ephtable, nexciton)
        self.assertAlmostEqual( \
            mpslib.dot(MPS, mpslib.conj(MPS)) + \
            mpslib.dot(MPSnew, mpslib.conj(MPSnew)) - \
            mpslib.dot(MPS, mpslib.conj(MPSnew)) - \
            mpslib.dot(MPSnew, mpslib.conj(MPS)), 0.0)

        MPSnew = MPSsolver.clean_MPS("R", MPS, ephtable, nexciton)
        self.assertAlmostEqual( \
            mpslib.dot(MPS, mpslib.conj(MPS)) + \
            mpslib.dot(MPSnew, mpslib.conj(MPSnew)) - \
            mpslib.dot(MPS, mpslib.conj(MPSnew)) - \
            mpslib.dot(MPSnew, mpslib.conj(MPS)), 0.0)
Пример #22
0
    def test_FiniteT_spectra_abs(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)

        # 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:
            QNargs = [ephtable, False]
            HMPO = [HMPO, HMPOQN, HMPOQNidx, HMPOQNtot]
        else:
            QNargs = None

        dipoleMPO, dipoleMPOdim = MPSsolver.construct_onsiteMPO(mol,
                                                                pbond,
                                                                "a^\dagger",
                                                                dipole=True,
                                                                QNargs=QNargs)
        GSMPS, GSMPSdim = tMPS.Max_Entangled_GS_MPS(mol, pbond, QNargs=QNargs)
        GSMPO = tMPS.hilbert_to_liouville(GSMPS, QNargs=QNargs)
        GSMPO = mpslib.MPSdtype_convert(GSMPO, QNargs=QNargs)

        nsteps = 50
        dt = 30.0
        autocorr = tMPS.FiniteT_spectra("abs",
                                        mol,
                                        pbond,
                                        GSMPO,
                                        HMPO,
                                        dipoleMPO,
                                        nsteps,
                                        dt,
                                        ephtable,
                                        thresh=1.0e-3,
                                        temperature=298,
                                        algorithm=value[0],
                                        compress_method=value[1],
                                        QNargs=QNargs)

        autocorr = np.array(autocorr)

        with open("std_data/tMPS/TTabs_" + str(value[1] + ".npy"), 'rb') as f:
            TTabs_std = np.load(f)

        self.assertTrue(
            np.allclose(autocorr, TTabs_std[0:nsteps], rtol=value[4]))
Пример #23
0
    def test_quasiboson_constructMPO(self):

        mol = construct_mol([4, 4])
        MPS1, MPSdim1, MPSQN1, MPO1, MPOdim1, MPOQN1, MPOQNidx1, MPOQNtot1, ephtable1, pbond1 = \
            MPSsolver.construct_MPS_MPO_2(mol, J, procedure[0][0], nexciton, MPOscheme=2)

        mol = construct_mol([4, 4], [2, 2], [1e-7, 1e-7])
        MPS, MPSdim, MPSQN, MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, ephtable, pbond = \
            MPSsolver.construct_MPS_MPO_2(mol, J, procedure[0][0], nexciton,
                    MPOscheme=2)

        # merge the decomposed MPO
        MPOmerge = []
        impo = 0
        for imol in xrange(nmols):
            MPOmerge.append(MPO[impo])
            impo += 1
            for iph in xrange(mol[imol].nphs):
                MPOmerge.append(
                    np.einsum("abcd, defg -> abecfg", MPO[impo],
                              MPO[impo + 1]).reshape(MPO[impo].shape[0], 4, 4,
                                                     MPO[impo + 1].shape[-1]))
                impo += 2

        self.assertAlmostEqual( \
            mpslib.distance(MPO1, MPOmerge), 0.0)

        energy = MPSsolver.optimization(MPS,
                                        MPSdim,
                                        MPSQN,
                                        MPO,
                                        MPOdim,
                                        ephtable,
                                        pbond,
                                        nexciton,
                                        procedure,
                                        method="2site")
        self.assertAlmostEqual(np.min(energy) * constant.au2ev, 2.28614053133)

        energy = MPSsolver.optimization(MPS,
                                        MPSdim,
                                        MPSQN,
                                        MPO,
                                        MPOdim,
                                        ephtable,
                                        pbond,
                                        nexciton,
                                        procedure,
                                        method="1site")
        self.assertAlmostEqual(np.min(energy) * constant.au2ev, 2.28614053133)

        MPSnew = MPSsolver.clean_MPS("L", MPS, ephtable, nexciton)
        self.assertAlmostEqual( \
            mpslib.distance(MPSnew, mpslib.conj(MPS)), 0.0)

        MPSnew = MPSsolver.clean_MPS("R", MPS, ephtable, nexciton)
        self.assertAlmostEqual( \
            mpslib.distance(MPSnew, mpslib.conj(MPS)), 0.0)
Пример #24
0
    def test_nonlinear_omega_2(self):
        nmols = 2
        J = np.array([[0.0, 1000],[1000, 0.0]])*constant.cm2au

        nlevels =  [5,5]
        mol = []
        phinfo = [list(a) for a in zip(omega, D, nlevels)]
        for imol in xrange(nmols):
            mol_local = obj.Mol(elocalex, nphs, dipole_abs)
            mol_local.create_ph(phinfo)
            mol.append(mol_local)
        
        MPS, MPSdim, MPSQN, MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, ephtable, pbond = \
            MPSsolver.construct_MPS_MPO_2(mol, J, procedure[0][0], nexciton, MPOscheme=2)
        energy = MPSsolver.optimization(MPS, MPSdim, MPSQN, MPO, MPOdim, 
                ephtable, pbond, nexciton, procedure, method="2site")

        fx, fy, fph_dof_list, fnconfigs = exact_solver.pre_Hmat(nexciton, mol)
        fHmat = exact_solver.construct_Hmat(fnconfigs, mol, J,
                indirect=[fph_dof_list, fx, fy])
        fe, fc =  exact_solver.Hmat_diagonalization(fHmat, method="full")
        print np.min(energy), fe[0]
        self.assertAlmostEqual(np.min(energy),fe[0])
Пример #25
0
    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]))
Пример #26
0
    def test_force3rd(self,value):
        elocalex = 1.e4 * constant.cm2au
        dipole_abs = 1.0
        nmols = 1
        J = np.zeros([nmols, nmols])
        omega_value = np.array([100.])*constant.cm2au
        omega = [{0:omega_value[0],1:omega_value[0]}]
        S_value = 2.0
        if value[1] == "+":
            phase = 1.0
        elif value[1] == "-":
            phase = -1.0
        
        D_value = phase * np.sqrt(S_value)*np.sqrt(2.0/omega_value)
        D = [{0:0.0,1:D_value[0]}]
        force3rd = [{0:abs(omega_value[0]**2/D_value[0]*0.2/2.), \
            1:abs(omega_value[0]**2/D_value[0]*0.2/2.0)}]
        
        print "alpha", omega_value[0]**2/2.
        print "beta", omega_value[0]**2/D_value[0]*0.2/2.
        print "D", D_value[0]
        
        nphs = 1
        nlevels =  [30]
        
        phinfo = [list(a) for a in zip(omega, D, nlevels, force3rd)]
        
        mol = []
        for imol in xrange(nmols):
            mol_local = obj.Mol(elocalex, nphs, dipole_abs)
            mol_local.create_ph(phinfo)
            mol.append(mol_local)
        
        if value[0] == "abs":
            nexciton = 0
            opera = "a^\dagger"
        elif value[0] == "emi":
            nexciton = 1
            opera = "a"

        procedure = [[50,0.4],[50,0.2],[50,0.1],[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] -=  elocalex 
        
        dipoleMPO, dipoleMPOdim = MPSsolver.construct_onsiteMPO(mol, pbond, opera, dipole=True)
        nsteps = 10000
        dt = 30.0
        print "energy dE", 1.0/dt/ nsteps / constant.cm2au * 2.0 * np.pi
        print "energy E", 1.0/dt / constant.cm2au * 2.0 * np.pi

        temperature = 0
        autocorr = tMPS.Exact_Spectra(value[0], mol, pbond, iMPS, dipoleMPO, nsteps, dt, temperature)
        autocorr = np.array(autocorr)
        print mol[0].e0
        np.save(value[0]+value[1],autocorr)
        autocorr_std = np.load("std_data/force3rd/"+value[0]+str(value[1])+".npy")
        self.assertTrue(np.allclose(autocorr,autocorr_std,rtol=1e-2, atol=1e-03))
Пример #27
0
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
Пример #28
0
    def test_Chain_Map_discrete(self, value):

        elocalex = 2.67 / constant.au2ev
        dipole_abs = 15.45
        nmols = 3
        # eV
        J = np.array([[0.0, -0.1, -0.2], [-0.1, 0.0, -0.3], [-0.2, -0.3, 0.0]
                      ]) / constant.au2ev
        omega_value = np.array([106.51, 1555.55, 1200.0]) * constant.cm2au
        D_value = np.array([30.1370, 8.7729, 20.0])
        D = [{0: 0.0, 1: x} for x in D_value]
        omega = [{0:omega_value[0], 1:omega_value[0]},{0:omega_value[1], \
            1:omega_value[1]},{0:omega_value[2], 1:omega_value[2]}]
        nexciton = 1
        nphs = 3

        procedure = [[10, 0.4], [20, 0.3], [30, 0.2], [40, 0.1], [40, 0]]

        nlevels = [8] * nphs
        nqboson = [value[0]] * nphs
        qbtrunc = [1e-7] * nphs
        force3rd = [None] * nphs
        phinfo = [
            list(a) for a in zip(omega, D, nlevels, force3rd, nqboson, qbtrunc)
        ]
        mol = []
        for imol in xrange(nmols):
            mol_local = obj.Mol(elocalex, nphs, dipole_abs)
            mol_local.create_ph(phinfo)
            mol.append(mol_local)

        MPS, MPSdim, MPSQN, MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, ephtable, pbond = \
                    MPSsolver.construct_MPS_MPO_2(mol, J, procedure[0][0], nexciton, \
                    MPOscheme=2)
        energy1 = MPSsolver.optimization(MPS,
                                         MPSdim,
                                         MPSQN,
                                         MPO,
                                         MPOdim,
                                         ephtable,
                                         pbond,
                                         nexciton,
                                         procedure,
                                         method="2site")

        Chain = chainmap.Chain_Map_discrete(mol)
        molnew = chainmap.Chain_Mol(Chain, mol)

        MPS, MPSdim, MPSQN, MPO, MPOdim, MPOQN, MPOQNidx, MPOQNtot, ephtable, pbond = \
                    MPSsolver.construct_MPS_MPO_2(molnew, J, procedure[0][0], nexciton, \
                    MPOscheme=2, rep="chain")

        energy2 = MPSsolver.optimization(MPS,
                                         MPSdim,
                                         MPSQN,
                                         MPO,
                                         MPOdim,
                                         ephtable,
                                         pbond,
                                         nexciton,
                                         procedure,
                                         method="2site")
        print np.min(energy1), np.min(energy2)
        self.assertAlmostEqual(np.min(energy1), np.min(energy2))
Пример #29
0
def ExactPropagator_hybrid_TDDMRG_TDH(mol,
                                      J,
                                      MPS,
                                      WFN,
                                      x,
                                      space="GS",
                                      QNargs=None):
    '''
    construct the exact propagator in the GS space or single molecule
    '''
    nmols = len(mol)
    assert space in ["GS", "EX"]
    if space == "EX":
        assert nmols == 1

    # TDDMRG propagator
    if QNargs is None:
        pbond = [mps.shape[1] for mps in MPS]
    else:
        pbond = [mps.shape[1] for mps in MPS[0]]

    MPO_indep, MPOdim, MPOQN, MPOQNidx, MPOQNtot = MPSsolver.construct_MPO(
        mol, J, pbond)
    if QNargs is not None:
        MPO_indep = [MPO_indep, MPOQN, MPOQNidx, MPOQNtot]

    e_mean = mpslib.exp_value(MPS, MPO_indep, MPS, QNargs=QNargs)
    print "e_mean", e_mean

    if space == "EX":
        # the DMRG part exact propagator has no elocalex and e0
        e_mean -= mol[0].e0 + mol[0].elocalex

    MPOprop, MPOpropdim = tMPS.ExactPropagatorMPO(mol,
                                                  pbond,
                                                  x,
                                                  space=space,
                                                  QNargs=QNargs,
                                                  shift=-e_mean)

    Etot = e_mean

    # TDH propagator
    iwfn = 0
    HAM = []
    for imol in xrange(nmols):
        for iph in xrange(mol[imol].nphs_hybrid):
            H_vib_indep = mol[imol].ph_hybrid[iph].H_vib_indep
            H_vib_dep = mol[imol].ph_hybrid[iph].H_vib_dep
            e_mean = mflib.exp_value(WFN[iwfn], H_vib_indep, WFN[iwfn])
            if space == "EX":
                e_mean += mflib.exp_value(WFN[iwfn], H_vib_dep, WFN[iwfn])
            Etot += e_mean

            if space == "GS":
                ham = H_vib_indep - np.diag([e_mean] * H_vib_indep.shape[0],
                                            k=0)
            elif space == "EX":
                ham = H_vib_indep + H_vib_dep - np.diag(
                    [e_mean] * H_vib_indep.shape[0], k=0)

            HAM.append(ham)
            iwfn += 1

    if space == "EX":
        Etot += mol[0].elocalex + mol[0].e0 + mol[0].e0_hybrid

    return MPOprop, HAM, Etot
Пример #30
0
    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))