def test_ucc_energy(self): noa = self.no nob = self.no nva = self.nv nvb = self.nv na = noa + nva nb = nob + nvb no = noa + nob nv = nva + nvb Faa = test_utils.make_random_F(noa, nva) Fbb = test_utils.make_random_F(nob, nvb) # Direct integrals over a,b orbitals Ia = test_utils.make_random_I_anti(noa, nva) Ib = test_utils.make_random_I_anti(nob, nvb) Iabab = test_utils.make_random_Ifull_gen(noa, nva, nob, nvb, noa, nva, nob, nvb) # Full antisymmetric spin-orbital tensor I = spin_utils.int_to_spin2(Ia, Ib, Iabab, noa, nva, nob, nvb) F = spin_utils.F_to_spin(Faa, Fbb, noa, nva, nob, nvb) # initial T T1a, T1b = test_utils.make_random_T1_spatial(noa, nva, nob, nvb) T2aa, T2ab, T2bb = test_utils.make_random_T2_spatial( noa, nva, nob, nvb) T1 = spin_utils.T1_to_spin(T1a, T1b, noa, nva, nob, nvb) T2 = spin_utils.T2_to_spin(T2aa, T2ab, T2bb, noa, nva, nob, nvb) E_ref = cc_energy.cc_energy(T1, T2, F.ov, I.oovv) E_out = cc_energy.ucc_energy((T1a, T1b), (T2aa, T2ab, T2bb), Faa.ov, Fbb.ov, Ia.oovv, Ib.oovv, Iabab.oovv) s = abs(E_ref - E_out) < self.thresh err = "Error in ucc_energy" self.assertTrue(s, err)
def test_uccsd_lambda(self): noa = self.no nob = self.no nva = self.nv nvb = self.nv na = noa + nva nb = nob + nvb no = noa + nob nv = nva + nvb Fa = test_utils.make_random_F(noa, nva) Fb = test_utils.make_random_F(nob, nvb) # Direct integrals over a,b orbitals Ia = test_utils.make_random_I_anti(noa, nva) Ib = test_utils.make_random_I_anti(nob, nvb) Iabab = test_utils.make_random_Ifull_gen(noa, nva, nob, nvb, noa, nva, nob, nvb) # Full antisymmetric spin-orbital tensor I = spin_utils.int_to_spin2(Ia, Ib, Iabab, noa, nva, nob, nvb) F = spin_utils.F_to_spin(Fa, Fb, noa, nva, nob, nvb) # initial T T1a, T1b = test_utils.make_random_T1_spatial(noa, nva, nob, nvb) T2aa, T2ab, T2bb = test_utils.make_random_T2_spatial( noa, nva, nob, nvb) T1 = spin_utils.T1_to_spin(T1a, T1b, noa, nva, nob, nvb) T2 = spin_utils.T2_to_spin(T2aa, T2ab, T2bb, noa, nva, nob, nvb) # initial L L1aold, L1bold = test_utils.make_random_T1_spatial(nva, noa, nvb, nob) L2aaold, L2abold, L2bbold = test_utils.make_random_T2_spatial( nva, noa, nvb, nob) L1old = spin_utils.T1_to_spin(L1aold, L1bold, nva, noa, nvb, nob) L2old = spin_utils.T2_to_spin(L2aaold, L2abold, L2bbold, nva, noa, nvb, nob) # Get updated Lambda using spin orbitals L1_ref, L2_ref = cc_equations.ccsd_lambda_opt(F, I, L1old, L2old, T1, T2) # Get updated Lambda using unrestricted code M1, M2 = cc_equations.uccsd_lambda_opt(Fa, Fb, Ia, Ib, Iabab, (L1aold, L1bold), (L2aaold, L2abold, L2bbold), (T1a, T1b), (T2aa, T2ab, T2bb)) L1a, L1b = M1 L2aa, L2ab, L2bb = M2 L1 = spin_utils.T1_to_spin(L1a, L1b, nva, noa, nvb, nob) L2 = spin_utils.T2_to_spin(L2aa, L2ab, L2bb, nva, noa, nvb, nob) z1 = numpy.linalg.norm(L1 - L1_ref) / numpy.sqrt(L1.size) z2 = numpy.linalg.norm(L2 - L2_ref) / numpy.sqrt(L2.size) s1 = z1 < self.thresh s2 = z2 < self.thresh e1 = "Error in UCCSD L1" e2 = "Error in UCCSD L2" self.assertTrue(s1, e1) self.assertTrue(s2, e2)
def test_uccsd(self): noa = self.no nob = self.no nva = self.nv nvb = self.nv na = noa + nva nb = nob + nvb no = noa + nob nv = nva + nvb Faa = test_utils.make_random_F(noa, nva) Fbb = test_utils.make_random_F(nob, nvb) # Direct integrals over a,b orbitals Ia = test_utils.make_random_I_anti(noa, nva) Ib = test_utils.make_random_I_anti(nob, nvb) I_abab = test_utils.make_random_Ifull_gen(noa, nva, nob, nvb, noa, nva, nob, nvb) # Full antisymmetric spin-orbital tensor I = spin_utils.int_to_spin2(Ia, Ib, I_abab, noa, nva, nob, nvb) F = spin_utils.F_to_spin(Faa, Fbb, noa, nva, nob, nvb) # initial T T1a, T1b = test_utils.make_random_T1_spatial(noa, nva, nob, nvb) T2aa, T2ab, T2bb = test_utils.make_random_T2_spatial( noa, nva, nob, nvb) T1 = spin_utils.T1_to_spin(T1a, T1b, noa, nva, nob, nvb) T2 = spin_utils.T2_to_spin(T2aa, T2ab, T2bb, noa, nva, nob, nvb) # Update with spin orbitals S1ref, S2ref = cc_equations.ccsd_stanton(F, I, T1, T2) # Update with UCCSD S1, S2 = cc_equations.uccsd_stanton(Faa, Fbb, Ia, Ib, I_abab, (T1a, T1b), (T2aa, T2ab, T2bb)) S1a, S1b = S1 S2aa, S2ab, S2bb = S2 S1 = spin_utils.T1_to_spin(S1a, S1b, noa, nva, nob, nvb) S2 = spin_utils.T2_to_spin(S2aa, S2ab, S2bb, noa, nva, nob, nvb) z1 = numpy.linalg.norm(S1 - S1ref) / numpy.sqrt(S1.size) z2 = numpy.linalg.norm(S2 - S2ref) / numpy.sqrt(S2.size) s1 = z1 < self.thresh s2 = z2 < self.thresh e1 = "Error in UCCSD T1" e2 = "Error in UCCSD T2" self.assertTrue(s1, e1) self.assertTrue(s2, e2)
def test_u2rdm(self): noa = 3 nva = 5 nob = 2 nvb = 6 thresh = 1e-14 # use unrestricted one-particle property Aa = test_utils.make_random_I_anti(noa, nva) Ab = test_utils.make_random_I_anti(nob, nvb) Aab = test_utils.make_random_Ifull_gen( noa, nva, nob, nvb, noa, nva, nob, nvb) Atot = spin_utils.int_to_spin2(Aa, Ab, Aab, noa, nva, nob, nvb) # get unrestricted and general amplitudes T1a, T1b = test_utils.make_random_T1_spatial(noa, nva, nob, nvb) T2aa, T2ab, T2bb \ = test_utils.make_random_T2_spatial(noa, nva, nob, nvb) L1a, L1b = test_utils.make_random_T1_spatial(nva, noa, nvb, nob) L2aa, L2ab, L2bb \ = test_utils.make_random_T2_spatial(nva, noa, nvb, nob) T1 = spin_utils.T1_to_spin(T1a, T1b, noa, nva, nob, nvb) L1 = spin_utils.T1_to_spin(L1a, L1b, nva, noa, nvb, nob) T2 = spin_utils.T2_to_spin(T2aa, T2ab, T2bb, noa, nva, nob, nvb) L2 = spin_utils.T2_to_spin(L2aa, L2ab, L2bb, nva, noa, nvb, nob) # make general pieces of 2-rdm Pijab = L2.copy() Pciab = cc_equations.ccsd_2rdm_ciab(T1, T2, L1, L2) Pjkai = cc_equations.ccsd_2rdm_jkai(T1, T2, L1, L2) Pcdab = cc_equations.ccsd_2rdm_cdab(T1, T2, L1, L2) Pbjai = cc_equations.ccsd_2rdm_bjai(T1, T2, L1, L2) Pklij = cc_equations.ccsd_2rdm_klij(T1, T2, L1, L2) Pbcai = cc_equations.ccsd_2rdm_bcai(T1, T2, L1, L2) Pkaij = cc_equations.ccsd_2rdm_kaij(T1, T2, L1, L2) Pabij = cc_equations.ccsd_2rdm_abij(T1, T2, L1, L2) # make unrestricted RDMs Pijab_u = L2aa.copy() PIJAB_u = L2bb.copy() PiJaB_u = L2ab.copy() Pciab_u, PCIAB_u, PcIaB_u, PCiAb_u = cc_equations.uccsd_2rdm_ciab( T1a, T1b, T2aa, T2ab, T2bb, L1a, L1b, L2aa, L2ab, L2bb) Pjkai_u, PJKAI_u, PjKaI_u, PJkAi_u = cc_equations.uccsd_2rdm_jkai( T1a, T1b, T2aa, T2ab, T2bb, L1a, L1b, L2aa, L2ab, L2bb) Pcdab_u, PCDAB_u, PcDaB_u = cc_equations.uccsd_2rdm_cdab( T1a, T1b, T2aa, T2ab, T2bb, L1a, L1b, L2aa, L2ab, L2bb) Pbjai_u, PBJAI_u, PbJaI_u, PbJAi_u, PBjaI_u, PBjAi_u \ = cc_equations.uccsd_2rdm_bjai( T1a, T1b, T2aa, T2ab, T2bb, L1a, L1b, L2aa, L2ab, L2bb) Pklij_u, PKLIJ_u, PkLiJ_u = cc_equations.uccsd_2rdm_klij( T1a, T1b, T2aa, T2ab, T2bb, L1a, L1b, L2aa, L2ab, L2bb) Pbcai_u, PBCAI_u, PbCaI_u, PBcAi_u = cc_equations.uccsd_2rdm_bcai( T1a, T1b, T2aa, T2ab, T2bb, L1a, L1b, L2aa, L2ab, L2bb) Pkaij_u, PKAIJ_u, PkAiJ_u, PKaIj_u = cc_equations.uccsd_2rdm_kaij( T1a, T1b, T2aa, T2ab, T2bb, L1a, L1b, L2aa, L2ab, L2bb) Pabij_u, PABIJ_u, PaBiJ_u = cc_equations.uccsd_2rdm_abij( T1a, T1b, T2aa, T2ab, T2bb, L1a, L1b, L2aa, L2ab, L2bb) # ijab ref = numpy.einsum('ijab,abij->', Pijab, Atot.vvoo) out = numpy.einsum('ijab,abij->', Pijab_u, Aa.vvoo) out += numpy.einsum('ijab,abij->', PIJAB_u, Ab.vvoo) out += 4.0*numpy.einsum('ijab,abij->', PiJaB_u, Aab.vvoo) diff = abs(out - ref) / abs(ref + 0.001) self.assertTrue(diff < thresh, "Error in Pijab: {}".format(diff)) # ciab ref = numpy.einsum('ciab,abci->', Pciab, Atot.vvvo) out = numpy.einsum('ciab,abci->', Pciab_u, Aa.vvvo) out += numpy.einsum('ciab,abci->', PCIAB_u, Ab.vvvo) out += 2.0*numpy.einsum('ciab,abci->', PcIaB_u, Aab.vvvo) out += 2.0*numpy.einsum('ciab,baic->', PCiAb_u, Aab.vvov) diff = abs(out - ref) / abs(ref + 0.001) self.assertTrue(diff < thresh, "Error in Pciab: {}".format(diff)) # jkai ref = numpy.einsum('jkai,aijk->', Pjkai, Atot.vooo) out = numpy.einsum('jkai,aijk->', Pjkai_u, Aa.vooo) out += numpy.einsum('jkai,aijk->', PJKAI_u, Ab.vooo) out += 2.0*numpy.einsum('jKaI,aIjK->', PjKaI_u, Aab.vooo) out += 2.0*numpy.einsum('JkAi,iAkJ->', PJkAi_u, Aab.ovoo) diff = abs(out - ref) / abs(ref + 0.001) self.assertTrue(diff < thresh, "Error in Pciab: {}".format(diff)) # cdab ref = numpy.einsum('cdab,abcd->', Pcdab, Atot.vvvv) out = numpy.einsum('cdab,abcd->', Pcdab_u, Aa.vvvv) out += numpy.einsum('cdab,abcd->', PCDAB_u, Ab.vvvv) out += 4.0*numpy.einsum('cdab,abcd->', PcDaB_u, Aab.vvvv) diff = abs(out - ref) / abs(ref + 0.001) self.assertTrue(diff < thresh, "Error in Pcdab: {}".format(diff)) # bjai ref = numpy.einsum('bjai,aibj->', Pbjai, Atot.vovo) out = numpy.einsum('bjai,aibj->', Pbjai_u, Aa.vovo) out += numpy.einsum('bJaI,aIbJ->', PbJaI_u, Aab.vovo) out -= numpy.einsum('bJAi,iAbJ->', PbJAi_u, Aab.ovvo) out -= numpy.einsum('BjaI,aIjB->', PBjaI_u, Aab.voov) out += numpy.einsum('BjAi,iAjB->', PBjAi_u, Aab.ovov) out += numpy.einsum('BJAI,AIBJ->', PBJAI_u, Ab.vovo) diff = abs(out - ref) / abs(ref + 0.001) self.assertTrue(diff < thresh, "Error in Pbjai: {}".format(diff)) # klij ref = numpy.einsum('klij,ijkl->', Pklij, Atot.oooo) out = numpy.einsum('klij,ijkl->', Pklij_u, Aa.oooo) out += numpy.einsum('klij,ijkl->', PKLIJ_u, Ab.oooo) out += 4.0*numpy.einsum('kLiJ,iJkL->', PkLiJ_u, Aab.oooo) diff = abs(out - ref) / abs(ref + 0.001) self.assertTrue(diff < thresh, "Error in Pklij: {}".format(diff)) # bcai ref = numpy.einsum('bcai,aibc->', Pbcai, Atot.vovv) out = numpy.einsum('bcai,aibc->', Pbcai_u, Aa.vovv) out += 2.0*numpy.einsum('bCaI,aIbC->', PbCaI_u, Aab.vovv) out += 2.0*numpy.einsum('BcAi,iAcB->', PBcAi_u, Aab.ovvv) out += numpy.einsum('bcai,aibc->', PBCAI_u, Ab.vovv) diff = abs(out - ref) / abs(ref + 0.001) self.assertTrue(diff < thresh, "Error in Pbcai: {}".format(diff)) # kaij ref = numpy.einsum('kaij,ijka->', Pkaij, Atot.ooov) out = numpy.einsum('kaij,ijka->', Pkaij_u, Aa.ooov) out += 2.0*numpy.einsum('kaij,ijka->', PkAiJ_u, Aab.ooov) out += 2.0*numpy.einsum('KaIj,jIaK->', PKaIj_u, Aab.oovo) out += numpy.einsum('kaij,ijka->', PKAIJ_u, Ab.ooov) diff = abs(out - ref) / abs(ref + 0.001) self.assertTrue(diff < thresh, "Error in Pkaij: {}".format(diff)) # abij ref = numpy.einsum('abij,ijab->', Pabij, Atot.oovv) out = numpy.einsum('abij,ijab->', Pabij_u, Aa.oovv) out += numpy.einsum('abij,ijab->', PABIJ_u, Ab.oovv) out += 4.0*numpy.einsum('aBiJ,iJaB->', PaBiJ_u, Aab.oovv) diff = abs(out - ref) / abs(ref + 0.001) self.assertTrue(diff < thresh, "Error in Pabij: {}".format(diff))