Skip to content

Commit

Permalink
Adds tests for DF-CC2 and DF-QCISD
Browse files Browse the repository at this point in the history
  • Loading branch information
obackhouse committed Oct 21, 2023
1 parent 7c6bcb4 commit 5970d66
Show file tree
Hide file tree
Showing 4 changed files with 360 additions and 0 deletions.
102 changes: 102 additions & 0 deletions tests/test_RDFCC2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
"""Tests for the RDFCC2 model.
"""

import unittest

import numpy as np
import pytest
from pyscf import gto, scf, lib

from ebcc import REBCC, NullLogger, Space


@pytest.mark.regression
class RDFCC2_Tests(unittest.TestCase):
"""Test RDFCC2 against RCC2.
"""

@classmethod
def setUpClass(cls):
mol = gto.Mole()
mol.atom = "O 0.0 0.0 0.11779; H 0.0 0.755453 -0.471161; H 0.0 -0.755453 -0.471161"
mol.basis = "cc-pvdz"
mol.verbose = 0
mol.build()

mf = scf.RHF(mol)
mf.conv_tol = 1e-12
mf.kernel()

cc2_ref = REBCC(
mf,
ansatz="CC2",
log=NullLogger(),
)
cc2_ref.options.e_tol = 1e-10
eris = cc2_ref.get_eris()
cc2_ref.kernel(eris=eris)
cc2_ref.solve_lambda(eris=eris)

mf = mf.density_fit(auxbasis="aug-cc-pvqz-ri")

cc2 = REBCC(
mf,
ansatz="CC2",
log=NullLogger(),
)
cc2.options.e_tol = 1e-10
eris = cc2.get_eris()
cc2.kernel(eris=eris)
cc2.solve_lambda(eris=eris)

cls.mf, cls.cc2_ref, cls.cc2 = mf, cc2_ref, cc2

@classmethod
def teardownclass(cls):
del cls.mf, cls.cc2_ref, cls.cc2

def test_converged(self):
self.assertTrue(self.cc2.converged)
self.assertTrue(self.cc2.converged_lambda)
self.assertTrue(self.cc2_ref.converged)
self.assertTrue(self.cc2_ref.converged_lambda)

def test_energy(self):
a = self.cc2_ref.e_tot
b = self.cc2.e_tot
self.assertAlmostEqual(a, b, 5)

def test_t1_amplitudes(self):
a = self.cc2_ref.t1
b = self.cc2.t1
np.testing.assert_almost_equal(a, b, 4)

def test_t2_amplitudes(self):
a = self.cc2_ref.t2
b = self.cc2.t2
np.testing.assert_almost_equal(a, b, 4)

def test_l1_amplitudes(self):
a = self.cc2_ref.l1
b = self.cc2.l1
np.testing.assert_almost_equal(a, b, 4)

def test_l2_amplitudes(self):
a = self.cc2_ref.l2
b = self.cc2.l2
np.testing.assert_almost_equal(a, b, 4)

def test_rdm1(self):
a = self.cc2_ref.make_rdm1_f()
b = self.cc2.make_rdm1_f()
np.testing.assert_almost_equal(a, b, 4, verbose=True)

def test_rdm2(self):
a = self.cc2_ref.make_rdm2_f()
b = self.cc2.make_rdm2_f()
np.testing.assert_almost_equal(a, b, 4, verbose=True)


if __name__ == "__main__":
print("Tests for RDFCC2")
unittest.main()
78 changes: 78 additions & 0 deletions tests/test_RDFQCISD.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""Tests for the RDFQCISD model.
"""

import unittest

import numpy as np
import pytest
from pyscf import gto, scf, lib

from ebcc import REBCC, NullLogger, Space


@pytest.mark.regression
class RDFQCISD_Tests(unittest.TestCase):
"""Test RDFQCISD against RQCISD.
"""

@classmethod
def setUpClass(cls):
mol = gto.Mole()
mol.atom = "O 0.0 0.0 0.11779; H 0.0 0.755453 -0.471161; H 0.0 -0.755453 -0.471161"
mol.basis = "cc-pvdz"
mol.verbose = 0
mol.build()

mf = scf.RHF(mol)
mf.conv_tol = 1e-12
mf.kernel()

qcisd_ref = REBCC(
mf,
ansatz="QCISD",
log=NullLogger(),
)
qcisd_ref.options.e_tol = 1e-10
eris = qcisd_ref.get_eris()
qcisd_ref.kernel(eris=eris)

mf = mf.density_fit(auxbasis="aug-cc-pvqz-ri")

qcisd = REBCC(
mf,
ansatz="QCISD",
log=NullLogger(),
)
qcisd.options.e_tol = 1e-10
eris = qcisd.get_eris()
qcisd.kernel(eris=eris)

cls.mf, cls.qcisd_ref, cls.qcisd = mf, qcisd_ref, qcisd

@classmethod
def teardownclass(cls):
del cls.mf, cls.qcisd_ref, cls.qcisd

def test_converged(self):
self.assertTrue(self.qcisd.converged)
self.assertTrue(self.qcisd_ref.converged)

def test_energy(self):
a = self.qcisd_ref.e_tot
b = self.qcisd.e_tot
self.assertAlmostEqual(a, b, 5)

def test_t1_amplitudes(self):
a = self.qcisd_ref.t1
b = self.qcisd.t1
np.testing.assert_almost_equal(a, b, 4)

def test_t2_amplitudes(self):
a = self.qcisd_ref.t2
b = self.qcisd.t2
np.testing.assert_almost_equal(a, b, 4)


if __name__ == "__main__":
print("Tests for RDFQCISD")
unittest.main()
102 changes: 102 additions & 0 deletions tests/test_UDFCC2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
"""Tests for the UDFCC2 model.
"""

import unittest

import numpy as np
import pytest
from pyscf import gto, scf, lib

from ebcc import UEBCC, NullLogger, Space


@pytest.mark.regression
class UDFCC2_Tests(unittest.TestCase):
"""Test UDFCC2 against UCC2.
"""

@classmethod
def setUpClass(cls):
mol = gto.Mole()
mol.atom = "O 0.0 0.0 0.11779; H 0.0 0.755453 -0.471161; H 0.0 -0.755453 -0.471161"
mol.basis = "cc-pvdz"
mol.verbose = 0
mol.build()

mf = scf.RHF(mol)
mf.conv_tol = 1e-12
mf.kernel()

cc2_ref = UEBCC(
mf,
ansatz="CC2",
log=NullLogger(),
)
cc2_ref.options.e_tol = 1e-10
eris = cc2_ref.get_eris()
cc2_ref.kernel(eris=eris)
cc2_ref.solve_lambda(eris=eris)

mf = mf.density_fit(auxbasis="aug-cc-pvqz-ri")

cc2 = UEBCC(
mf,
ansatz="CC2",
log=NullLogger(),
)
cc2.options.e_tol = 1e-10
eris = cc2.get_eris()
cc2.kernel(eris=eris)
cc2.solve_lambda(eris=eris)

cls.mf, cls.cc2_ref, cls.cc2 = mf, cc2_ref, cc2

@classmethod
def teardownclass(cls):
del cls.mf, cls.cc2_ref, cls.cc2

def test_converged(self):
self.assertTrue(self.cc2.converged)
self.assertTrue(self.cc2.converged_lambda)
self.assertTrue(self.cc2_ref.converged)
self.assertTrue(self.cc2_ref.converged_lambda)

def test_energy(self):
a = self.cc2_ref.e_tot
b = self.cc2.e_tot
self.assertAlmostEqual(a, b, 5)

def test_t1_amplitudes(self):
a = self.cc2_ref.t1.aa
b = self.cc2.t1.aa
np.testing.assert_almost_equal(a, b, 4)

def test_t2_amplitudes(self):
a = self.cc2_ref.t2.aaaa
b = self.cc2.t2.aaaa
np.testing.assert_almost_equal(a, b, 4)

def test_l1_amplitudes(self):
a = self.cc2_ref.l1.aa
b = self.cc2.l1.aa
np.testing.assert_almost_equal(a, b, 4)

def test_l2_amplitudes(self):
a = self.cc2_ref.l2.aaaa
b = self.cc2.l2.aaaa
np.testing.assert_almost_equal(a, b, 4)

def test_rdm1(self):
a = self.cc2_ref.make_rdm1_f().aa
b = self.cc2.make_rdm1_f().aa
np.testing.assert_almost_equal(a, b, 4, verbose=True)

def test_rdm2(self):
a = self.cc2_ref.make_rdm2_f().aaaa
b = self.cc2.make_rdm2_f().aaaa
np.testing.assert_almost_equal(a, b, 4, verbose=True)


if __name__ == "__main__":
print("Tests for UDFCC2")
unittest.main()
78 changes: 78 additions & 0 deletions tests/test_UDFQCISD.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""Tests for the UDFQCISD model.
"""

import unittest

import numpy as np
import pytest
from pyscf import gto, scf, lib

from ebcc import UEBCC, NullLogger, Space


@pytest.mark.regression
class UDFQCISD_Tests(unittest.TestCase):
"""Test UDFQCISD against UQCISD.
"""

@classmethod
def setUpClass(cls):
mol = gto.Mole()
mol.atom = "O 0.0 0.0 0.11779; H 0.0 0.755453 -0.471161; H 0.0 -0.755453 -0.471161"
mol.basis = "cc-pvdz"
mol.verbose = 0
mol.build()

mf = scf.RHF(mol)
mf.conv_tol = 1e-12
mf.kernel()

qcisd_ref = UEBCC(
mf,
ansatz="QCISD",
log=NullLogger(),
)
qcisd_ref.options.e_tol = 1e-10
eris = qcisd_ref.get_eris()
qcisd_ref.kernel(eris=eris)

mf = mf.density_fit(auxbasis="aug-cc-pvqz-ri")

qcisd = UEBCC(
mf,
ansatz="QCISD",
log=NullLogger(),
)
qcisd.options.e_tol = 1e-10
eris = qcisd.get_eris()
qcisd.kernel(eris=eris)

cls.mf, cls.qcisd_ref, cls.qcisd = mf, qcisd_ref, qcisd

@classmethod
def teardownclass(cls):
del cls.mf, cls.qcisd_ref, cls.qcisd

def test_converged(self):
self.assertTrue(self.qcisd.converged)
self.assertTrue(self.qcisd_ref.converged)

def test_energy(self):
a = self.qcisd_ref.e_tot
b = self.qcisd.e_tot
self.assertAlmostEqual(a, b, 5)

def test_t1_amplitudes(self):
a = self.qcisd_ref.t1.aa
b = self.qcisd.t1.aa
np.testing.assert_almost_equal(a, b, 4)

def test_t2_amplitudes(self):
a = self.qcisd_ref.t2.aaaa
b = self.qcisd.t2.aaaa
np.testing.assert_almost_equal(a, b, 4)


if __name__ == "__main__":
print("Tests for UDFQCISD")
unittest.main()

0 comments on commit 5970d66

Please sign in to comment.