Skip to content

Commit 54c76e2

Browse files
authored
Merge pull request #119 from lcmd-epfl/c2m-depfix
Update requirements and pyproject: - update cell2mol version - fix setup.py when no access to gitdir - replace vulnerable dependencies - add `[dev]` option - unsure compatibility with declared numpy and pyscf versions - adapt new functions for python 3.9 Manual checks: - python 3.11 works - python 3.9 works thanks to the hacks (without cell2mol) Todo: - drop python 3.9 after the Marvel event in January
2 parents 6ede655 + 4072f82 commit 54c76e2

12 files changed

Lines changed: 65 additions & 40 deletions

File tree

pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ classifiers = [
3737
# note: maximal versions are just the latest versions to exist when compatibility checks were made, later versions may also work
3838
requires-python = ">=3.9"
3939
dependencies = [
40-
'numpy >= 1.22.3, < 2.4',
40+
'numpy >= 1.26.1, < 2.4',
4141
'scipy >= 1.1.0, < 1.17',
4242
'tqdm >= 4.66',
4343
]
4444

4545
[project.optional-dependencies]
46-
pyscf = ['pyscf >= 2.0.1, < 2.12']
46+
pyscf = ['pyscf >= 2.1.0, < 2.12']
4747
qml = ['ase >= 3.22, < 3.27']
4848
regression = ["scikit-learn >= 0.24.2, < 1.8"]
4949
wigner = ["sympy >= 1.5, < 1.15"]
@@ -52,8 +52,10 @@ cell2mol = ["qstack[pyscf,cell2mol-itself]"]
5252
equio-itself = ["metatensor-core >= 0.1.8, == 0.1.*"]
5353
equio = ["qstack[pyscf,equio-itself]"]
5454
spahm = ["qstack[pyscf]"]
55+
all = ["qstack[pyscf,qml,regression,wigner,equio,gmol,cell2mol]"]
5556
docs-build = ["sphinx", "sphinx-argparse", "sphinx-autobuild", "myst-parser", "furo"]
56-
all = ["qstack[pyscf,qml,regression,wigner,equio,gmol]"]
57+
lint = ["ruff"]
58+
dev = ["qstack[all,docs-build,lint]"]
5759

5860
[project.urls]
5961
Repository = "https://github.com/lcmd-epfl/Q-stack.git"

qstack/__init__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
"""Q-stack."""
22

3+
import sys
4+
import warnings
5+
import builtins
36
from qstack import tools
4-
#from qstack import compound # needs pyscf
57
from qstack import constants
68
from qstack import mathutils
7-
#from qstack import fields # needs scipy, pyscf
8-
#from qstack import basis_opt # needs pyscf, scipy
9-
#from qstack import spahm # requires pyscf
10-
#from qstack import orcaio # requires pyscf
11-
#from qstack import qml # requires ase
12-
#from qstack import regression # requires sklearn (scikit-learn as pip calls it)
9+
10+
11+
if sys.version_info[1]<10:
12+
warnings.warn('Redefining built-in function zip for compatibility', stacklevel=1)
13+
_zip = builtins.zip
14+
def zip_override(*iterables, strict=False):
15+
"""Override built-in zip for python<3.10 to ignore `strict` argument."""
16+
return _zip(*iterables)
17+
builtins.zip = zip_override

qstack/fields/decomposition.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import numpy as np
44
import scipy
5-
from pyscf import scf
5+
from pyscf import scf, gto
66
from qstack import compound
77
from . import moments
88

@@ -59,10 +59,10 @@ def get_self_repulsion(mol_or_mf, dm):
5959
Returns:
6060
float: Self-repulsion energy (a.u).
6161
"""
62-
try:
63-
j, _k = mol_or_mf.get_jk()
64-
except AttributeError:
62+
if isinstance(mol_or_mf, gto.mole.Mole):
6563
j, _k = scf.hf.get_jk(mol_or_mf, dm)
64+
else:
65+
j, _k = mol_or_mf.get_jk()
6666
return np.einsum('ij,ij', j, dm)
6767

6868

qstack/regression/local_kernels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
import ctypes
1212
import sysconfig
1313
import warnings
14-
import itertools
1514
import numpy as np
1615
import sklearn.metrics.pairwise as _SKLEARN_PAIRWISE
1716
from qstack.regression import __path__ as REGMODULE_PATH
17+
from qstack.tools import pairwise
1818

1919

2020
RAM_BATCHING_SIZE = 1024**3 * 5 # 5GiB
@@ -66,7 +66,7 @@ def compute_distance_matrix(R1, R2):
6666
else:
6767
dists = np.zeros((batch_size, *R2.shape), dtype=dtype)
6868
batch_limits = np.minimum(np.arange(0, R1.shape[0]+batch_size, step=batch_size), R1.shape[0])
69-
for batch_start, batch_end in itertools.pairwise(batch_limits):
69+
for batch_start, batch_end in pairwise(batch_limits):
7070
dists_view = dists[:batch_end-batch_start]
7171
R1_view = R1[batch_start:batch_end, None, ...]
7272
np.subtract(R1_view, R2[None,:], out=dists_view)

qstack/reorder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _orca2gpr_idx(l_slices, m):
5151
idx[s] = np.concatenate((idx[s][::-2], idx[s][1::2]))
5252
signs = np.ones_like(idx)
5353
signs[np.where(np.abs(m)>=3)] = -1 # in pyscf order
54-
signs[idx] = signs # in orca order
54+
signs[idx] = np.copy(signs) # in orca order. copy for numpy < 2
5555
return idx, signs
5656

5757

qstack/spahm/rho/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def chsp_converter(chsp):
5252
if fname is None:
5353
return np.full(n, None, dtype=object)
5454
if os.path.isfile(fname):
55-
chsp = np.loadtxt(fname, dtype=object, converters=chsp_converter, encoding=None)
56-
if len(chsp)!=n:
55+
chsp = np.loadtxt(fname, dtype=object, converters={0: chsp_converter}, encoding=None)
56+
if chsp.shape != (n,):
5757
raise RuntimeError(f'Wrong length of the file {fname}')
5858
else:
5959
raise RuntimeError(f"{fname} can not be found")

qstack/tools.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,25 @@
44
"""
55

66
import os
7+
import sys
78
import time
89
import resource
910
import argparse
10-
import itertools
1111
import numpy as np
12+
from itertools import accumulate
13+
if sys.version_info[1]>=10:
14+
from itertools import pairwise
15+
else:
16+
def pairwise(iterable):
17+
"""Implement itertools.pairwise for python<3.10.
18+
19+
Taken from https://docs.python.org/3/library/itertools.html#itertools.pairwise
20+
"""
21+
iterator = iter(iterable)
22+
a = next(iterator, None)
23+
for b in iterator:
24+
yield a, b
25+
a = b
1226

1327

1428
def unix_time_decorator(func):
@@ -115,8 +129,8 @@ def slice_generator(iterable, inc=lambda x: x, i0=0):
115129
tuple: (element, slice) pairs for each element in the iterable.
116130
"""
117131
func = func=lambda total, elem: total+inc(elem)
118-
starts = itertools.accumulate(iterable, func=func, initial=i0)
119-
starts_ends = itertools.pairwise(starts)
132+
starts = accumulate(iterable, func=func, initial=i0)
133+
starts_ends = pairwise(starts)
120134
for elem, (start, end) in zip(iterable, starts_ends, strict=True):
121135
yield elem, np.s_[start:end]
122136

requirements.py3.11.txt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
attrs==21.4.0
2-
certifi==2021.10.8
32
h5py==3.11.0
43
iniconfig==1.1.1
5-
packaging==21.3
4+
packaging==25.0
65
pluggy==1.0.0
76
py==1.11.0
8-
pyparsing==3.0.6
7+
pyparsing==3.2.5
98
pyscf==2.5.0
109
pytest==6.2.5
1110
numpy==2.3.*
12-
scipy==1.10
11+
scipy==1.16.3
1312
toml==0.10.2
14-
scikit-learn==1.5.0
15-
ase==3.22
16-
tqdm==4.66
17-
metatensor-core==0.1.8
18-
cell2mol @ git+https://github.com/lcmd-epfl/cell2mol.git@22473bbf12a013467137a55a63c88fbbdc95baa2
13+
scikit-learn==1.7.2
14+
ase==3.26
15+
tqdm==4.67
16+
metatensor-core==0.1.17
17+
cell2mol @ git+https://github.com/lcmd-epfl/cell2mol.git@40b3237

requirements.py3.13.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pyparsing==3.2.5
66
pyscf==2.11.0
77
pytest==8.4.2
88
numpy==2.3.*
9-
scipy==1.16.2
9+
scipy==1.16.3
1010
scikit-learn==1.7.2
1111
ase==3.26
1212
tqdm==4.67

requirements.py3.9.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
attrs==21.4.0
2-
certifi==2021.10.8
32
h5py==3.6.0
43
iniconfig==1.1.1
54
packaging==21.3
65
pluggy==1.0.0
76
py==1.11.0
87
pyparsing==3.0.6
9-
pyscf==2.0.1
8+
pyscf>=2.1
109
pytest==6.2.5
11-
numpy===1.22.3
10+
numpy>=1.26.1
1211
scipy==1.10
1312
toml==0.10.2
14-
scikit-learn==0.24.2
13+
scikit-learn==1.6.1
1514
ase==3.22
16-
tqdm==4.66
15+
tqdm==4.67
1716
metatensor-core==0.1.8
18-
cell2mol @ git+https://github.com/lcmd-epfl/cell2mol.git@22473bbf12a013467137a55a63c88fbbdc95baa2

0 commit comments

Comments
 (0)