From ec57c4dceb9578dd8c5a566dc3906ed77a551747 Mon Sep 17 00:00:00 2001 From: SaltyChiang Date: Wed, 6 Nov 2024 20:02:42 +0800 Subject: [PATCH] Fix compatibility with Cython<3. --- pyquda_core/pyproject.toml | 2 +- pyquda_core/pyquda/_version.py | 2 +- pyquda_core/pyquda/dirac/gauge.py | 16 +++++++++++----- pyquda_core/pyquda/dirac/hisq.py | 8 ++++---- pyquda_core/pyquda/dirac/staggered.py | 8 ++++---- pyquda_core/pyquda/src/pyquda.in.pyx | 19 ++++++++++--------- 6 files changed, 31 insertions(+), 24 deletions(-) diff --git a/pyquda_core/pyproject.toml b/pyquda_core/pyproject.toml index 1bea43f..a4bcf68 100644 --- a/pyquda_core/pyproject.toml +++ b/pyquda_core/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools", "wheel", "Cython>=3", "numpy"] +requires = ["setuptools", "wheel", "Cython", "numpy"] [tool.setuptools.packages.find] include = ["pyquda*"] diff --git a/pyquda_core/pyquda/_version.py b/pyquda_core/pyquda/_version.py index c598173..e94731c 100644 --- a/pyquda_core/pyquda/_version.py +++ b/pyquda_core/pyquda/_version.py @@ -1 +1 @@ -__version__ = "0.9.3" +__version__ = "0.9.4" diff --git a/pyquda_core/pyquda/dirac/gauge.py b/pyquda_core/pyquda/dirac/gauge.py index 9f49953..fd939f0 100644 --- a/pyquda_core/pyquda/dirac/gauge.py +++ b/pyquda_core/pyquda/dirac/gauge.py @@ -38,6 +38,7 @@ QudaGaugeSmearType, QudaLinkType, QudaMassNormalization, + QudaPrecision, QudaReconstructType, QudaSolveType, ) @@ -53,13 +54,18 @@ def __init__(self, latt_info: Union[LatticeInfo, LaplaceLatticeInfo]) -> None: self.newQudaInvertParam() self.newQudaGaugeSmearParam() self.newQudaGaugeObservableParam() - self.setPrecision() + self.setPrecision( + cuda=QudaPrecision.QUDA_DOUBLE_PRECISION, + sloppy=QudaPrecision.QUDA_DOUBLE_PRECISION, + precondition=QudaPrecision.QUDA_DOUBLE_PRECISION, + eigensolver=QudaPrecision.QUDA_DOUBLE_PRECISION, + ) # Use QUDA_RECONSTRUCT_NO to ensure slight deviations from SU(3) can be preserved self.setReconstruct( - cuda=max(self.reconstruct.cuda, QudaReconstructType.QUDA_RECONSTRUCT_NO), - sloppy=max(self.reconstruct.sloppy, QudaReconstructType.QUDA_RECONSTRUCT_NO), - precondition=max(self.reconstruct.precondition, QudaReconstructType.QUDA_RECONSTRUCT_NO), - eigensolver=max(self.reconstruct.eigensolver, QudaReconstructType.QUDA_RECONSTRUCT_NO), + cuda=QudaReconstructType.QUDA_RECONSTRUCT_NO, + sloppy=QudaReconstructType.QUDA_RECONSTRUCT_NO, + precondition=QudaReconstructType.QUDA_RECONSTRUCT_NO, + eigensolver=QudaReconstructType.QUDA_RECONSTRUCT_NO, ) def newQudaGaugeParam(self): diff --git a/pyquda_core/pyquda/dirac/hisq.py b/pyquda_core/pyquda/dirac/hisq.py index cee346d..dcf54f6 100644 --- a/pyquda_core/pyquda/dirac/hisq.py +++ b/pyquda_core/pyquda/dirac/hisq.py @@ -30,10 +30,10 @@ def __init__( else: self.setPrecision() self.setReconstruct( - cuda=max(self.reconstruct.cuda, QudaReconstructType.QUDA_RECONSTRUCT_NO), - sloppy=max(self.reconstruct.sloppy, QudaReconstructType.QUDA_RECONSTRUCT_NO), - precondition=max(self.reconstruct.precondition, QudaReconstructType.QUDA_RECONSTRUCT_NO), - eigensolver=max(self.reconstruct.eigensolver, QudaReconstructType.QUDA_RECONSTRUCT_NO), + cuda=QudaReconstructType.QUDA_RECONSTRUCT_NO, + sloppy=QudaReconstructType.QUDA_RECONSTRUCT_NO, + precondition=QudaReconstructType.QUDA_RECONSTRUCT_NO, + eigensolver=QudaReconstructType.QUDA_RECONSTRUCT_NO, ) def newPathCoeff(self): diff --git a/pyquda_core/pyquda/dirac/staggered.py b/pyquda_core/pyquda/dirac/staggered.py index b66e844..fd600ce 100644 --- a/pyquda_core/pyquda/dirac/staggered.py +++ b/pyquda_core/pyquda/dirac/staggered.py @@ -28,10 +28,10 @@ def __init__( else: self.setPrecision() self.setReconstruct( - cuda=max(self.reconstruct.cuda, QudaReconstructType.QUDA_RECONSTRUCT_NO), - sloppy=max(self.reconstruct.sloppy, QudaReconstructType.QUDA_RECONSTRUCT_NO), - precondition=max(self.reconstruct.precondition, QudaReconstructType.QUDA_RECONSTRUCT_NO), - eigensolver=max(self.reconstruct.eigensolver, QudaReconstructType.QUDA_RECONSTRUCT_NO), + cuda=QudaReconstructType.QUDA_RECONSTRUCT_NO, + sloppy=QudaReconstructType.QUDA_RECONSTRUCT_NO, + precondition=QudaReconstructType.QUDA_RECONSTRUCT_NO, + eigensolver=QudaReconstructType.QUDA_RECONSTRUCT_NO, ) def newQudaGaugeParam(self, tadpole_coeff: float): diff --git a/pyquda_core/pyquda/src/pyquda.in.pyx b/pyquda_core/pyquda/src/pyquda.in.pyx index 899df3e..ba28118 100755 --- a/pyquda_core/pyquda/src/pyquda.in.pyx +++ b/pyquda_core/pyquda/src/pyquda.in.pyx @@ -41,7 +41,8 @@ cdef class _NDArray: cdef void **ptrs cdef void ***ptrss - def __cinit__(self, ndarray data): + def __cinit__(self, data): + shape = data.shape ndim = data.ndim cdef size_t ptr_uint64 if ndim == 1: @@ -50,18 +51,18 @@ cdef class _NDArray: ptr_uint64 = data.ctypes.data self.ptr = ptr_uint64 elif ndim == 2: - self.n0, self.n1 = data.shape[0], 0 - self.ptrs = malloc(self.n0 * sizeof(void *)) - for i in range(self.n0): + self.n0, self.n1 = shape[0], 0 + self.ptrs = malloc(shape[0] * sizeof(void *)) + for i in range(shape[0]): assert data[i].flags["C_CONTIGUOUS"] ptr_uint64 = data[i].ctypes.data self.ptrs[i] = ptr_uint64 elif ndim == 3: - self.n0, self.n1 = data.shape[0], data.shape[1] - self.ptrss = malloc(self.n0 * sizeof(void **)) - for i in range(self.n0): - self.ptrss[i] = malloc(self.n1 * sizeof(void *)) - for j in range(self.n1): + self.n0, self.n1 = shape[0], shape[1] + self.ptrss = malloc(shape[0] * sizeof(void **)) + for i in range(shape[0]): + self.ptrss[i] = malloc(shape[1] * sizeof(void *)) + for j in range(shape[1]): assert data[i, j].flags["C_CONTIGUOUS"] ptr_uint64 = data[i, j].ctypes.data self.ptrss[i][j] = ptr_uint64