From d606b49341c9e886c0bdb8d130794d5c46669a2e Mon Sep 17 00:00:00 2001 From: Shaun Weatherly Date: Wed, 16 Oct 2024 15:00:55 -0400 Subject: [PATCH 1/7] Added unittest for BE-DMRG (Insensitive to imports) --- tests/dmrg_molBE_test.py | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/dmrg_molBE_test.py diff --git a/tests/dmrg_molBE_test.py b/tests/dmrg_molBE_test.py new file mode 100644 index 0000000..2e91c22 --- /dev/null +++ b/tests/dmrg_molBE_test.py @@ -0,0 +1,50 @@ +""" +This script tests the QuEmb to block2 interface for performing ground state BE-DMRG. +Author(s): Shaun Weatherly +""" + +import os, unittest, tempfile +from pyscf import cc, gto, scf +from molbe import fragpart, BE + +class TestBE_DMRG(unittest.TestCase): + try: + from pyscf import dmrgscf + except ImportError: + dmrgscf=None + + @unittest.skipIf(dmrgscf is None, "Module `pyscf.dmrgscf` not imported correctly.") + def test_h8_sto3g_pipek(self): + mol = gto.M() + mol.atom = [['H', (0.,0.,i*1.2)] for i in range(8)] + mol.basis = 'sto-3g' + mol.charge = 0 + mol.spin = 0 + mol.build() + self.molecular_DMRG_test(mol, 'be1', 100, 'H8 (BE1)', 'hchain_simple', -4.20236532) + + def molecular_DMRG_test(self, mol, be_type, maxM, test_name, frag_type, target, delta = 1e-4): + with tempfile.TemporaryDirectory() as tmp: + mf = scf.RHF(mol); mf.kernel() + fobj = fragpart(frag_type=frag_type, be_type=be_type, mol=mol) + mybe = BE(mf, fobj, lo_method='pipek', pop_method='lowdin') + mybe.oneshot(solver='block2', + scratch_dir=str(tmp), + maxM=int(maxM), + maxIter=30, + force_cleanup=True) + self.assertAlmostEqual(mybe.ebe_tot, target, + msg = "BE Correlation Energy (Chem. Pot. Optimization) for " + test_name + + " does not match the expected correlation energy!", delta = delta) + tmpfiles = [] + for path, dir_n, file_n in os.walk(tmp, topdown=True): + for n in file_n: + if n.startswith('F.') or n.startswith('FCIDUMP') or n.startswith('node'): + tmpfiles.append(n) + try: + assert len(tmpfiles) == 0 + except Exception as inst: + print(f"DMRG tempfiles not cleared correctly in {test_name}:\n", inst, tmpfiles) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file From 54573d799ef48a0233735c3eb08f3fb718ffd8ca Mon Sep 17 00:00:00 2001 From: Shaun Weatherly Date: Wed, 16 Oct 2024 15:02:52 -0400 Subject: [PATCH 2/7] Remove redundant imports. --- tests/dmrg_molBE_test.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/dmrg_molBE_test.py b/tests/dmrg_molBE_test.py index 2e91c22..6bd2a8f 100644 --- a/tests/dmrg_molBE_test.py +++ b/tests/dmrg_molBE_test.py @@ -3,8 +3,10 @@ Author(s): Shaun Weatherly """ -import os, unittest, tempfile -from pyscf import cc, gto, scf +import os +import unittest +import tempfile +from pyscf import gto, scf from molbe import fragpart, BE class TestBE_DMRG(unittest.TestCase): From d658569df4022999cda596f754e3d0b64e987bf0 Mon Sep 17 00:00:00 2001 From: Shaun Weatherly Date: Wed, 16 Oct 2024 16:09:55 -0400 Subject: [PATCH 3/7] Update quemb_unittest.yml for continuous integration --- .github/workflows/quemb_unittest.yml | 30 +++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/quemb_unittest.yml b/.github/workflows/quemb_unittest.yml index 7925143..e63388a 100644 --- a/.github/workflows/quemb_unittest.yml +++ b/.github/workflows/quemb_unittest.yml @@ -1,7 +1,7 @@ -# Author(s): Minsik Cho +# Author(s): Minsik Cho, Shaun Weatherly # Based on: https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-python -name: Run Unit Tests for quemb +name: Run Unit Tests for quemb (Continuous Integration) on: push: @@ -18,20 +18,44 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Set up Python 3.9 uses: actions/setup-python@v5 with: python-version: "3.9" + - uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} key: ${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ hashFiles('dev-requirements.txt') }} + - name: Install dependencies run: | python -m pip install --upgrade pip pip install --upgrade --upgrade-strategy eager pytest if [ -f requirements.txt ]; then pip install --upgrade --upgrade-strategy eager -r requirements.txt; fi echo ${{ github.workspace }} > $(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")/quemb.pth + - name: Test with pytest run: | - pytest + cd tests + pytest --doctest-modules --junitxml=junit/quemb-test-results_${{ matrix.python-version }}.xml --cov=quemb --cov-report=xml --cov-report=html + if: always() + + - name: Upload pytest junit results + uses: actions/upload-artifact@v4 + with: + name: quemb-test-results_${{ matrix.python-version }} + path: tests/junit/quemb-test-results_${{ matrix.python-version }}.xml + + - name: Upload pytest html results + uses: actions/upload-artifact@v4 + with: + name: quemb-tests-coverage_${{ matrix.python-version }} + path: tests/htmlcov + if: always() + + - name: Download all artifacts + uses: actions/download-artifact@v4 + if: always() + \ No newline at end of file From 196906fde1df1061b8c55a4b347cbd3500df96c0 Mon Sep 17 00:00:00 2001 From: Shaun Weatherly Date: Mon, 21 Oct 2024 11:22:38 -0400 Subject: [PATCH 4/7] Update pytest name --- .github/workflows/quemb_unittest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/quemb_unittest.yml b/.github/workflows/quemb_unittest.yml index e63388a..f5a2400 100644 --- a/.github/workflows/quemb_unittest.yml +++ b/.github/workflows/quemb_unittest.yml @@ -1,7 +1,7 @@ # Author(s): Minsik Cho, Shaun Weatherly # Based on: https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-python -name: Run Unit Tests for quemb (Continuous Integration) +name: Run Unit Tests for quemb on: push: From 9aec3be2d52f20f686355528e11f21917dbb7bef Mon Sep 17 00:00:00 2001 From: Shaun Weatherly Date: Mon, 21 Oct 2024 11:28:38 -0400 Subject: [PATCH 5/7] No artifact download, change pytest args. --- .github/workflows/quemb_unittest.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/quemb_unittest.yml b/.github/workflows/quemb_unittest.yml index f5a2400..a386c47 100644 --- a/.github/workflows/quemb_unittest.yml +++ b/.github/workflows/quemb_unittest.yml @@ -39,7 +39,7 @@ jobs: - name: Test with pytest run: | cd tests - pytest --doctest-modules --junitxml=junit/quemb-test-results_${{ matrix.python-version }}.xml --cov=quemb --cov-report=xml --cov-report=html + pytest --doctest-modules --junitxml=junit/quemb-test-results_${{ matrix.python-version }}.xml if: always() - name: Upload pytest junit results @@ -54,8 +54,3 @@ jobs: name: quemb-tests-coverage_${{ matrix.python-version }} path: tests/htmlcov if: always() - - - name: Download all artifacts - uses: actions/download-artifact@v4 - if: always() - \ No newline at end of file From 89f9efda47c48a01208c27a7e748ed095b394243 Mon Sep 17 00:00:00 2001 From: Shaun Weatherly Date: Mon, 21 Oct 2024 12:42:19 -0400 Subject: [PATCH 6/7] Fixed missing bits in `quemb_unittest.yml` --- .github/workflows/quemb_unittest.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/quemb_unittest.yml b/.github/workflows/quemb_unittest.yml index a386c47..f54223e 100644 --- a/.github/workflows/quemb_unittest.yml +++ b/.github/workflows/quemb_unittest.yml @@ -15,14 +15,17 @@ permissions: jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9", "3.10", "3.11"] steps: - uses: actions/checkout@v4 - - name: Set up Python 3.9 + - name: Set up Python ${{ matrix.python-version }}$ uses: actions/setup-python@v5 with: - python-version: "3.9" + python-version: ${{ matrix.python-version }} - uses: actions/cache@v4 with: @@ -48,9 +51,9 @@ jobs: name: quemb-test-results_${{ matrix.python-version }} path: tests/junit/quemb-test-results_${{ matrix.python-version }}.xml - - name: Upload pytest html results - uses: actions/upload-artifact@v4 - with: - name: quemb-tests-coverage_${{ matrix.python-version }} - path: tests/htmlcov - if: always() + #- name: Upload pytest html results + # uses: actions/upload-artifact@v4 + # with: + # name: quemb-tests-coverage_${{ matrix.python-version }} + # path: tests/htmlcov + # if: always() From 8b1e336c74df376945b822ed67e6c0b123bdef0b Mon Sep 17 00:00:00 2001 From: Shaun Weatherly Date: Mon, 21 Oct 2024 12:51:26 -0400 Subject: [PATCH 7/7] Fixed extraneous `$` and versions. --- .github/workflows/quemb_unittest.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/quemb_unittest.yml b/.github/workflows/quemb_unittest.yml index f54223e..fcc0f83 100644 --- a/.github/workflows/quemb_unittest.yml +++ b/.github/workflows/quemb_unittest.yml @@ -17,12 +17,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.9", "3.10", "3.11"] + python-version: ["3.9", "3.12"] steps: - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }}$ + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }}