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

Ensuring NumPy 2.0 compatibility #225

Merged
merged 9 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
- id: check-yaml

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.13.2
hooks:
- id: isort

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies = [
"pybtex>=0.24",
"spglib>=1.9",
"upf-to-json>=0.9.5",
"ase-koopmans==0.1.4",
"ase-koopmans==0.1.5",
"scikit-learn>=1.0",
"deepdiff>=5.8.1",
]
Expand Down
4 changes: 2 additions & 2 deletions src/koopmans/calculators/_koopmans_cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def good_fft(nr: int) -> int:
return nr


def read_ham_file(filename: Path) -> np.ndarray[Any, np.dtype[np.cfloat]]:
def read_ham_file(filename: Path) -> np.ndarray[Any, np.dtype[np.complex128]]:
# Read a single hamiltonian XML file
if not filename.exists():
raise FileExistsError(f'{filename} does not exist')
Expand All @@ -77,7 +77,7 @@ def read_ham_file(filename: Path) -> np.ndarray[Any, np.dtype[np.cfloat]]:
assert ham_xml.text is not None, f'{filename} is empty'

ham_array = np.array([complex(*[float(x) for x in line.split(',')])
for line in ham_xml.text.strip().split('\n')], dtype=np.cfloat) * utils.units.Hartree
for line in ham_xml.text.strip().split('\n')], dtype=np.complex128) * utils.units.Hartree

return ham_array.reshape((length, length))

Expand Down
14 changes: 7 additions & 7 deletions src/koopmans/calculators/_ui/_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ def __init__(self, atoms: Atoms, *args, **kwargs):
self.atoms.calc = self

# Intermediate variables
self.centers: NDArray[np.float_] = np.array([])
self.centers: NDArray[np.float64] = np.array([])
self.spreads: List[float] = []
self.phases: List[complex] = []
self.hr: NDArray[np.complex_] = np.array([])
self.hr_coarse: NDArray[np.complex_] = np.array([])
self.hr_smooth: NDArray[np.complex_] = np.array([])
self.hk: NDArray[np.complex_] = np.array([])
self.hr: NDArray[np.complex128] = np.array([])
self.hr_coarse: NDArray[np.complex128] = np.array([])
self.hr_smooth: NDArray[np.complex128] = np.array([])
self.hk: NDArray[np.complex128] = np.array([])
self.Rvec: NDArray[np.int_] = np.array([])
self.Rsmooth: NDArray[np.int_] = np.array([])
self.wRs: List[int] = []
Expand Down Expand Up @@ -308,7 +308,7 @@ def parse_phases(self) -> None:
self.phases = []
return

def print_centers(self, centers: NDArray[np.float_] = np.array([])) -> None:
def print_centers(self, centers: NDArray[np.float64] = np.array([])) -> None:
"""
print_centers simply prints out the centers in the following Xcrysden-readable format:

Expand Down Expand Up @@ -649,7 +649,7 @@ def calc_dos(self) -> None:

return

def correct_phase(self) -> NDArray[np.complex_]:
def correct_phase(self) -> NDArray[np.complex128]:
"""
correct_phase calculate the correct phase factor to put in the Fourier transform
to get the interpolated k-space hamiltonian. The correction consists
Expand Down
5 changes: 3 additions & 2 deletions src/koopmans/calculators/_ui/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from numpy.typing import ArrayLike, NDArray


def crys_to_cart(vec: NDArray[np.float_], trmat: NDArray[np.float_], typ: int) -> NDArray[np.float_]:
def crys_to_cart(vec: NDArray[np.float64], trmat: NDArray[np.float64], typ: int) -> NDArray[np.float64]:
"""
Function to transform the numpy array vec (or a list/array of numpy arrays) from
crystal to cartesian (in alat units), or viceversa, as it is done in QE: typ=+1
Expand All @@ -33,7 +33,8 @@ def crys_to_cart(vec: NDArray[np.float_], trmat: NDArray[np.float_], typ: int) -
return vec_tr


def extract_hr(hr: NDArray[np.complex_], rvect: NDArray[np.int_], nr1: int, nr2: int, nr3: int) -> NDArray[np.complex_]:
def extract_hr(hr: NDArray[np.complex128], rvect: NDArray[np.int_],
nr1: int, nr2: int, nr3: int) -> NDArray[np.complex128]:
"""
Function to select the Wannier Hamiltonian only on the primitive cell R-vectors.
The Hamiltonian coming from a Wannier90 calculation with k-points is indeed
Expand Down
2 changes: 1 addition & 1 deletion src/koopmans/calculators/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class ReturnsBandStructure(ABC):
"""

@abstractmethod
def eigenvalues_from_results(self) -> npt.NDArray[np.float_]:
def eigenvalues_from_results(self) -> npt.NDArray[np.float64]:
...

@abstractmethod
Expand Down
4 changes: 2 additions & 2 deletions src/koopmans/utils/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def read_wannier_hr_file(fname: Path) -> Tuple[np.ndarray, np.ndarray, List[int]
return hr_np, rvect_np, weights, nrpts


def read_wannier_u_file(fname: Path) -> Tuple[npt.NDArray[np.complex_], npt.NDArray[np.float_], int]:
def read_wannier_u_file(fname: Path) -> Tuple[npt.NDArray[np.complex128], npt.NDArray[np.float64], int]:

with open(fname, 'r') as fd:
lines = fd.readlines()
Expand All @@ -286,7 +286,7 @@ def read_wannier_u_file(fname: Path) -> Tuple[npt.NDArray[np.complex_], npt.NDAr
return umat, kpts, nk


def write_wannier_u_file(fname: Path, umat: npt.NDArray[np.complex_], kpts: npt.NDArray[np.float_]):
def write_wannier_u_file(fname: Path, umat: npt.NDArray[np.complex128], kpts: npt.NDArray[np.float64]):

flines = [f' Written on {datetime.now().isoformat(timespec="seconds")}']
flines.append(''.join([f'{x:12d}' for x in umat.shape]))
Expand Down
Loading