diff --git a/qiskit_algorithms/optimizers/snobfit.py b/qiskit_algorithms/optimizers/snobfit.py index f74d8ca8..8c87fd60 100644 --- a/qiskit_algorithms/optimizers/snobfit.py +++ b/qiskit_algorithms/optimizers/snobfit.py @@ -15,6 +15,7 @@ from typing import Any, Dict, Optional, Callable, Tuple, List import numpy as np +from qiskit.exceptions import QiskitError from qiskit.utils import optionals as _optionals from .optimizer import Optimizer, OptimizerSupportLevel, OptimizerResult, POINT @@ -50,7 +51,17 @@ def __init__( Raises: MissingOptionalLibraryError: scikit-quant or SQSnobFit not installed + QiskitError: If NumPy 1.24.0 or above is installed. + See https://github.com/scikit-quant/scikit-quant/issues/24 for more details. """ + # check version + version = tuple(map(int, np.__version__.split("."))) + if version >= (1, 24, 0): + raise QiskitError( + "SnobFit is incompatible with NumPy 1.24.0 or above, please " + "install a previous version. See also scikit-quant/scikit-quant#24." + ) + super().__init__() self._maxiter = maxiter self._maxfail = maxfail diff --git a/test/optimizers/test_optimizers_scikitquant.py b/test/optimizers/test_optimizers_scikitquant.py index 63dd95c4..70716c4e 100644 --- a/test/optimizers/test_optimizers_scikitquant.py +++ b/test/optimizers/test_optimizers_scikitquant.py @@ -17,6 +17,7 @@ from ddt import ddt, data, unpack +import numpy from qiskit import BasicAer from qiskit.circuit.library import RealAmplitudes from qiskit.utils import QuantumInstance, algorithm_globals @@ -63,6 +64,10 @@ def test_bobyqa(self): except MissingOptionalLibraryError as ex: self.skipTest(str(ex)) + @unittest.skipIf( + tuple(map(int, numpy.__version__.split("."))) >= (1, 24, 0), + "scikit's SnobFit currently incompatible with NumPy 1.24.0.", + ) def test_snobfit(self): """SNOBFIT optimizer test.""" try: @@ -71,6 +76,10 @@ def test_snobfit(self): except MissingOptionalLibraryError as ex: self.skipTest(str(ex)) + @unittest.skipIf( + tuple(map(int, numpy.__version__.split("."))) >= (1, 24, 0), + "scikit's SnobFit currently incompatible with NumPy 1.24.0.", + ) @data((None,), ([(-1, 1), (None, None)],)) @unpack def test_snobfit_missing_bounds(self, bounds):