Skip to content

Commit

Permalink
Finalise support for Numpy 2.0
Browse files Browse the repository at this point in the history
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:

- Qiskitgh-10890
- Qiskitgh-10891
- Qiskitgh-10892
- Qiskitgh-10897
- Qiskitgh-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.
  • Loading branch information
jakelishman committed Mar 12, 2024
1 parent 9f228fa commit 13163f0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
13 changes: 11 additions & 2 deletions qiskit/quantum_info/operators/symplectic/clifford.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,17 @@ def __init__(self, data, validate=True, copy=True):

# Initialize StabilizerTable directly from the data
else:
if isinstance(data, (list, np.ndarray)) and np.asarray(data, dtype=bool).ndim == 2:
data = np.array(data, dtype=bool, copy=copy)
if (
isinstance(data, (list, np.ndarray))
and (data_asarray := np.asarray(data, dtype=bool)).ndim == 2
):
# This little dance is to avoid Numpy 1/2 incompatiblities between the availability
# and meaning of the 'copy' argument in 'array' and 'asarray', when the input needs
# its dtype converting. 'asarray' prefers to return 'self' if possible in both.
if copy and data_asarray is data:
data = data_asarray.copy()
else:
data = data_asarray
if data.shape[0] == data.shape[1]:
self.tableau = self._stack_table_phase(
data, np.zeros(data.shape[0], dtype=bool)
Expand Down
2 changes: 1 addition & 1 deletion qiskit/visualization/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _num_to_latex(raw_value, decimals=15, first_term=True, coefficient=False):
"""
import sympy # runtime import

raw_value = np.around(raw_value, decimals=decimals)
raw_value = np.around(raw_value, decimals=decimals).item()
value = sympy.nsimplify(raw_value, rational=False)

if isinstance(value, sympy.core.numbers.Rational) and value.denominator > 50:
Expand Down
5 changes: 5 additions & 0 deletions releasenotes/notes/numpy-2.0-2f3e35bd42c48518.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
features:
- |
This release of Qiskit finalizes support for NumPy 2.0. Qiskit will continue to support both
Numpy 1.x and 2.x for the foreseeable future.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
rustworkx>=0.14.0
numpy>=1.17,<2
numpy>=1.17,<3
scipy>=1.5
sympy>=1.3
dill>=0.3
python-dateutil>=2.8.0
stevedore>=3.0.0
typing-extensions
symengine>=0.11
symengine>=0.11

0 comments on commit 13163f0

Please sign in to comment.