Skip to content

Commit

Permalink
Merge pull request #59 from arcondello/Cython3
Browse files Browse the repository at this point in the history
Update for Cython 3 and Python 3.12
  • Loading branch information
arcondello authored Oct 27, 2023
2 parents 6b336ab + ebe0d35 commit cb416fe
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 18 deletions.
16 changes: 7 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion dwave/samplers/greedy/descent.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion dwave/samplers/sa/simulated_annealing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<object>interrupt_function)()
except Exception:
Expand Down
2 changes: 2 additions & 0 deletions dwave/samplers/tree/sample.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions dwave/samplers/tree/solve.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
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",
'dimod==0.12.0',
"cython~=3.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"',
]
Expand Down
3 changes: 3 additions & 0 deletions releasenotes/notes/cython3-36beac915dba0ea1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
features:
- Build C++ extensions with Cython 3.
5 changes: 5 additions & 0 deletions releasenotes/notes/python3.12-1e39dd7f62fb5dbe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
features:
- Build wheels for Python 3.12.
upgrade:
- No longer build wheels for Python 3.7.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cython==0.29.28
dimod==0.12.1
cython==3.0.4
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
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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]
Expand All @@ -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
Expand Down

0 comments on commit cb416fe

Please sign in to comment.