Skip to content

Commit

Permalink
Enable whole testsuite (#1)
Browse files Browse the repository at this point in the history
- streamlined build process
- added more tests
- enable static code analysis + linting as part of test suite
  • Loading branch information
mcocdawc authored Nov 20, 2024
1 parent 027c88d commit 14eb856
Show file tree
Hide file tree
Showing 88 changed files with 4,989,410 additions and 293 deletions.
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

0 comments on commit 14eb856

Please sign in to comment.