From 168470ab58bcd5df5c46282c4d137acd60d51bdb Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Tue, 10 Dec 2024 16:33:33 -0500 Subject: [PATCH 01/27] better typing and fixed a minor bug for cubegen --- src/quemb/shared/helper.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/quemb/shared/helper.py b/src/quemb/shared/helper.py index 428a9a3e..f28621e6 100644 --- a/src/quemb/shared/helper.py +++ b/src/quemb/shared/helper.py @@ -1,5 +1,6 @@ +from collections.abc import Sequence from pathlib import Path -from typing import Any, Callable, Optional, TypeVar +from typing import Any, Callable, Optional, TypeVar, Dict from pyscf.tools.cubegen import orbital @@ -71,26 +72,30 @@ def ncore_(z: int) -> int: def write_cube( - be_object: object, cube_file_path: PathLike, fragment_idx: Optional[list], **kwargs + be_object: molbe.BE, + cube_file_path: PathLike, + fragment_idx: Optional[Sequence[int]] = None, + cubegen_kwargs: Optional[Dict[str, Any]] = None, ) -> None: """Write cube files of embedding orbitals from a BE object. Parameters ---------- - be_object : object + be_object BE object containing the fragments, each of which contains embedding orbitals. - cube_file_path : PathLike + cube_file_path Directory to write the cube files to. - fragment_idx : Optional[list] + fragment_idx Index of the fragments to write the cube files for. If None, write all fragments. - kwargs: Any + cubegen_kwargs Keyword arguments passed to cubegen.orbital. """ cube_file_path = Path(cube_file_path) + cubegen_kwargs = cubegen_kwargs if cubegen_kwargs else {} if not isinstance(be_object, molbe.BE): raise NotImplementedError("Support for Periodic BE not implemented yet.") - if not fragment_idx: + if fragment_idx is None: fragment_idx = range(be_object.Nfrag) for idx in fragment_idx: for emb_orb_idx in range(be_object.Fobjs[idx].TA.shape[1]): @@ -98,5 +103,5 @@ def write_cube( be_object.mol, cube_file_path / f"frag_{idx}_orb_{emb_orb_idx}.cube", be_object.Fobjs[idx].TA[:, emb_orb_idx], - **kwargs, + **cubegen_kwargs, ) From 3e833ed00ddb605806268b813eb480395e2977a4 Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Tue, 10 Dec 2024 16:34:13 -0500 Subject: [PATCH 02/27] explicitly fail when `lo_method == "iao" and iao_val_core` this automatically fixes a non-resolved import as well --- src/quemb/kbe/lo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quemb/kbe/lo.py b/src/quemb/kbe/lo.py index 1a6914bb..488e45f1 100644 --- a/src/quemb/kbe/lo.py +++ b/src/quemb/kbe/lo.py @@ -55,7 +55,7 @@ def localize( Whether to perform Wannier localization in the IAO space """ if lo_method == "iao" and iao_val_core: - raise NotImplementedError("This does not work. Contact Developers.") + raise NotImplementedError("iao_val_core and lo_method='iao' not supported.") if lo_method == "lowdin": # Lowdin orthogonalization with k-points From 6309fcb6bc4206e565337c3ab36477c183eef391 Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Tue, 10 Dec 2024 16:38:18 -0500 Subject: [PATCH 03/27] kbe should use the molbe be_func and be_func_parallel this fixes the last wrong import --- src/quemb/kbe/pbe.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/quemb/kbe/pbe.py b/src/quemb/kbe/pbe.py index 39c5c8a5..221aed53 100644 --- a/src/quemb/kbe/pbe.py +++ b/src/quemb/kbe/pbe.py @@ -18,7 +18,6 @@ from quemb.molbe.helper import get_eri, get_scfObj, get_veff from quemb.molbe.be_parallel import be_func_parallel from quemb.molbe.solver import be_func - from quemb.shared import be_var from quemb.shared.external.optqn import ( get_be_error_jacobian as _ext_get_be_error_jacobian, From c3a728081cf70f57fabb045475f240b7a9599c2d Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Tue, 10 Dec 2024 17:23:46 -0500 Subject: [PATCH 04/27] fixed mypy of scratch manager --- src/quemb/shared/manage_scratch.py | 18 +++++++++++------- tests/scratch_manager_test.py | 18 +++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/quemb/shared/manage_scratch.py b/src/quemb/shared/manage_scratch.py index c7d214a4..e8db745b 100644 --- a/src/quemb/shared/manage_scratch.py +++ b/src/quemb/shared/manage_scratch.py @@ -5,7 +5,7 @@ from shutil import rmtree from types import TracebackType -from attr import define +from attr import define, field from typing_extensions import Literal, Optional, TypeAlias, Union from quemb.shared.be_var import SCRATCH @@ -13,6 +13,10 @@ PathLike: TypeAlias = Union[str, os.PathLike] +def _get_absolute_path(pathlike: PathLike) -> Path: + return Path(pathlike).resolve() + + @define(order=False) class WorkDir: """Manage a scratch area. @@ -41,13 +45,13 @@ class WorkDir: without errors. """ - path: Path - cleanup_at_end: bool - - def __init__(self, scratch_area: PathLike, cleanup_at_end: bool = True) -> None: - self.path = Path(scratch_area).resolve() - self.cleanup_at_end = cleanup_at_end + path: Path = field(converter=_get_absolute_path) + cleanup_at_end: bool = True + # The __init__ is automatically created + # the values `self.path` and `self.cleanup_at_end` are already filled. + # we define the __attrs_post_init__ to create the directory + def __attrs_post_init__(self) -> None: self.path.mkdir(parents=True, exist_ok=True) if any(self.path.iterdir()): self.cleanup_at_end = False diff --git a/tests/scratch_manager_test.py b/tests/scratch_manager_test.py index 94add337..c971e82c 100644 --- a/tests/scratch_manager_test.py +++ b/tests/scratch_manager_test.py @@ -7,7 +7,7 @@ from quemb.shared.manage_scratch import WorkDir -def test_already_created(): +def test_already_created() -> None: my_tmp = Path(mkdtemp()) assert my_tmp.exists() @@ -20,7 +20,7 @@ def test_already_created(): scratch.cleanup() -def test_keep_upon_error(): +def test_keep_upon_error() -> None: my_tmp = Path(mkdtemp()) assert my_tmp.exists() @@ -34,7 +34,7 @@ def test_keep_upon_error(): assert not my_tmp.exists() -def test_already_created_non_empty(): +def test_already_created_non_empty() -> None: my_tmp = Path(mkdtemp()) assert my_tmp.exists() @@ -48,7 +48,7 @@ def test_already_created_non_empty(): assert my_tmp.exists() -def test_context_manager(): +def test_context_manager() -> None: my_tmp = Path(mkdtemp()) assert my_tmp.exists() @@ -58,7 +58,7 @@ def test_context_manager(): assert not my_tmp.exists() -def test_creation_user_defined(): +def test_creation_user_defined() -> None: test_dir = Path("./scratch_test") with WorkDir("./scratch_test") as scratch: assert test_dir.exists() @@ -66,9 +66,9 @@ def test_creation_user_defined(): assert not test_dir.exists() -def test_creation_PID(): +def test_creation_PID() -> None: PID = os.getpid() - with WorkDir(scratch_area=Path("./scratch_root")) as scratch_root: + with WorkDir(path=Path("./scratch_root")) as scratch_root: tmp_root = scratch_root.path with WorkDir.from_environment(user_defined_root=tmp_root) as dir: assert dir.path == tmp_root / f"QuEmb_{PID}" @@ -76,9 +76,9 @@ def test_creation_PID(): assert dir_2.path == tmp_root / f"QuEmb_{PID + 1}" -def test_dunder_methods(): +def test_dunder_methods() -> None: "Test if we can use an instance of `WorkDir` as if it was a `Path`" - with WorkDir(scratch_area=Path("./scratch")) as scratch: + with WorkDir(path=Path("./scratch")) as scratch: with open(scratch / "test.txt", "w") as f: f.write("hello world") From 9bf111f1d6b316e85da1f6b5da93484084045659 Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Tue, 10 Dec 2024 17:24:01 -0500 Subject: [PATCH 05/27] fixed molbe_io_fcidump_test --- tests/molbe_io_fcidump_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/molbe_io_fcidump_test.py b/tests/molbe_io_fcidump_test.py index 3845efe8..ede232d2 100644 --- a/tests/molbe_io_fcidump_test.py +++ b/tests/molbe_io_fcidump_test.py @@ -15,7 +15,7 @@ from quemb.molbe.misc import be2fcidump, libint2pyscf -def prepare_system(): +def prepare_system() -> BE: # Read in molecular integrals expressed in libint basis ordering # numpy.loadtxt takes care of the input under the hood mol, mf = libint2pyscf( @@ -36,7 +36,7 @@ def prepare_system(): return oct_be -def verify_fcidump_writing(kind_of_MO: str): +def verify_fcidump_writing(kind_of_MO: str) -> None: oct_be = prepare_system() tmp_dir = Path(mkdtemp()) data_dir = Path("data/octane_FCIDUMPs/") @@ -60,7 +60,7 @@ def verify_fcidump_writing(kind_of_MO: str): not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true", reason="This test is known to fail.", ) -def test_embedding(): +def test_embedding() -> None: verify_fcidump_writing("embedding") @@ -68,7 +68,7 @@ def test_embedding(): not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true", reason="This test is known to fail.", ) -def test_fragment_mo(): +def test_fragment_mo() -> None: verify_fcidump_writing("fragment_mo") From 3645ae1fc66765eed52ad499f0a4086047befe5c Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Tue, 10 Dec 2024 17:35:34 -0500 Subject: [PATCH 06/27] improved mypy testing --- example/__init__.py | 3 +++ mypy.ini | 8 ++------ tests/__init__.py | 3 +++ tests/chem_dm_kBE_test.py | 6 +++--- 4 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 example/__init__.py create mode 100644 tests/__init__.py diff --git a/example/__init__.py b/example/__init__.py new file mode 100644 index 00000000..c4216c09 --- /dev/null +++ b/example/__init__.py @@ -0,0 +1,3 @@ +# the __init__.py file only exists so that we can +# have more fine-grained control over which file we want to test how +# in mypy. diff --git a/mypy.ini b/mypy.ini index dbb78019..01100bb4 100644 --- a/mypy.ini +++ b/mypy.ini @@ -3,16 +3,12 @@ disallow_untyped_defs = True check_untyped_defs = True -[mypy-quemb.molbe.*] +[mypy-quemb.molbe.*,quemb.kbe.*,quemb.shared.external.*] disallow_untyped_defs = False check_untyped_defs = False -[mypy-quemb.kbe.*] - disallow_untyped_defs = False - check_untyped_defs = False - -[mypy-quemb.shared.external.*] +[mypy-tests.*,example.*] disallow_untyped_defs = False check_untyped_defs = False diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..c4216c09 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,3 @@ +# the __init__.py file only exists so that we can +# have more fine-grained control over which file we want to test how +# in mypy. diff --git a/tests/chem_dm_kBE_test.py b/tests/chem_dm_kBE_test.py index 076ae4c0..dff2ceea 100644 --- a/tests/chem_dm_kBE_test.py +++ b/tests/chem_dm_kBE_test.py @@ -21,7 +21,7 @@ class Test_kBE_Full(unittest.TestCase): @unittest.skipIf(libdmet is None, "Module `libdmet` not imported correctly.") - def test_kc2_sto3g_be1_chempot(self): + def test_kc2_sto3g_be1_chempot(self) -> None: kpt = [1, 1, 1] cell = gto.Cell() @@ -46,7 +46,7 @@ def test_kc2_sto3g_be1_chempot(self): cell, kpt, "be1", "C2 (kBE1)", "autogen", -74.64695833012868, only_chem=True ) - def test_kc4_sto3g_be2_density(self): + def test_kc4_sto3g_be2_density(self) -> None: kpt = [1, 1, 1] cell = gto.Cell() @@ -87,7 +87,7 @@ def periodic_test( target, delta=1e-4, only_chem=True, - ): + ) -> None: kpts = cell.make_kpts(kpt, wrap_around=True) mydf = df.GDF(cell, kpts) mydf.build() From 8d74c81b42e0abeedbd8590dd2fe03b8de8576ab Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Tue, 10 Dec 2024 17:37:52 -0500 Subject: [PATCH 07/27] fixed a wrong import --- example/molbe_io_fcidump.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/example/molbe_io_fcidump.py b/example/molbe_io_fcidump.py index 3c774d54..239f3897 100644 --- a/example/molbe_io_fcidump.py +++ b/example/molbe_io_fcidump.py @@ -1,8 +1,9 @@ # Illustrates how fcidump file containing fragment hamiltonian # can be generated using be2fcidump -from quemb.molbe import BE, be_var, fragpart +from quemb.molbe import BE, fragpart from quemb.molbe.misc import be2fcidump, libint2pyscf +from quemb.shared import be_var be_var.PRINT_LEVEL = 3 From a8f687f313ef319a374443bb181fd19a0355b321 Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Tue, 10 Dec 2024 17:41:15 -0500 Subject: [PATCH 08/27] more explicit blacklist for tests --- mypy.ini | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mypy.ini b/mypy.ini index 01100bb4..6c9c788d 100644 --- a/mypy.ini +++ b/mypy.ini @@ -7,8 +7,12 @@ disallow_untyped_defs = False check_untyped_defs = False +# blacklist tests +[mypy-tests.chem_dm_kBE_test,tests.chempot_molBE_test,tests.dm_molBE_test,tests.dmrg_molBE_test,tests.eri_onthefly_test,tests.hf-in-hf_BE_test,tests.kbe_polyacetylene_test,tests.molbe_h8_test,tests.molbe_io_fcidump_test,tests.molbe_octane_get_rdms_test,tests.molbe_octane_test,tests.molbe_oneshot_rbe_hcore_test,tests.molbe_oneshot_rbe_qmmm-fromchk_test,tests.ube-oneshot_test] + disallow_untyped_defs = False + check_untyped_defs = False -[mypy-tests.*,example.*] +[mypy-example.*] disallow_untyped_defs = False check_untyped_defs = False From ca5d1119c19ec1d07003539df7165e15956f40cb Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Tue, 10 Dec 2024 17:43:09 -0500 Subject: [PATCH 09/27] enable the test for mypy --- .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 17964874..ea193b96 100644 --- a/.github/workflows/quemb_unittest.yml +++ b/.github/workflows/quemb_unittest.yml @@ -74,7 +74,7 @@ jobs: - name: Static analysis with mypy run: | - mypy tests/ example/ src/ || true # for the moment we want to report always report success + mypy tests/ example/ src/ From 06296dc7bbc0738bc622c56e79c4a9a9a95b619e Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Wed, 11 Dec 2024 09:54:24 -0500 Subject: [PATCH 10/27] moved write_cube to shared.io this fixes a circular import of molbe.BE molbe.BE depends on shared/helper, so we cannot import it in shared/helper.py --- src/quemb/shared/helper.py | 49 ++++---------------------------------- src/quemb/shared/io.py | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 44 deletions(-) create mode 100644 src/quemb/shared/io.py diff --git a/src/quemb/shared/helper.py b/src/quemb/shared/helper.py index f28621e6..4b7618fc 100644 --- a/src/quemb/shared/helper.py +++ b/src/quemb/shared/helper.py @@ -1,14 +1,11 @@ -from collections.abc import Sequence -from pathlib import Path -from typing import Any, Callable, Optional, TypeVar, Dict - -from pyscf.tools.cubegen import orbital - -from quemb import molbe -from quemb.shared.manage_scratch import PathLike +from typing import Any, Callable, Dict, Optional, TypeAlias, TypeVar Function = TypeVar("Function", bound=Callable) +# A dictionary that is used to pass keyword arguments via unpacking +# to the next function +KwargDict: TypeAlias = Dict[str, Any] + # Note that we have once Callable and once Function. # This is **intentional**. @@ -69,39 +66,3 @@ def ncore_(z: int) -> int: else: raise ValueError("Ncore not computed in helper.ncore(), add it yourself!") return nc - - -def write_cube( - be_object: molbe.BE, - cube_file_path: PathLike, - fragment_idx: Optional[Sequence[int]] = None, - cubegen_kwargs: Optional[Dict[str, Any]] = None, -) -> None: - """Write cube files of embedding orbitals from a BE object. - - Parameters - ---------- - be_object - BE object containing the fragments, each of which contains embedding orbitals. - cube_file_path - Directory to write the cube files to. - fragment_idx - Index of the fragments to write the cube files for. - If None, write all fragments. - cubegen_kwargs - Keyword arguments passed to cubegen.orbital. - """ - cube_file_path = Path(cube_file_path) - cubegen_kwargs = cubegen_kwargs if cubegen_kwargs else {} - if not isinstance(be_object, molbe.BE): - raise NotImplementedError("Support for Periodic BE not implemented yet.") - if fragment_idx is None: - fragment_idx = range(be_object.Nfrag) - for idx in fragment_idx: - for emb_orb_idx in range(be_object.Fobjs[idx].TA.shape[1]): - orbital( - be_object.mol, - cube_file_path / f"frag_{idx}_orb_{emb_orb_idx}.cube", - be_object.Fobjs[idx].TA[:, emb_orb_idx], - **cubegen_kwargs, - ) diff --git a/src/quemb/shared/io.py b/src/quemb/shared/io.py new file mode 100644 index 00000000..79c9a0a1 --- /dev/null +++ b/src/quemb/shared/io.py @@ -0,0 +1,45 @@ +from collections.abc import Sequence +from pathlib import Path +from typing import Optional + +from pyscf.tools.cubegen import orbital + +from quemb import molbe +from quemb.shared.helper import KwargDict +from quemb.shared.manage_scratch import PathLike + + +def write_cube( + be_object: molbe.BE, + cube_file_path: PathLike, + fragment_idx: Optional[Sequence[int]] = None, + cubegen_kwargs: Optional[KwargDict] = None, +) -> None: + """Write cube files of embedding orbitals from a BE object. + + Parameters + ---------- + be_object + BE object containing the fragments, each of which contains embedding orbitals. + cube_file_path + Directory to write the cube files to. + fragment_idx + Index of the fragments to write the cube files for. + If None, write all fragments. + cubegen_kwargs + Keyword arguments passed to cubegen.orbital. + """ + cube_file_path = Path(cube_file_path) + cubegen_kwargs = cubegen_kwargs if cubegen_kwargs else {} + if not isinstance(be_object, molbe.BE): + raise NotImplementedError("Support for Periodic BE not implemented yet.") + if fragment_idx is None: + fragment_idx = range(be_object.Nfrag) + for idx in fragment_idx: + for emb_orb_idx in range(be_object.Fobjs[idx].TA.shape[1]): + orbital( + be_object.mol, + cube_file_path / f"frag_{idx}_orb_{emb_orb_idx}.cube", + be_object.Fobjs[idx].TA[:, emb_orb_idx], + **cubegen_kwargs, + ) From 5b9c13eaabdf8ed57f009152f6943b8714d29983 Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Wed, 11 Dec 2024 09:56:06 -0500 Subject: [PATCH 11/27] fixed import in test --- tests/molbe_octane_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/molbe_octane_test.py b/tests/molbe_octane_test.py index d60c1842..408e5cbe 100644 --- a/tests/molbe_octane_test.py +++ b/tests/molbe_octane_test.py @@ -9,7 +9,7 @@ from pyscf import cc, gto, scf from quemb.molbe import BE, fragpart -from quemb.shared.helper import write_cube +from quemb.shared.io import write_cube # TODO: actually add meaningful tests for energies etc. # At the moment the test fails already for technical reasons. From 85400498209db5f87d420274510111246b6b7baf Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Wed, 11 Dec 2024 13:36:06 -0500 Subject: [PATCH 12/27] bumped up python versions --- .github/workflows/build_docs.yml | 4 ++-- .github/workflows/quemb_unittest.yml | 4 ++-- README.md | 2 +- setup.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index c9702419..c1fdc582 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -18,10 +18,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Python 3.9 + - name: Set up Python 3.10 uses: actions/setup-python@v5 with: - python-version: "3.9" + python-version: "3.10" cache: 'pip' - name: Install dependencies run: | diff --git a/.github/workflows/quemb_unittest.yml b/.github/workflows/quemb_unittest.yml index ea193b96..a138b3f9 100644 --- a/.github/workflows/quemb_unittest.yml +++ b/.github/workflows/quemb_unittest.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.12"] + python-version: ["3.13"] steps: @@ -83,7 +83,7 @@ jobs: needs: analysis strategy: matrix: - python-version: ["3.9", "3.12"] + python-version: ["3.10", "3.13"] steps: - uses: actions/checkout@v4 diff --git a/README.md b/README.md index 5908b31c..078d031a 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ processors. ### Prerequisites -- Python 3.6 or higher +- Python `>=3.10` - PySCF library - Numpy - Scipy diff --git a/setup.py b/setup.py index f35132ad..ed548467 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ license="Apache 2.0", packages=find_packages("src"), package_dir={"": "src"}, - python_requires=">=3.7", + python_requires=">=3.10", install_requires=[ "numpy>=1.22.0", "scipy>=1.7.0", From fbbcef8773731b486ad538cd75ca07a8ef2f69cf Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Wed, 11 Dec 2024 14:33:05 -0500 Subject: [PATCH 13/27] changed quemb unittest to install pytest earlier --- .github/workflows/quemb_unittest.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/quemb_unittest.yml b/.github/workflows/quemb_unittest.yml index a138b3f9..5baa1f61 100644 --- a/.github/workflows/quemb_unittest.yml +++ b/.github/workflows/quemb_unittest.yml @@ -48,7 +48,7 @@ jobs: - name: Install dependencies run: | - pip install --upgrade --upgrade-strategy eager ruff pylint mypy scipy-stubs + pip install --upgrade --upgrade-strategy eager ruff pylint mypy scipy-stubs pytest pip install . @@ -106,8 +106,6 @@ jobs: - name: Install dependencies run: | - pip install --upgrade --upgrade-strategy eager pytest - 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 From 1cfdd0bc023aeb6c09cedb0bf02550c3dbc61c2b Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Wed, 11 Dec 2024 14:37:33 -0500 Subject: [PATCH 14/27] actually also install pytest for test :-D --- .github/workflows/quemb_unittest.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/quemb_unittest.yml b/.github/workflows/quemb_unittest.yml index 5baa1f61..1010d06f 100644 --- a/.github/workflows/quemb_unittest.yml +++ b/.github/workflows/quemb_unittest.yml @@ -106,6 +106,7 @@ jobs: - name: Install dependencies run: | + pip install pytest 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 From fce077b29b73d4eb3f653d14f30d11320e3eba4d Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Wed, 11 Dec 2024 17:40:15 -0500 Subject: [PATCH 15/27] fixed typing issues in tests --- mypy.ini | 8 ++++---- tests/molbe_octane_test.py | 15 +++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/mypy.ini b/mypy.ini index 6c9c788d..a7f34214 100644 --- a/mypy.ini +++ b/mypy.ini @@ -7,12 +7,12 @@ disallow_untyped_defs = False check_untyped_defs = False -# blacklist tests -[mypy-tests.chem_dm_kBE_test,tests.chempot_molBE_test,tests.dm_molBE_test,tests.dmrg_molBE_test,tests.eri_onthefly_test,tests.hf-in-hf_BE_test,tests.kbe_polyacetylene_test,tests.molbe_h8_test,tests.molbe_io_fcidump_test,tests.molbe_octane_get_rdms_test,tests.molbe_octane_test,tests.molbe_oneshot_rbe_hcore_test,tests.molbe_oneshot_rbe_qmmm-fromchk_test,tests.ube-oneshot_test] +# explicitly blacklist tests +[mypy-tests.chem_dm_kBE_test,tests.chempot_molBE_test,tests.dm_molBE_test,tests.dmrg_molBE_test,tests.eri_onthefly_test,tests.hf-in-hf_BE_test,tests.kbe_polyacetylene_test,tests.molbe_h8_test,tests.molbe_io_fcidump_test,tests.molbe_octane_get_rdms_test,tests.molbe_oneshot_rbe_hcore_test,tests.molbe_oneshot_rbe_qmmm-fromchk_test,tests.ube-oneshot_test] disallow_untyped_defs = False check_untyped_defs = False -[mypy-example.*] +[mypy-example.kbe_polyacetylene,example.molbe_dmrg_block2,example.molbe_h8_chemical_potential,example.molbe_h8_density_matching,example.molbe_hexene_oneshot_uccsd,example.molbe_io_fcidump,example.molbe_octane_get_rdms,example.molbe_octane,example.molbe_oneshot_rbe_hcore,example.molbe_oneshot_rbe_qmmm-fromchk,example.molbe_oneshot_ube_qmmm,example.molbe_ppp] disallow_untyped_defs = False check_untyped_defs = False @@ -29,4 +29,4 @@ ignore_missing_imports = True [mypy-h5py.*] - ignore_missing_imports = True + ignore_missing_imports = True \ No newline at end of file diff --git a/tests/molbe_octane_test.py b/tests/molbe_octane_test.py index 408e5cbe..3a01b7ce 100644 --- a/tests/molbe_octane_test.py +++ b/tests/molbe_octane_test.py @@ -3,6 +3,7 @@ import os import tempfile +from typing import Tuple import numpy as np import pytest @@ -19,7 +20,7 @@ not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true", reason="This test is known to fail.", ) -def test_octane_molbe(): +def test_octane_molbe() -> None: # Prepare octane molecule mol, mf = prepare_octane() @@ -45,7 +46,7 @@ def test_octane_molbe(): print(f"*** BE2 Correlation Energy Error (%) : {err_:>8.4f} %") -def test_cubegen(): +def test_cubegen() -> None: # Prepare octane molecule mol, mf = prepare_octane() # Build fragments @@ -55,23 +56,21 @@ def test_cubegen(): mybe.optimize(solver="CCSD", nproc=1, ompnum=1) # Write cube file to a temporary location with tempfile.TemporaryDirectory() as tmpdir: - write_cube(mybe, tmpdir, fragment_idx=[3], resolution=5) + write_cube(mybe, tmpdir, fragment_idx=[3], cubegen_kwargs=dict(resolution=5)) with open(os.path.join(tmpdir, "frag_3_orb_2.cube"), "r") as f: - cube_content = f.read() cube_content = np.fromstring( - "".join(cube_content.split("\n")[2:]), sep=" ", dtype=float + "".join(f.read().split("\n")[2:]), sep=" ", dtype=float ) with open("data/octane_frag_3_orb_2.cube", "r") as f: - reference_content = f.read() reference_content = np.fromstring( - "".join(reference_content.split("\n")[2:]), sep=" ", dtype=float + "".join(f.read().split("\n")[2:]), sep=" ", dtype=float ) assert np.isclose( cube_content, reference_content ).all(), "Cube file content does not match reference content." -def prepare_octane(): +def prepare_octane() -> Tuple[gto.Mole, scf.hf.RHF]: mol = gto.M( atom=""" C 0.4419364699 -0.6201930287 0.0000000000 From 9eccd2797bae2c84ce6d94ab07a29a7cbbb8cd05 Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Wed, 11 Dec 2024 17:47:36 -0500 Subject: [PATCH 16/27] do explicit blacklist in mypy.ini --- mypy.ini | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mypy.ini b/mypy.ini index a7f34214..5ad72749 100644 --- a/mypy.ini +++ b/mypy.ini @@ -3,11 +3,21 @@ disallow_untyped_defs = True check_untyped_defs = True -[mypy-quemb.molbe.*,quemb.kbe.*,quemb.shared.external.*] + +# explicitly blacklist files, this means we can easily add in stricter type checks +# by removing them from the blacklist +[mypy-quemb.molbe.ube,quemb.molbe.be_parallel,quemb.molbe.autofrag,quemb.molbe.eri_onthefly,quemb.molbe.fragment,quemb.molbe.helper,quemb.molbe.lchain,quemb.molbe.lo,quemb.molbe.mbe,quemb.molbe.misc,quemb.molbe._opt,quemb.molbe.pfrag,quemb.molbe.solver] + disallow_untyped_defs = False + check_untyped_defs = False + +[mypy-quemb.kbe.autofrag,quemb.kbe.chain,quemb.kbe.fragment,quemb.kbe.helper,quemb.kbe.__init__,quemb.kbe.lo_k,quemb.kbe.lo,quemb.kbe.misc,quemb.kbe.pbe,quemb.kbe.pfrag,quemb.kbe.solver] + disallow_untyped_defs = False + check_untyped_defs = False + +[mypy-quemb.shared.external.ccsd_rdm,quemb.shared.external.cphf_utils,quemb.shared.external.cpmp2_utils,quemb.shared.external.__init__,quemb.shared.external.jac_utils,quemb.shared.external.lo_helper,quemb.shared.external.optqn,quemb.shared.external.uccsd_eri,quemb.shared.external.unrestricted_utils] disallow_untyped_defs = False check_untyped_defs = False -# explicitly blacklist tests [mypy-tests.chem_dm_kBE_test,tests.chempot_molBE_test,tests.dm_molBE_test,tests.dmrg_molBE_test,tests.eri_onthefly_test,tests.hf-in-hf_BE_test,tests.kbe_polyacetylene_test,tests.molbe_h8_test,tests.molbe_io_fcidump_test,tests.molbe_octane_get_rdms_test,tests.molbe_oneshot_rbe_hcore_test,tests.molbe_oneshot_rbe_qmmm-fromchk_test,tests.ube-oneshot_test] disallow_untyped_defs = False check_untyped_defs = False From 64d696e7647835d0481888176fbb7a065b022211 Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Wed, 11 Dec 2024 18:16:38 -0500 Subject: [PATCH 17/27] refactored kbe update_heff --- src/quemb/kbe/pfrag.py | 41 +++++++++++++--------------------------- src/quemb/molbe/pfrag.py | 4 +--- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/src/quemb/kbe/pfrag.py b/src/quemb/kbe/pfrag.py index 7fb2d87f..381e4dcc 100644 --- a/src/quemb/kbe/pfrag.py +++ b/src/quemb/kbe/pfrag.py @@ -353,49 +353,34 @@ def update_heff( self, u, cout=None, - return_heff=False, - no_chempot=False, + do_chempot=True, only_chem=False, ): """Update the effective Hamiltonian for the fragment.""" - heff_ = numpy.zeros_like(self.h1) if cout is None: cout = self.udim - if not no_chempot: + if do_chempot: for i, fi in enumerate(self.fsites): if not any(i in sublist for sublist in self.edge_idx): heff_[i, i] -= u[-1] if only_chem: self.heff = heff_ - if return_heff: - if cout is None: - return heff_ - else: - return (cout, heff_) - return cout - - for idx, i in enumerate(self.edge_idx): - for j in range(len(i)): - for k in range(len(i)): - if j > k: - continue - - heff_[i[j], i[k]] = u[cout] - heff_[i[k], i[j]] = u[cout] - - cout += 1 + return + else: + for idx, i in enumerate(self.edge_idx): + for j in range(len(i)): + for k in range(len(i)): + if j > k: + continue + heff_[i[j], i[k]] = u[cout] + heff_[i[k], i[j]] = u[cout] + cout += 1 - self.heff = heff_ - if return_heff: - if cout is None: - return heff_ - else: - return (cout, heff_) - return cout + self.heff = heff_ def set_udim(self, cout): for i in self.edge_idx: diff --git a/src/quemb/molbe/pfrag.py b/src/quemb/molbe/pfrag.py index fe62368a..62c19de0 100644 --- a/src/quemb/molbe/pfrag.py +++ b/src/quemb/molbe/pfrag.py @@ -268,9 +268,7 @@ def scf( mf_ = None def update_heff(self, u, cout=None, only_chem=False): - """ - Update the effective Hamiltonian for the fragment. - """ + """Update the effective Hamiltonian for the fragment.""" heff_ = numpy.zeros_like(self.h1) if cout is None: From b8a67820a3a657249b867eda40fa2f2d8932d0df Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Thu, 12 Dec 2024 12:46:58 -0500 Subject: [PATCH 18/27] updated doc and removed some unnecessary commands - everythying uses `pip install .` now - take out some not-anymore-needed conda specific installation commands - take out PYTHONPATH fiddling --- .github/workflows/quemb_unittest.yml | 1 - README.md | 47 +++++++++++++--------------- docs/source/index.rst | 5 +++ docs/source/install.rst | 39 ++++++++++------------- 4 files changed, 44 insertions(+), 48 deletions(-) diff --git a/.github/workflows/quemb_unittest.yml b/.github/workflows/quemb_unittest.yml index 1010d06f..53213adc 100644 --- a/.github/workflows/quemb_unittest.yml +++ b/.github/workflows/quemb_unittest.yml @@ -112,7 +112,6 @@ jobs: 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: Test with pytest diff --git a/README.md b/README.md index 078d031a..d553cde1 100644 --- a/README.md +++ b/README.md @@ -29,31 +29,28 @@ processors. - PySCF library - Numpy - Scipy -- libDMET (required for periodic BE) -- [Wannier90](https://github.com/wannier-developers/wannier90)&& (to use Wannier functions) - -&&Wannier90 code is interfaced via [libDMET](https://github.com/gkclab/libdmet_preview) in QuEmb - -### Steps - -1. Clone the repository: - ```bash - git clone https://github.com/oimeitei/quemb.git - cd quemb - -2. Install QuEmb using one of the following approaches: - ```bash - pip install . - ``` - or simply add `path/to/quemd` to `PYTHONPATH` - ```bash - export PYTHONPATH=/path/to/quemb:$PYTHONPATH - ``` - - For conda (or virtual environment) installations, after creating your environment, specify the path to mol-be source as a path file, as in: - ```bash - echo path/to/quemb > $(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")/quemb.pth - ``` +- [libDMET](https://github.com/gkclab/libdmet_preview) (required for periodic BE) +- [Wannier90](https://github.com/wannier-developers/wannier90)## (to use Wannier functions) + +## `Wannier90` code is optional and only necessary to use Wannier functions in periodic code. + +The required dependencies, with the exception of the optional `Wannier90`, +are automatically installed by `pip`. + +### Installation + +One can just `pip install` directly from the Github repository: +```bash +pip install git+https://https://github.com/troyvvgroup/quemb +``` + +Alternatively one can manually clone and install as in: +```bash +git clone https://https://github.com/troyvvgroup/quemb +cd quemb +pip install . +``` + ## Basic Usage diff --git a/docs/source/index.rst b/docs/source/index.rst index 9222d94f..30d6edfa 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -36,3 +36,8 @@ References optimize solvers misc + + + +.. role:: bash(code) + :language: bash \ No newline at end of file diff --git a/docs/source/install.rst b/docs/source/install.rst index 2542ec68..7e8e2a35 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -4,39 +4,34 @@ Installation Prerequisites ------------- - * Python 3.6 or higher + * Python >=10 or higher * PySCF library * Numpy * Scipy - * libDMET :sup:`##` (required for periodic BE) - * `Wannier90 `_ :sup:`&&` (to use Wannier functions) + * `libDMET `__ (required for periodic BE) + * `Wannier90 `_ :sup:`##` -| :sup:`##` The modified version of `libDMET `_ available at `here `_ is recommended to run periodic BE using QuEmb. -| :sup:`&&` Wannier90 code is interfaced via `libDMET `_ in QuEmb +| :sup:`##` Wannier90 code is optional and only necessary to use Wannier functions in periodic code. +The required dependencies, with the exception of the optional :code:`Wannier90`, +are automatically installed by :bash:`pip`. -Obtain the source code ----------------------- -Clone the Github repository:: - git clone https://github.com/oimeitei/quemb.git +Installation +------------- + +One can just :bash:`pip install` directly from the Github repository -pip install ------------ +.. code-block:: bash -:: + pip install git+https://https://github.com/troyvvgroup/quemb - pip install . -Add to ``PYTHONPATH`` ---------------------- -Simply add ``path/to/quemb`` to ``PYTHONPATH`` -:: - export PYTHONPATH=/path/to/quemb:$PYTHONPATH +Alternatively one can manually clone and install as in -Conda or virtual environment ----------------------------- -For conda (or virtual environment) installations, after creating your environment, specify the path to mol-be source as a path file, as in:: +.. code-block:: bash - echo path/to/quemb > $(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")/quemb.pth + git clone https://https://github.com/troyvvgroup/quemb + cd quemb + pip install . \ No newline at end of file From 0769f9acd65eb10bde41388889a41d4d3c4fe0d5 Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Thu, 12 Dec 2024 13:16:51 -0500 Subject: [PATCH 19/27] enforce checks for `ruff check` and `pylint` pylint only checks E0401,R0401,E0611 because the actually require importing python code which `ruff` does not do --- .github/workflows/quemb_unittest.yml | 4 ++-- docs/source/install.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/quemb_unittest.yml b/.github/workflows/quemb_unittest.yml index 53213adc..bc30d1a8 100644 --- a/.github/workflows/quemb_unittest.yml +++ b/.github/workflows/quemb_unittest.yml @@ -60,7 +60,7 @@ jobs: - name: Static analysis with ruff # for the moment we want to report always report success run: | - ruff check . || true + ruff check . - name: Static analysis with pylint @@ -69,7 +69,7 @@ jobs: # TODO: if they add it to ruff as well https://github.com/astral-sh/ruff/issues/9103 # remove pylint. run: | - pylint --disable=all --enable=E0401,R0401,E0611 . || true # for the moment we want to report always report success + pylint --disable=all --enable=E0401,R0401,E0611 . # for the moment we want to report always report success - name: Static analysis with mypy diff --git a/docs/source/install.rst b/docs/source/install.rst index 7e8e2a35..50102d69 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -11,7 +11,7 @@ Prerequisites * `libDMET `__ (required for periodic BE) * `Wannier90 `_ :sup:`##` -| :sup:`##` Wannier90 code is optional and only necessary to use Wannier functions in periodic code. +| :sup:`##` :code:`Wannier90` code is optional and only necessary to use Wannier functions in periodic code. The required dependencies, with the exception of the optional :code:`Wannier90`, are automatically installed by :bash:`pip`. From 133e01c950721ea1aae2548c2dc9e0625e11a25d Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Thu, 12 Dec 2024 13:19:04 -0500 Subject: [PATCH 20/27] fixed comments in build yaml files --- .github/workflows/quemb_unittest.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/quemb_unittest.yml b/.github/workflows/quemb_unittest.yml index bc30d1a8..1e183d5a 100644 --- a/.github/workflows/quemb_unittest.yml +++ b/.github/workflows/quemb_unittest.yml @@ -58,7 +58,6 @@ jobs: - name: Static analysis with ruff - # for the moment we want to report always report success run: | ruff check . @@ -69,7 +68,7 @@ jobs: # TODO: if they add it to ruff as well https://github.com/astral-sh/ruff/issues/9103 # remove pylint. run: | - pylint --disable=all --enable=E0401,R0401,E0611 . # for the moment we want to report always report success + pylint --disable=all --enable=E0401,R0401,E0611 . - name: Static analysis with mypy From d2b9d5041e74d93f97425916d48400b6a5260c35 Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Thu, 12 Dec 2024 14:07:48 -0500 Subject: [PATCH 21/27] made mypy testing even more beautiful --- src/quemb/shared/manage_scratch.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/quemb/shared/manage_scratch.py b/src/quemb/shared/manage_scratch.py index e8db745b..dfd8313c 100644 --- a/src/quemb/shared/manage_scratch.py +++ b/src/quemb/shared/manage_scratch.py @@ -4,16 +4,16 @@ from pathlib import Path from shutil import rmtree from types import TracebackType +from typing import Annotated, Final, Literal, Optional, TypeAlias from attr import define, field -from typing_extensions import Literal, Optional, TypeAlias, Union from quemb.shared.be_var import SCRATCH -PathLike: TypeAlias = Union[str, os.PathLike] +PathLike: TypeAlias = str | os.PathLike -def _get_absolute_path(pathlike: PathLike) -> Path: +def _to_abs_path(pathlike: PathLike) -> Path: return Path(pathlike).resolve() @@ -21,9 +21,10 @@ def _get_absolute_path(pathlike: PathLike) -> Path: class WorkDir: """Manage a scratch area. - Upon initialisation of the object the `path` is created, + Upon initialisation of the object the workdir `path` is created, if it does not exist yet. If it already exists, it is ensured, that it is empty. + Internally the `path` will be stored as absolute. If `do_cleanup` is true, then the scratch area is deleted, when if `self.cleanup` is called. @@ -45,8 +46,8 @@ class WorkDir: without errors. """ - path: Path = field(converter=_get_absolute_path) - cleanup_at_end: bool = True + path: Final[Annotated[Path, "An absolute path"]] = field(converter=_to_abs_path) + cleanup_at_end: Final[bool] = True # The __init__ is automatically created # the values `self.path` and `self.cleanup_at_end` are already filled. @@ -54,7 +55,6 @@ class WorkDir: def __attrs_post_init__(self) -> None: self.path.mkdir(parents=True, exist_ok=True) if any(self.path.iterdir()): - self.cleanup_at_end = False raise ValueError("scratch_area has to be empty.") def __enter__(self) -> WorkDir: From 2f55fba47b881698e46e93b7fe35cc46e1790f03 Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Thu, 12 Dec 2024 14:32:53 -0500 Subject: [PATCH 22/27] fixed small type error in os.environ.get --- src/quemb/molbe/solver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quemb/molbe/solver.py b/src/quemb/molbe/solver.py index 19fdea54..ae2794fd 100644 --- a/src/quemb/molbe/solver.py +++ b/src/quemb/molbe/solver.py @@ -816,7 +816,7 @@ def solve_block2(mf, nocc, frag_scratch, **solver_kwargs): [max_noise, max_noise, max_noise / 10, max_noise / 100, max_noise / 100, 0.0], ) # Other DMRG parameters - mc.fcisolver.threads = int(os.environ.get("OMP_NUM_THREADS", 8)) + mc.fcisolver.threads = int(os.environ.get("OMP_NUM_THREADS", "8")) mc.fcisolver.twodot_to_onedot = int(twodot_to_onedot) mc.fcisolver.maxIter = int(max_iter) mc.fcisolver.block_extra_keyword = list(block_extra_keyword) From 03048d14a389fe86b7fd384c7683d459de6babdd Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Fri, 13 Dec 2024 10:15:54 -0500 Subject: [PATCH 23/27] fixed unsorted imports --- src/quemb/kbe/pbe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quemb/kbe/pbe.py b/src/quemb/kbe/pbe.py index 221aed53..be617cab 100644 --- a/src/quemb/kbe/pbe.py +++ b/src/quemb/kbe/pbe.py @@ -15,8 +15,8 @@ from quemb.kbe.misc import print_energy, storePBE from quemb.kbe.pfrag import Frags from quemb.molbe._opt import BEOPT -from quemb.molbe.helper import get_eri, get_scfObj, get_veff from quemb.molbe.be_parallel import be_func_parallel +from quemb.molbe.helper import get_eri, get_scfObj, get_veff from quemb.molbe.solver import be_func from quemb.shared import be_var from quemb.shared.external.optqn import ( From 7ff5b354438daef458678d16d68409e3f923417b Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Fri, 13 Dec 2024 10:20:41 -0500 Subject: [PATCH 24/27] enable ruff check and redirect stderr in pre-commit hook --- .githooks/pre-commit | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 24ddcf39..1d72c2b1 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -19,15 +19,20 @@ if [ "`git diff --check --cached | wc -c`" -gt 0 ]; then fi -if ! command -v ruff 2>&1 >/dev/null; then +if ! command -v ruff >/dev/null 2>&1; then >&2 echo "Please install ruff via 'pip install ruff'." exit 1 else - if ! ruff format --diff `git rev-parse --show-toplevel`; then + if ! ruff format --diff `git rev-parse --show-toplevel` >/dev/null 2>&1; then >&2 echo "There are problems with PEP8-compliance." >&2 echo 'You can check yourself by executing "ruff format --diff `git rev-parse --show-toplevel`"' exit 1 fi + if ! ruff check `git rev-parse --show-toplevel` >/dev/null 2>&1; then + >&2 echo "There are problems in the code." + >&2 echo 'You can check yourself by executing "ruff check `git rev-parse --show-toplevel`"' + exit 1 + fi fi From b799cceaea730da4ab358048f57ed75014b9ab7a Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Fri, 13 Dec 2024 10:33:06 -0500 Subject: [PATCH 25/27] do the mypy testing with 3.10 --- .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 1e183d5a..7788fb0d 100644 --- a/.github/workflows/quemb_unittest.yml +++ b/.github/workflows/quemb_unittest.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.13"] + python-version: ["3.10"] steps: From 5f2f57335d130e884aa12fd2a0ab87e83e27791d Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Fri, 13 Dec 2024 10:41:40 -0500 Subject: [PATCH 26/27] separated requirements clearly out --- .github/workflows/quemb_unittest.yml | 4 ++-- docs/requirements.txt | 1 + requirements.txt | 6 ------ setup.py | 1 - tests/static_analysis_requirements.txt | 7 +++++++ tests/test_requirements.txt | 3 +++ 6 files changed, 13 insertions(+), 9 deletions(-) delete mode 100644 requirements.txt create mode 100644 tests/static_analysis_requirements.txt create mode 100644 tests/test_requirements.txt diff --git a/.github/workflows/quemb_unittest.yml b/.github/workflows/quemb_unittest.yml index 7788fb0d..1c902766 100644 --- a/.github/workflows/quemb_unittest.yml +++ b/.github/workflows/quemb_unittest.yml @@ -48,7 +48,7 @@ jobs: - name: Install dependencies run: | - pip install --upgrade --upgrade-strategy eager ruff pylint mypy scipy-stubs pytest + pip install -r tests/static_analysis_requirements.txt pip install . @@ -105,7 +105,7 @@ jobs: - name: Install dependencies run: | - pip install pytest + pip install -r tests/test_requirements.txt 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 diff --git a/docs/requirements.txt b/docs/requirements.txt index 144ce731..681d165c 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,3 +1,4 @@ # the additional (!) requirements for building the doc +# the dependencies of `quemb` itself are given in the setup.py sphinx_rtd_theme sphinx_autodoc_typehints diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 49fd1fa5..00000000 --- a/requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -pyscf==2.6.2 -pytest==8.3.2 -libdmet @ git+https://github.com/gkclab/libdmet_preview.git -matplotlib -attrs -typing_extensions diff --git a/setup.py b/setup.py index ed548467..6f8e8ffa 100644 --- a/setup.py +++ b/setup.py @@ -25,6 +25,5 @@ "matplotlib", "libdmet @ git+https://github.com/gkclab/libdmet_preview.git", "attrs", - "typing_extensions", ], ) diff --git a/tests/static_analysis_requirements.txt b/tests/static_analysis_requirements.txt new file mode 100644 index 00000000..e62e20cb --- /dev/null +++ b/tests/static_analysis_requirements.txt @@ -0,0 +1,7 @@ +# the additional (!) requirements for performing static analysis of the code +# the dependencies of `quemb` itself are given in the setup.py +ruff +pylint +mypy +scipy-stubs +pytest \ No newline at end of file diff --git a/tests/test_requirements.txt b/tests/test_requirements.txt new file mode 100644 index 00000000..2562dc10 --- /dev/null +++ b/tests/test_requirements.txt @@ -0,0 +1,3 @@ +# the additional (!) requirements for testing the code +# the dependencies of `quemb` itself are given in the setup.py +pytest \ No newline at end of file From 6140dbe13c6934f4e1a1d0ce6555f1562e5752c7 Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Fri, 13 Dec 2024 12:30:12 -0500 Subject: [PATCH 27/27] deleted superfluos return --- src/quemb/kbe/pfrag.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/quemb/kbe/pfrag.py b/src/quemb/kbe/pfrag.py index 381e4dcc..ca5f9d90 100644 --- a/src/quemb/kbe/pfrag.py +++ b/src/quemb/kbe/pfrag.py @@ -369,7 +369,6 @@ def update_heff( if only_chem: self.heff = heff_ - return else: for idx, i in enumerate(self.edge_idx): for j in range(len(i)):