From 26bb49a1c77f9057bef47534c6e0463c226fa846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Sat, 20 Jul 2024 16:10:46 +0200 Subject: [PATCH 1/4] BLD: remove upper bound for Cython (drop deprecated DEF statements) --- .github/workflows/wheels.yaml | 2 +- pyproject.toml | 5 +---- yt/utilities/lib/geometry_utils.pxd | 17 +++++++++++------ yt/utilities/lib/geometry_utils.pyx | 6 ------ yt/utilities/lib/image_samplers.pxd | 3 ++- yt/utilities/lib/image_samplers.pyx | 2 -- 6 files changed, 15 insertions(+), 20 deletions(-) diff --git a/.github/workflows/wheels.yaml b/.github/workflows/wheels.yaml index a304652701b..2b08e7f49a1 100644 --- a/.github/workflows/wheels.yaml +++ b/.github/workflows/wheels.yaml @@ -92,7 +92,7 @@ jobs: # keep in sync with pyproject.toml run: | - python -m pip install "Cython>=3.0.3, <3.1" + python -m pip install Cython>=3.0.3 python -m pip install numpy>=1.25 python -m pip install ewah-bool-utils>=1.0.2 python -m pip install --upgrade wheel diff --git a/pyproject.toml b/pyproject.toml index 8a562a27a7d..cd1c05277bb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,10 +2,7 @@ # keep in sync with .github/workflows/wheels.yaml requires = [ "setuptools>=61.2", - - # for the upper pin in Cython - # see https://github.com/yt-project/yt/issues/4044 - "Cython>=3.0.3, <3.1", + "Cython>=3.0.3", "numpy>=2.0.0", "ewah-bool-utils>=1.2.0", ] diff --git a/yt/utilities/lib/geometry_utils.pxd b/yt/utilities/lib/geometry_utils.pxd index 3165bb43149..0b8145a3ba0 100644 --- a/yt/utilities/lib/geometry_utils.pxd +++ b/yt/utilities/lib/geometry_utils.pxd @@ -11,12 +11,17 @@ cimport numpy as np from libc.float cimport DBL_MANT_DIG from libc.math cimport frexp, ldexp, sqrt -DEF ORDER_MAX=20 -DEF INDEX_MAX_64=2097151 -# TODO: Handle error for indices past max -DEF XSHIFT=2 -DEF YSHIFT=1 -DEF ZSHIFT=0 +cdef enum: + ORDER_MAX=20 + +cdef enum: + # TODO: Handle error for indices past max + INDEX_MAX_64=2097151 + +cdef enum: + XSHIFT=2 + YSHIFT=1 + ZSHIFT=0 @cython.cdivision(True) @cython.boundscheck(False) diff --git a/yt/utilities/lib/geometry_utils.pyx b/yt/utilities/lib/geometry_utils.pyx index e6eed9af3a2..ad63adf60e2 100644 --- a/yt/utilities/lib/geometry_utils.pyx +++ b/yt/utilities/lib/geometry_utils.pyx @@ -23,12 +23,6 @@ from yt.utilities.exceptions import YTDomainOverflow from yt.utilities.lib.vec3_ops cimport L2_norm, cross, dot, subtract -DEF ORDER_MAX=20 -DEF INDEX_MAX_64=2097151 -DEF XSHIFT=2 -DEF YSHIFT=1 -DEF ZSHIFT=0 - cdef extern from "math.h": double exp(double x) noexcept nogil float expf(float x) noexcept nogil diff --git a/yt/utilities/lib/image_samplers.pxd b/yt/utilities/lib/image_samplers.pxd index 9027a902e4f..725ca8a01c6 100644 --- a/yt/utilities/lib/image_samplers.pxd +++ b/yt/utilities/lib/image_samplers.pxd @@ -15,7 +15,8 @@ cimport numpy as np from .partitioned_grid cimport PartitionedGrid from .volume_container cimport VolumeContainer -DEF Nch = 4 +cdef enum: + Nch = 4 # NOTE: We don't want to import the field_interpolator_tables here, as it # breaks a bunch of C++ interop. Maybe some day it won't. So, we just forward diff --git a/yt/utilities/lib/image_samplers.pyx b/yt/utilities/lib/image_samplers.pyx index 0ae116e3777..39a247ff63e 100644 --- a/yt/utilities/lib/image_samplers.pyx +++ b/yt/utilities/lib/image_samplers.pyx @@ -37,8 +37,6 @@ from ._octree_raytracing cimport RayInfo, _OctreeRayTracing cdef extern from "platform_dep.h": long int lrint(double x) noexcept nogil -DEF Nch = 4 - from cython.parallel import parallel, prange from cpython.exc cimport PyErr_CheckSignals From 3d022c141126dccc3db86af2b4872c4f56c17607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Sat, 20 Jul 2024 16:47:46 +0200 Subject: [PATCH 2/4] BLD: sync up pyproject.toml and wheels.yaml --- .github/workflows/wheels.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/wheels.yaml b/.github/workflows/wheels.yaml index 2b08e7f49a1..22978a00639 100644 --- a/.github/workflows/wheels.yaml +++ b/.github/workflows/wheels.yaml @@ -93,9 +93,8 @@ jobs: # keep in sync with pyproject.toml run: | python -m pip install Cython>=3.0.3 - python -m pip install numpy>=1.25 - python -m pip install ewah-bool-utils>=1.0.2 - python -m pip install --upgrade wheel + python -m pip install numpy>=2.0.0 + python -m pip install ewah-bool-utils>=1.2.0 python -m pip install --upgrade setuptools - name: build yt shell: bash From b541a572d6379024d1338075254ecaf34a4660fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Fri, 26 Jul 2024 12:07:14 +0200 Subject: [PATCH 3/4] TST: test against Cython 3.1 dev --- .github/workflows/bleeding-edge.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bleeding-edge.yaml b/.github/workflows/bleeding-edge.yaml index 3567465440c..dca8c5387f1 100644 --- a/.github/workflows/bleeding-edge.yaml +++ b/.github/workflows/bleeding-edge.yaml @@ -50,9 +50,9 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install --upgrade setuptools wheel - python -m pip install --pre --only-binary ":all:" numpy matplotlib \ + python -m pip install --pre --only-binary ":all:" numpy matplotlib Cython \ --extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple - python -m pip install --pre ewah-bool-utils Cython + python -m pip install --pre ewah-bool-utils python -m pip install git+https://github.com/yt-project/unyt.git python -m pip install --pre pytest PyYAML From 8a4003fed8ba5599da83a0d38ae2b3e103863b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Fri, 26 Jul 2024 12:09:44 +0200 Subject: [PATCH 4/4] BLD: fix compilation against Cython 3.1 --- yt/geometry/particle_deposit.pxd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yt/geometry/particle_deposit.pxd b/yt/geometry/particle_deposit.pxd index e89fdd9260a..8f16f9af6ef 100644 --- a/yt/geometry/particle_deposit.pxd +++ b/yt/geometry/particle_deposit.pxd @@ -14,12 +14,13 @@ import numpy as np cimport cython from libc.math cimport sqrt from libc.stdlib cimport free, malloc -from numpy.math cimport PI as NPY_PI from yt.utilities.lib.fp_utils cimport * from .oct_container cimport Oct, OctreeContainer +cdef extern from "numpy/npy_math.h": + double NPY_PI cdef extern from "platform_dep.h": void *alloca(int)