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

Enable whole testsuite #1

Merged
merged 46 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
eb34fb5
don't skip tests in GitHub Actions
mcocdawc Nov 2, 2024
d53f312
skip test_octane_BE2
mcocdawc Nov 4, 2024
d5326e9
move packages into src/ directory
mcocdawc Nov 4, 2024
eb55a5f
install DMRG scf as part of test-suite
mcocdawc Nov 4, 2024
188cb2d
wrong directory in github actions
mcocdawc Nov 4, 2024
207c687
raise DMRG failing as error
mcocdawc Nov 4, 2024
f41e93e
pure syntactical refactoring according to PEP8
mcocdawc Nov 4, 2024
be703fc
Did automatic save fixes by `ruff`
mcocdawc Nov 4, 2024
54fdd29
reenable all tests
mcocdawc Nov 6, 2024
fbd4094
fix small naming error in dmrg example
mcocdawc Nov 7, 2024
3cee539
added .ruff.toml
mcocdawc Nov 12, 2024
c238ac9
reformat imports as well
mcocdawc Nov 12, 2024
ccd496d
fixed kbe_polyacetylene.py and turned into test
mcocdawc Nov 13, 2024
166fe87
give better error when using density matching and BE1
mcocdawc Nov 13, 2024
95f778c
fixed molbe_h8_density_matching.py example
mcocdawc Nov 13, 2024
8be49a9
turned the molbe_h8 examples into test
mcocdawc Nov 13, 2024
9a90834
copied data to test directory
mcocdawc Nov 13, 2024
52d9086
added reference octane FCIDUMPs
mcocdawc Nov 13, 2024
f244808
added test for fcidump writing
mcocdawc Nov 13, 2024
f4430b2
added FCIDUMP test (which fails!!! :-(( )
mcocdawc Nov 14, 2024
f12da87
added test for fcidump writing
mcocdawc Nov 14, 2024
14b4b92
added test for molbe rdms
mcocdawc Nov 14, 2024
a07907d
added another (currently failing) test from examples
mcocdawc Nov 14, 2024
a1e98f5
turned QM/MM example into test
mcocdawc Nov 14, 2024
1f65e11
added failing test
mcocdawc Nov 14, 2024
715a20b
properly renamed
mcocdawc Nov 14, 2024
b8d08f9
added explicit failing tests
mcocdawc Nov 14, 2024
74e0bb4
fixed fcidump writer test
mcocdawc Nov 14, 2024
19a21bb
avoid the custom libdmet
mcocdawc Nov 19, 2024
0dd2a31
Merge branch 'main' of github.com:troyvvgroup/quemb into enable_whole…
mcocdawc Nov 19, 2024
2e05286
mark DMRG as currently known to fail
mcocdawc Nov 19, 2024
5e15186
use distorted C1 octane for test
mcocdawc Nov 19, 2024
b0a1071
play around with molbe_io_fcidump test
mcocdawc Nov 19, 2024
a9b61d5
fixed abs call
mcocdawc Nov 19, 2024
17217aa
test if the deviation is consistent
mcocdawc Nov 19, 2024
302af67
mark molbe_io_fcidump_test.py as known to fail
mcocdawc Nov 19, 2024
b4219bc
skip known to fail tests
mcocdawc Nov 20, 2024
348e89b
make doc fails when hitting warnings
mcocdawc Nov 20, 2024
5792835
make sure that quemb is installed for the docs
mcocdawc Nov 20, 2024
1f9f657
apply `ruff format`
mcocdawc Nov 20, 2024
8316165
Merge branch 'format_PEP8' into enable_whole_testsuite
mcocdawc Nov 20, 2024
6a4a107
enable ruff testing
mcocdawc Nov 20, 2024
93fafb4
don't execute pytest if static analysis fails
mcocdawc Nov 20, 2024
f6227dd
for the moment always report success for ruff
mcocdawc Nov 20, 2024
c4e2875
Merge branch 'main' into enable_whole_testsuite
mcocdawc Nov 20, 2024
3b5e7b8
fixed typo
mcocdawc Nov 20, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install --upgrade --upgrade-strategy eager -r docs/requirements.txt
echo ${{ github.workspace }} > $(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")/quemb.pth
- name: Test building docs & Archive the results
Expand Down
37 changes: 25 additions & 12 deletions .github/workflows/quemb_unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,46 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Prepare pip
run: |
python -m pip install --upgrade pip


- 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
pip install --upgrade --upgrade-strategy eager pytest ruff
if [ -f requirements.txt ]; then pip install --upgrade --upgrade-strategy eager -r requirements.txt; fi
pip install git+https://github.com/pyscf/dmrgscf
PYSCFHOME=$(pip show pyscf-dmrgscf | grep 'Location' | tr ' ' '\n' | tail -n 1)
wget https://raw.githubusercontent.com/pyscf/dmrgscf/master/pyscf/dmrgscf/settings.py.example
mv settings.py.example ${PYSCFHOME}/pyscf/dmrgscf/settings.py
pip install .
echo ${{ github.workspace }} > $(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")/quemb.pth


- name: Check formatting
run: |
ruff format --diff || true # for the moment we want to report always report success


- name: Static analysis
run: |
ruff check . || true # for the moment we want to report always report success


- name: Test with pytest
run: |
cd tests
pytest --doctest-modules --junitxml=junit/quemb-test-results_${{ matrix.python-version }}.xml
if: always()
QUEMB_SKIP_EXPENSIVE_TESTS=true pytest --doctest-modules --junitxml=junit/quemb-test-results_${{ matrix.python-version }}.xml

- 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()
path: tests/junit/quemb-test-results_${{ matrix.python-version }}.xml
14 changes: 14 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[lint]
# see the rules [here](https://docs.astral.sh/ruff/rules/)
select = ["E", "F", "I", "NPY", "ARG"]
# select = ["E501"]
ignore = [
"S101",
# https://docs.astral.sh/ruff/rules/assert/
# We want to use assert especially because it is disabled for
# optimized builds.
"E741",
# https://docs.astral.sh/ruff/rules/ambiguous-variable-name/
# Prevents the use of the characters 'l', 'O', or 'I' as variable names.
# Overly restrictive, in particular when implementing mathematical expressions.
]
5 changes: 1 addition & 4 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
# the additional (!) requirements for building the doc
sphinx_rtd_theme
numpy
scipy
h5py
pyscf
7 changes: 4 additions & 3 deletions example/kbe_polyacetylene.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
# pyscf's periodic HF calculation

import numpy
from pyscf.pbc import gto, scf, df
from kbe import fragpart, BE
from pyscf.pbc import df, gto, scf

from kbe import BE, fragpart

kpt = [1, 1, 3]
cell = gto.Cell()
Expand Down Expand Up @@ -49,7 +50,7 @@
# Define fragment in the supercell
kfrag = fragpart(be_type="be2", mol=cell, kpt=kpt, frozen_core=True)
# Initialize BE
mykbe = BE(kmf, fobj, kpts=kpts)
mykbe = BE(kmf, kfrag, kpts=kpts)

# Perform BE density matching
mykbe.optimize(solver="CCSD")
9 changes: 6 additions & 3 deletions example/molbe_dmrg_block2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
# `block2` is a DMRG and sparse tensor network library developed by the
# Garnet-Chan group at Caltech: https://block2.readthedocs.io/en/latest/index.html

import os, numpy, sys
import os

import matplotlib.pyplot as plt
from pyscf import gto, scf, fci, cc
import numpy
from pyscf import cc, fci, gto, scf

from molbe import BE, fragpart

# We'll consider the dissociation curve for a 1D chain of 8 H-atoms:
Expand Down Expand Up @@ -54,7 +57,7 @@
# Next, run BE-DMRG with default parameters and maxM=100.
mybe.oneshot(
solver="block2", # or 'DMRG', 'DMRGSCF', 'DMRGCI'
scratch=scratch, # Scratch dir for fragment DMRG
scratch_dir=scratch, # Scratch dir for fragment DMRG
maxM=100, # Max fragment bond dimension
force_cleanup=True, # Remove all fragment DMRG tmpfiles
)
Expand Down
3 changes: 2 additions & 1 deletion example/molbe_h8_chemical_potential.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Illustrates a simple molecular BE calculation with chemical
# potential matching

from pyscf import gto, scf, fci
from pyscf import fci, gto, scf

from molbe import BE, fragpart

# PySCF HF generated mol & mf (molecular desciption & HF object)
Expand Down
15 changes: 2 additions & 13 deletions example/molbe_h8_density_matching.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Illustrates a simple molecular BE calculation with BE
# density matching between edge & centers of fragments.

from pyscf import gto, scf, fci
from pyscf import fci, gto, scf

from molbe import BE, fragpart

# PySCF HF generated mol & mf (molecular desciption & HF object)
Expand Down Expand Up @@ -31,18 +32,6 @@

# Perform BE calculations with different fragment schemes:

# Define BE1 fragments
fobj = fragpart(be_type="be1", mol=mol)
# Initialize BE
mybe = BE(mf, fobj)
# Density matching in BE
mybe.optimize(solver="FCI")

# Compute BE error
be_ecorr = mybe.ebe_tot - mybe.ebe_hf
err_ = (fci_ecorr - be_ecorr) * 100.0 / fci_ecorr
print(f"*** BE1 Correlation Energy Error (%) : {err_:>8.4f} %")

# Define BE2 fragments
fobj = fragpart(be_type="be2", mol=mol)
mybe = BE(mf, fobj)
Expand Down
5 changes: 2 additions & 3 deletions example/molbe_hexene_oneshot_uccsd.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Illustrates a one-shot BE UCCSD calculation from UHF reference
# for hexene anion

import numpy

from pyscf import gto, scf
from molbe import fragpart, UBE, be_var
import sys

from molbe import UBE, fragpart

# Set up scratch directory settings
# be_var.SCRATCH='{scratch location}'
Expand Down
7 changes: 2 additions & 5 deletions example/molbe_io_fcidump.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# Illustrates how fcidump file containing fragment hamiltonian
# can be generated using be2fcidump

from pyscf import gto, scf
from molbe import BE
from molbe import fragpart
from molbe.misc import *
from molbe import be_var
from molbe import BE, be_var, fragpart
from molbe.misc import be2fcidump, libint2pyscf

be_var.PRINT_LEVEL = 3

Expand Down
5 changes: 3 additions & 2 deletions example/molbe_octane.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Illustrates parallelized BE computation on octane

from pyscf import gto, scf, cc
from molbe import fragpart, BE
from pyscf import cc, gto, scf

from molbe import BE, fragpart

# Perform pyscf HF calculation to get mol & mf objects
mol = gto.M(
Expand Down
3 changes: 2 additions & 1 deletion example/molbe_octane_get_rdms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Illustrates parallelized BE computation on octane

from pyscf import gto, scf
from molbe import fragpart, BE

from molbe import BE, fragpart

# Perform pyscf HF calculation to get mol & mf objects
mol = gto.M(
Expand Down
4 changes: 2 additions & 2 deletions example/molbe_oneshot_rbe_hcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# PySCF formats

import numpy
from pyscf import gto, scf, qmmm
from pyscf import gto, qmmm, scf

from molbe.misc import be2puffin
from molbe import be_var

# variables for scratch handling
# pbe_var.SCRATCH = '{}'
Expand Down
3 changes: 0 additions & 3 deletions example/molbe_oneshot_rbe_qmmm-fromchk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
# using the be2puffin functionality, starting from a checkfile.
# Returns BE CCSD energy for the system

import numpy
from pyscf import gto, scf, qmmm
from molbe.misc import be2puffin
from molbe import be_var

# variables for scratch handling
# pbe_var.SCRATCH = '{}'
Expand Down
2 changes: 0 additions & 2 deletions example/molbe_oneshot_ube_qmmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
# using the be2puffin functionality.
# Returns UBE UCCSD energy for the system

import numpy
from molbe.misc import be2puffin
from molbe import be_var

# variables for scratch handling
# pbe_var.SCRATCH = '{}'
Expand Down
3 changes: 2 additions & 1 deletion example/molbe_ppp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Perform BE calculation with 6-31g basis set

from pyscf import gto, scf
from molbe import fragpart, BE

from molbe import BE, fragpart

# Perform pyscf HF calculation to get mol & mf objects
mol = gto.M(
Expand Down
6 changes: 1 addition & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
pyscf==2.6.2
pytest==8.3.2
# TODO this temporarily points to mcocdawc/libdmet_preview.
# as soon as this PR: https://github.com/gkclab/libdmet_preview/pull/21
# is merged, let it point to the original libdmet
# https://github.com/gkclab/libdmet_preview
libdmet @ git+https://github.com/mcocdawc/libdmet_preview.git@add_fixes_for_BE
libdmet @ git+https://github.com/gkclab/libdmet_preview.git
matplotlib
11 changes: 4 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from setuptools import setup, find_packages

# Read the contents of your README file
from pathlib import Path

from setuptools import find_packages, setup

this_directory = Path(__file__).parent
long_description = (this_directory / "README.md").read_text()

Expand All @@ -14,17 +14,14 @@
long_description_content_type="text/markdown",
url="https://github.com/oimeitei/quemb",
license="Apache 2.0",
packages=find_packages(),
packages=find_packages("src"),
package_dir={"": "src"},
python_requires=">=3.7",
install_requires=[
"numpy>=1.22.0",
"scipy>=1.7.0",
"pyscf>=2.0.0",
"matplotlib",
# TODO this temporarily points to mcocdawc/libdmet_preview.
# as soon as this PR: https://github.com/gkclab/libdmet_preview/pull/21
# is merged, let it point to the original libdmet
# https://github.com/gkclab/libdmet_preview
"libdmet @ git+https://github.com/mcocdawc/libdmet_preview.git@add_fixes_for_BE",
],
)
File renamed without changes.
File renamed without changes.
26 changes: 14 additions & 12 deletions kbe/autofrag.py → src/kbe/autofrag.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Author(s): Oinam Romesh Meitei

import sys

import numpy

from molbe.helper import get_core
from itertools import compress


def warn_large_fragment():
Expand Down Expand Up @@ -103,13 +104,13 @@ def sidefunc(
for lmin1 in unit2[numpy.where(unit1 == Idx)[0]]:
for jdx, j in enumerate(coord):
if (
not jdx in unit1
and not jdx in unit2
jdx not in unit1
and jdx not in unit2
and not cell.atom_pure_symbol(jdx) == "H"
):
dist = numpy.linalg.norm(coord[lmin1] - j)
if dist <= bond:
if not jdx in sub_list: # avoid repeated occurence
if jdx not in sub_list: # avoid repeated occurence
main_list.append(jdx)
sub_list.append(jdx)
close_be3.append(jdx)
Expand All @@ -119,8 +120,8 @@ def sidefunc(
if kdx == jdx:
continue
if (
not kdx in unit1
and not kdx in unit2
kdx not in unit1
and kdx not in unit2
and not cell.atom_pure_symbol(kdx) == "H"
):
dist = numpy.linalg.norm(coord[jdx] - k)
Expand Down Expand Up @@ -165,10 +166,10 @@ def surround(
NK=NK,
rlist=rlist,
)
sublist = [tmpi for tmpi in sublist_ if not tmpi in rlist]
sublist = [tmpi for tmpi in sublist_ if tmpi not in rlist]
sublist = []
for tmpi in sublist_:
if not tmpi in rlist:
if tmpi not in rlist:
for tmp_jdx, tmpj in enumerate(ext_list):
if tmpj == tmpi and klist[tmp_jdx] == NK:
break
Expand Down Expand Up @@ -311,6 +312,7 @@ def autogen(
Weights for each fragment. Each entry contains a weight and a list of LO indices.
"""
from pyscf import lib

from .misc import sgeom

if not float(unitcell).is_integer():
Expand Down Expand Up @@ -1311,9 +1313,9 @@ def autogen(
and dist in inter_layer_dict[idx][1]
and jdx in inter_layer_dict[idx][0]
and dist < perpend_dist * ang2bohr
and not jdx in pedg
and jdx not in pedg
):
if not jdx in clist_check:
if jdx not in clist_check:
flist.append(jdx)
pedg.append(jdx)
if dist > bond:
Expand Down Expand Up @@ -1732,7 +1734,7 @@ def autogen(
and kdx in inter_layer_dict[jdx][0]
and dist < perpend_dist * ang2bohr
):
if not kdx in pedg and not kdx in clist_check:
if kdx not in pedg and kdx not in clist_check:
flist.append(kdx)
pedg.append(kdx)
if be_type == "be4":
Expand Down Expand Up @@ -1937,7 +1939,7 @@ def autogen(
)
w.close()

if not valence_basis is None:
if valence_basis is not None:
pao = True
else:
pao = False
Expand Down
Loading