Skip to content

Commit

Permalink
Fix NumPy 1.24.0 compatibility and pin coverage<7.0 (Qiskit/qiskit#…
Browse files Browse the repository at this point in the history
…9305)

* fix Kraus from (array, None)

* fix triu_to_dense test

* fix instruction comparison

* skip snobfit if numpy 1.24.0 or above is installed

Co-authored-by: ElePT <[email protected]>

* pin coverage <7.0

* add links to Kraus and snobfit issues

* retrigger CI

Co-authored-by: ElePT <[email protected]>
  • Loading branch information
Cryoris and ElePT authored Dec 20, 2022
1 parent 9a10db0 commit 8787551
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions qiskit_algorithms/optimizers/snobfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/optimizers/test_optimizers_scikitquant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit 8787551

Please sign in to comment.