Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cheaper test variants for Github Actions #97

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/quemb_unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ jobs:
- name: Test with pytest
run: |
cd tests
QUEMB_SKIP_EXPENSIVE_TESTS=true pytest --doctest-modules --junitxml=junit/quemb-test-results_${{ matrix.python-version }}.xml
QUEMB_SKIP_EXPENSIVE_TESTS=true pytest --durations=0 --durations-min=1.0 --doctest-modules --junitxml=junit/quemb-test-results_${{ matrix.python-version }}.xml
mscho527 marked this conversation as resolved.
Show resolved Hide resolved
# If --duration=0, pytest reports all tests that took longer than what was given with durations-min=[time in seconds]


- name: Upload pytest junit results
Expand Down
2 changes: 1 addition & 1 deletion src/quemb/kbe/pbe.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(
nproc: int = 1,
ompnum: int = 4,
iao_val_core: bool = True,
exxdiv: str = "ewald",
exxdiv: str | None = "ewald",
kpts: list[list[float]] | None = None,
cderi: PathLike | None = None,
iao_wannier: bool = False,
Expand Down
56 changes: 51 additions & 5 deletions tests/chem_dm_kBE_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Author(s): Shaun Weatherly
"""

import os
import unittest

from numpy import eye
Expand Down Expand Up @@ -43,9 +44,14 @@ def test_kc2_sto3g_be1_chempot(self) -> None:
cell.build()

self.periodic_test(
cell, kpt, "be1", "C2 (kBE1)", "autogen", -74.64695833012868, only_chem=True
cell, kpt, "be1", "C2 (kBE1)", "autogen", -102.16547952, only_chem=True
)

@unittest.skipIf(libdmet is None, "Module `libdmet` not imported correctly.")
@unittest.skipIf(
os.getenv("QUEMB_SKIP_EXPENSIVE_TESTS") == "true",
"Skipped expensive tests for QuEmb.",
)
def test_kc4_sto3g_be2_density(self) -> None:
kpt = [1, 1, 1]
cell = gto.Cell()
Expand Down Expand Up @@ -73,8 +79,42 @@ def test_kc4_sto3g_be2_density(self) -> None:
"be2",
"C4 (kBE2)",
"autogen",
-149.4085332249809,
-204.44557767,
only_chem=False,
)

@unittest.skipIf(libdmet is None, "Module `libdmet` not imported correctly.")
def test_kc4_sto3g_be2_mp2density(self) -> None:
kpt = [1, 1, 2]
cell = gto.Cell()

a = 10.0
b = 10.0
c = 5.68

lat = eye(3)
lat[0, 0] = a
lat[1, 1] = b
lat[2, 2] = c

cell.a = lat
cell.atom = [["C", (0.0, 0.0, i * 1.42)] for i in range(4)]

cell.unit = "Angstrom"
cell.basis = "sto-3g"
cell.verbose = 0
cell.build()

self.periodic_test(
cell,
kpt,
"be2",
"C4 (kBE2, MP2/frozen core)",
"autogen",
-120.87412293,
solver="MP2",
only_chem=False,
frozen_core=True,
)

def periodic_test(
Expand All @@ -86,7 +126,9 @@ def periodic_test(
frag_type,
target,
delta=1e-4,
solver="CCSD",
only_chem=True,
frozen_core=False,
) -> None:
kpts = cell.make_kpts(kpt, wrap_around=True)
mydf = df.GDF(cell, kpts)
Expand All @@ -99,10 +141,14 @@ def periodic_test(
kmf.kernel()

kfrag = fragpart(
be_type=be_type, mol=cell, frag_type=frag_type, kpt=kpt, frozen_core=True
be_type=be_type,
mol=cell,
frag_type=frag_type,
kpt=kpt,
frozen_core=frozen_core,
)
mykbe = BE(kmf, kfrag, kpts=kpts)
mykbe.optimize(solver="CCSD", only_chem=only_chem)
mykbe = BE(kmf, kfrag, kpts=kpts, exxdiv=None)
mykbe.optimize(solver=solver, only_chem=only_chem)

self.assertAlmostEqual(
mykbe.ebe_tot,
Expand Down
16 changes: 9 additions & 7 deletions tests/chempot_molBE_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ def test_h8_sto3g_ben(self):
mol.charge = 0.0
mol.spin = 0.0
mol.build()
mf = scf.RHF(mol)
mf.kernel()
self.molecular_restricted_test(
mol, "be2", "H8 (BE2)", "hchain_simple", -4.30628355, only_chem=True
mol, mf, "be2", "H8 (BE2)", "hchain_simple", -4.30628355, only_chem=True
)
self.molecular_restricted_test(
mol, "be3", "H8 (BE3)", "hchain_simple", -4.30649890, only_chem=True
mol, mf, "be3", "H8 (BE3)", "hchain_simple", -4.30649890, only_chem=True
)

def test_octane_sto3g_ben(self):
Expand All @@ -40,18 +42,18 @@ def test_octane_sto3g_ben(self):
mol.charge = 0.0
mol.spin = 0.0
mol.build()
mf = scf.RHF(mol)
mf.kernel()
self.molecular_restricted_test(
mol, "be2", "Octane (BE2)", "autogen", -310.33471581, only_chem=True
mol, mf, "be2", "Octane (BE2)", "autogen", -310.33471581, only_chem=True
)
self.molecular_restricted_test(
mol, "be3", "Octane (BE3)", "autogen", -310.33447096, only_chem=True
mol, mf, "be3", "Octane (BE3)", "autogen", -310.33447096, only_chem=True
)

def molecular_restricted_test(
self, mol, be_type, test_name, frag_type, target, delta=1e-4, only_chem=True
self, mol, mf, be_type, test_name, frag_type, target, delta=1e-4, only_chem=True
):
mf = scf.RHF(mol)
mf.kernel()
fobj = fragpart(frag_type=frag_type, be_type=be_type, mol=mol)
mybe = BE(mf, fobj)
mybe.optimize(solver="CCSD", method="QN", only_chem=only_chem)
Expand Down
Loading