From 62a046c99a445b63189b50f2d181dc97c0030ef6 Mon Sep 17 00:00:00 2001 From: Alexander Condello Date: Thu, 26 Oct 2023 08:21:19 -0700 Subject: [PATCH 1/2] Build C++ extensions with Cython3 --- dwave/samplers/greedy/descent.pyx | 2 +- dwave/samplers/sa/simulated_annealing.pyx | 2 +- dwave/samplers/tree/sample.pyx | 2 ++ dwave/samplers/tree/solve.pyx | 2 ++ pyproject.toml | 2 +- releasenotes/notes/cython3-36beac915dba0ea1.yaml | 3 +++ requirements.txt | 2 +- 7 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/cython3-36beac915dba0ea1.yaml diff --git a/dwave/samplers/greedy/descent.pyx b/dwave/samplers/greedy/descent.pyx index b7b6b2d..147133a 100644 --- a/dwave/samplers/greedy/descent.pyx +++ b/dwave/samplers/greedy/descent.pyx @@ -23,7 +23,7 @@ from libcpp.vector cimport vector import numpy as np cimport numpy as np -cimport decl +cimport dwave.samplers.greedy.decl as decl def steepest_gradient_descent(num_samples, diff --git a/dwave/samplers/sa/simulated_annealing.pyx b/dwave/samplers/sa/simulated_annealing.pyx index 992d695..27b75e4 100644 --- a/dwave/samplers/sa/simulated_annealing.pyx +++ b/dwave/samplers/sa/simulated_annealing.pyx @@ -194,7 +194,7 @@ def simulated_annealing(num_samples, h, coupler_starts, coupler_ends, return states_numpy[:num], energies_numpy[:num] -cdef bool interrupt_callback(void * const interrupt_function) with gil: +cdef bool interrupt_callback(void * const interrupt_function) noexcept with gil: try: return (interrupt_function)() except Exception: diff --git a/dwave/samplers/tree/sample.pyx b/dwave/samplers/tree/sample.pyx index 3078d8d..5a77fbc 100644 --- a/dwave/samplers/tree/sample.pyx +++ b/dwave/samplers/tree/sample.pyx @@ -25,6 +25,7 @@ import numpy as np import dimod from dimod.binary.binary_quadratic_model import BinaryQuadraticModel +cimport cython cimport numpy as np from cython.operator cimport dereference as deref from dimod cimport cyBQM_float64 @@ -47,6 +48,7 @@ cdef extern from "src/include/sample.hpp": double** pair_mrg_data, int* pair_mrg_rows, int* pair_mrg_cols, int** pair_data, int* pair_rows, int* pair_cols) except + +@cython.annotation_typing(False) # maintain Cython2 behavior def sample_bqm_wrapper(bqm: BinaryQuadraticModel, beta: float, max_complexity: float, diff --git a/dwave/samplers/tree/solve.pyx b/dwave/samplers/tree/solve.pyx index 2a37168..10aa8a9 100644 --- a/dwave/samplers/tree/solve.pyx +++ b/dwave/samplers/tree/solve.pyx @@ -19,6 +19,7 @@ import dimod import numpy as np +cimport cython cimport numpy as np from cython.operator cimport dereference as deref from dimod cimport cyBQM_float64 @@ -40,6 +41,7 @@ cdef extern from "src/include/solve.hpp": samples_dtype = np.intc # needs to be consistent with samples_type energies_dtype = np.double # needs to be consistent with energies_type +@cython.annotation_typing(False) # maintain Cython2 behavior def solve_bqm_wrapper(bqm: BinaryQuadraticModel, order: list, max_complexity: int, diff --git a/pyproject.toml b/pyproject.toml index f781da1..691232b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ requires = [ "setuptools>=46.4.0", # PEP-420 support, PEP-517/518 support, setup.cfg attr: support "wheel>=0.30.0", # limited python api support - "cython>=0.29.24,<3.0", + "cython~=3.0", 'dimod==0.12.0', 'numpy==1.19.0;python_version<"3.9"', # C API for numpy.random 'oldest-supported-numpy;python_version>="3.9"', diff --git a/releasenotes/notes/cython3-36beac915dba0ea1.yaml b/releasenotes/notes/cython3-36beac915dba0ea1.yaml new file mode 100644 index 0000000..c86e0d0 --- /dev/null +++ b/releasenotes/notes/cython3-36beac915dba0ea1.yaml @@ -0,0 +1,3 @@ +--- +features: + - Build C++ extensions with Cython 3. diff --git a/requirements.txt b/requirements.txt index a98b510..5c5794e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -cython==0.29.28 +cython==3.0.4 dimod==0.12.1 numpy==1.19.0;python_version<"3.9" # C API for numpy.random oldest-supported-numpy;python_version>="3.9" From ebe0d35c03e93c518e6a9046bf70ac470cd9deba Mon Sep 17 00:00:00 2001 From: Alexander Condello Date: Thu, 26 Oct 2023 08:29:40 -0700 Subject: [PATCH 2/2] Build wheels for Python 3.12 and drop 3.7 --- .circleci/config.yml | 16 +++++++--------- pyproject.toml | 2 +- .../notes/python3.12-1e39dd7f62fb5dbe.yaml | 5 +++++ requirements.txt | 2 +- setup.cfg | 6 +++--- 5 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 releasenotes/notes/python3.12-1e39dd7f62fb5dbe.yaml diff --git a/.circleci/config.yml b/.circleci/config.yml index 42f2719..9719ae9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,14 +1,14 @@ version: 2.1 orbs: - win: circleci/windows@2.2.0 + win: circleci/windows@5.0.0 commands: run-cibuildwheel: parameters: cibw-version: type: string - default: 2.11.2 + default: 2.16.2 steps: - run: name: run cibuildwheel @@ -174,7 +174,7 @@ jobs: test-doctest: docker: - - image: circleci/python:3.7 # as of march 2019 RTD uses 3.7 + - image: circleci/python:3.9 steps: - checkout @@ -292,22 +292,17 @@ workflows: - build-and-test-linux: &build matrix: parameters: - python-version: &python-versions [3.7.9, 3.8.9, 3.9.4, 3.10.0, 3.11.0] + python-version: &python-versions [3.8.9, 3.9.4, 3.10.0, 3.11.0, 3.12.0] - build-and-test-linux-aarch64: matrix: parameters: python-version: *python-versions - exclude: - - python-version: 3.7.9 - build-sdist - build-and-test-osx: &build-and-test-osx matrix: parameters: python-version: *python-versions cibw-arch: [x86_64, arm64] - exclude: - - python-version: 3.7.9 - cibw-arch: arm64 - build-and-test-windows: *build - test-codecov - test-doctest @@ -320,6 +315,9 @@ workflows: # test the lowest and highest of each minor for the dependencies dimod-version: [==0.12.0, ~=0.12.0] python-version: *python-versions + exclude: + - dimod-version: ==0.12.0 # Does not support Python 3.12 + python-version: 3.12.0 - test-linux-cpp11 - test-sdist: requires: diff --git a/pyproject.toml b/pyproject.toml index 691232b..39d63e3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = [ "setuptools>=46.4.0", # PEP-420 support, PEP-517/518 support, setup.cfg attr: support "wheel>=0.30.0", # limited python api support "cython~=3.0", - 'dimod==0.12.0', + 'dimod==0.12.13', # Lowest that support Python 3.8 through 3.12 'numpy==1.19.0;python_version<"3.9"', # C API for numpy.random 'oldest-supported-numpy;python_version>="3.9"', ] diff --git a/releasenotes/notes/python3.12-1e39dd7f62fb5dbe.yaml b/releasenotes/notes/python3.12-1e39dd7f62fb5dbe.yaml new file mode 100644 index 0000000..d474fe2 --- /dev/null +++ b/releasenotes/notes/python3.12-1e39dd7f62fb5dbe.yaml @@ -0,0 +1,5 @@ +--- +features: + - Build wheels for Python 3.12. +upgrade: + - No longer build wheels for Python 3.7. diff --git a/requirements.txt b/requirements.txt index 5c5794e..0b3494e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ cython==3.0.4 -dimod==0.12.1 +dimod==0.12.13 numpy==1.19.0;python_version<"3.9" # C API for numpy.random oldest-supported-numpy;python_version>="3.9" reno==3.3.0 # for changelog diff --git a/setup.cfg b/setup.cfg index 385f6e7..5a37ca6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,7 +10,7 @@ author = D-Wave Systems Inc. author_email = tools@dwavesys.com url = https://github.com/dwavesystems/dwave-samplers project_urls = - Documentation = https://docs.ocean.dwavesys.com/en/stable/docs_greedy/sdk_index.html + Documentation = https://docs.ocean.dwavesys.com Issue Tracker = https://github.com/dwavesystems/dwave-samplers/issues/ Source Code = https://github.com/dwavesystems/dwave-samplers/ classifiers = @@ -19,11 +19,11 @@ classifiers = Development Status :: 4 - Beta Programming Language :: Python :: 3 Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 Programming Language :: Python :: Implementation :: CPython [options] @@ -38,7 +38,7 @@ packages = dwave.samplers.tree zip_safe = false include_package_data = true -python_requires = >=3.7 +python_requires = >=3.8 install_requires = numpy>=1.19.0,<2.0.0 dimod>=0.12.0,<0.13.0