Skip to content

Commit 13163f0

Browse files
committed
Finalise support for Numpy 2.0
This commit brings the Qiskit test suite to a passing state (with all optionals installed) with Numpy 2.0.0b1, building on previous commits that handled much of the rest of the changing requirements: - gh-10890 - gh-10891 - gh-10892 - gh-10897 - gh-11023 Notably, this commit did not actually require a rebuild of Qiskit, despite us compiling against Numpy; it seems to happen that the C API stuff we use via `rust-numpy` (which loads the Numpy C extensions dynamically during module initialisation) hasn't changed.
1 parent 9f228fa commit 13163f0

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

qiskit/quantum_info/operators/symplectic/clifford.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,17 @@ def __init__(self, data, validate=True, copy=True):
163163

164164
# Initialize StabilizerTable directly from the data
165165
else:
166-
if isinstance(data, (list, np.ndarray)) and np.asarray(data, dtype=bool).ndim == 2:
167-
data = np.array(data, dtype=bool, copy=copy)
166+
if (
167+
isinstance(data, (list, np.ndarray))
168+
and (data_asarray := np.asarray(data, dtype=bool)).ndim == 2
169+
):
170+
# This little dance is to avoid Numpy 1/2 incompatiblities between the availability
171+
# and meaning of the 'copy' argument in 'array' and 'asarray', when the input needs
172+
# its dtype converting. 'asarray' prefers to return 'self' if possible in both.
173+
if copy and data_asarray is data:
174+
data = data_asarray.copy()
175+
else:
176+
data = data_asarray
168177
if data.shape[0] == data.shape[1]:
169178
self.tableau = self._stack_table_phase(
170179
data, np.zeros(data.shape[0], dtype=bool)

qiskit/visualization/array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def _num_to_latex(raw_value, decimals=15, first_term=True, coefficient=False):
3333
"""
3434
import sympy # runtime import
3535

36-
raw_value = np.around(raw_value, decimals=decimals)
36+
raw_value = np.around(raw_value, decimals=decimals).item()
3737
value = sympy.nsimplify(raw_value, rational=False)
3838

3939
if isinstance(value, sympy.core.numbers.Rational) and value.denominator > 50:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
This release of Qiskit finalizes support for NumPy 2.0. Qiskit will continue to support both
5+
Numpy 1.x and 2.x for the foreseeable future.

requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
rustworkx>=0.14.0
2-
numpy>=1.17,<2
2+
numpy>=1.17,<3
33
scipy>=1.5
44
sympy>=1.3
55
dill>=0.3
66
python-dateutil>=2.8.0
77
stevedore>=3.0.0
88
typing-extensions
9-
symengine>=0.11
9+
symengine>=0.11

0 commit comments

Comments
 (0)