Skip to content

Commit 8fce265

Browse files
Make tests compatible with SciPy 1.16 (#966)
* Set scipy>=1.16 * Release pinned scipy and change x0 for cobyla * Enforces 1D arrays in all jac modes as per scipy 1.16 * Fix formatting * Fix copyright --------- Co-authored-by: M. Emre Sahin <40424147+OkuyanBoga@users.noreply.github.com>
1 parent a88432f commit 8fce265

31 files changed

+52
-50
lines changed

docs/lowercase_filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2021, 2023.
3+
# (C) Copyright IBM 2021, 2025.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -10,7 +10,7 @@
1010
# copyright notice, and modified files need to carry a notice indicating
1111
# that they have been altered from the originals.
1212

13-
""" Implements a Lower Case Filter for Sphinx spelling """
13+
"""Implements a Lower Case Filter for Sphinx spelling"""
1414

1515
from enchant import tokenize
1616

qiskit_machine_learning/algorithms/classifiers/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2020, 2023.
3+
# (C) Copyright IBM 2020, 2025.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -10,7 +10,7 @@
1010
# copyright notice, and modified files need to carry a notice indicating
1111
# that they have been altered from the originals.
1212

13-
""" Classifiers Package """
13+
"""Classifiers Package"""
1414

1515
from .neural_network_classifier import NeuralNetworkClassifier
1616
from .qsvc import QSVC

qiskit_machine_learning/algorithms/inference/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2023, 2024.
3+
# (C) Copyright IBM 2023, 2025.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -10,7 +10,7 @@
1010
# copyright notice, and modified files need to carry a notice indicating
1111
# that they have been altered from the originals.
1212

13-
""" Inference Package """
13+
"""Inference Package"""
1414

1515

1616
from .qbayesian import QBayesian

qiskit_machine_learning/algorithms/regressors/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2021, 2023.
3+
# (C) Copyright IBM 2021, 2025.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -10,7 +10,7 @@
1010
# copyright notice, and modified files need to carry a notice indicating
1111
# that they have been altered from the originals.
1212

13-
""" Regressors Package"""
13+
"""Regressors Package"""
1414

1515
from .qsvr import QSVR
1616
from .neural_network_regressor import NeuralNetworkRegressor

qiskit_machine_learning/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2021, 2024.
3+
# (C) Copyright IBM 2021, 2025.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -10,7 +10,7 @@
1010
# copyright notice, and modified files need to carry a notice indicating
1111
# that they have been altered from the originals.
1212

13-
""" Machine Learning Exception """
13+
"""Machine Learning Exception"""
1414

1515
from qiskit.exceptions import QiskitError
1616

qiskit_machine_learning/optimizers/optimizer_utils/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2022, 2024.
3+
# (C) Copyright IBM 2022, 2025.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -9,7 +9,7 @@
99
# Any modifications or derivative works of this code must retain this
1010
# copyright notice, and modified files need to carry a notice indicating
1111
# that they have been altered from the originals.
12-
""" Supplementary tools for optimizers. """
12+
"""Supplementary tools for optimizers."""
1313

1414
from .learning_rate import LearningRate
1515

qiskit_machine_learning/optimizers/scipy_optimizer.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2018, 2024.
3+
# (C) Copyright IBM 2018, 2025.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -133,9 +133,8 @@ def minimize(
133133
Optimizer.gradient_num_diff, (fun, epsilon, self._max_evals_grouped)
134134
)
135135

136-
# Workaround for L_BFGS_B because it does not accept np.ndarray.
137-
# See https://github.com/Qiskit/qiskit/pull/6373.
138-
if jac is not None and self._method == "l-bfgs-b":
136+
# Ensure gradient is 1D for scipy>=1.16
137+
if jac is not None:
139138
jac = self._wrap_gradient(jac)
140139

141140
# Starting in scipy 1.9.0 maxiter is deprecated and maxfun (added in 1.5.0)
@@ -170,8 +169,8 @@ def minimize(
170169
def _wrap_gradient(gradient_function):
171170
def wrapped_gradient(x):
172171
gradient = gradient_function(x)
173-
if isinstance(gradient, np.ndarray):
174-
return gradient.tolist()
172+
# Ensure gradient is a 1D numpy array
173+
gradient = np.asarray(gradient).ravel()
175174
return gradient
176175

177176
return wrapped_gradient

qiskit_machine_learning/utils/loss_functions/kernel_loss_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2021, 2023.
3+
# (C) Copyright IBM 2021, 2025.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -10,7 +10,7 @@
1010
# copyright notice, and modified files need to carry a notice indicating
1111
# that they have been altered from the originals.
1212

13-
""" Kernel Loss utilities """
13+
"""Kernel Loss utilities"""
1414

1515
from abc import ABC, abstractmethod
1616
from typing import Sequence

qiskit_machine_learning/utils/loss_functions/loss_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2021, 2023.
3+
# (C) Copyright IBM 2021, 2025.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -10,7 +10,7 @@
1010
# copyright notice, and modified files need to carry a notice indicating
1111
# that they have been altered from the originals.
1212

13-
""" Loss utilities """
13+
"""Loss utilities"""
1414

1515
from abc import ABC, abstractmethod
1616

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
qiskit>=1.0,<2.0
22
numpy>=2.0
3-
scipy>=1.4,<1.16
3+
scipy>=1.4
44
scikit-learn>=1.2
55
setuptools>=40.1
66
dill>=0.3.4

0 commit comments

Comments
 (0)