Skip to content

Adds supports for SBPLX optimizer from nlopt #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 14, 2025
Merged
4 changes: 4 additions & 0 deletions .pylintdict
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ izaac
izz
jac
jacobian
johnson
jones
july
kandala
Expand Down Expand Up @@ -311,6 +312,7 @@ sanjiv
sashank
satisfiability
satyen
sbplx
schrödinger
schroediger
schroedinger
Expand All @@ -337,11 +339,13 @@ stdout
stefano
steppable
stepsize
steven
str
subcircuits
subclassed
subclasses
subcomponents
subplex
subspaces
suzuki
swappable
Expand Down
14 changes: 13 additions & 1 deletion qiskit_algorithms/optimizers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2018, 2023.
# (C) Copyright IBM 2018, 2025.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -98,6 +98,16 @@
IMFIL
SNOBFIT

Qiskit also provides local optimizers based on
`NLOpt <https://nlopt.readthedocs.io/en/latest/>`_.
See Global Optimizers section below for the optional NLOpt installation instructions.

.. autosummary::
:toctree: ../stubs/
:nosignatures:

SBPLX

Global Optimizers
-----------------
The global optimizers here all use `NLOpt <https://nlopt.readthedocs.io/en/latest/>`_ for their
Expand Down Expand Up @@ -132,6 +142,7 @@
from .nlopts.direct_l_rand import DIRECT_L_RAND
from .nlopts.esch import ESCH
from .nlopts.isres import ISRES
from .nlopts.sbplx import SBPLX
from .steppable_optimizer import SteppableOptimizer, AskData, TellData, OptimizerState
from .optimizer import Minimizer, Optimizer, OptimizerResult, OptimizerSupportLevel
from .p_bfgs import P_BFGS
Expand Down Expand Up @@ -175,6 +186,7 @@
"DIRECT_L_RAND",
"ESCH",
"ISRES",
"SBPLX",
"SNOBFIT",
"BOBYQA",
"IMFIL",
Expand Down
6 changes: 4 additions & 2 deletions qiskit_algorithms/optimizers/nlopts/nloptimizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2018, 2023.
# (C) Copyright IBM 2018, 2025.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -33,12 +33,13 @@ class NLoptOptimizerType(Enum):
GN_DIRECT_L = 3
GN_ESCH = 4
GN_ISRES = 5
LN_SBPLX = 6


@_optionals.HAS_NLOPT.require_in_instance
class NLoptOptimizer(Optimizer):
"""
NLopt global optimizer base class
NLopt global and local optimizer base class
"""

_OPTIONS = ["max_evals"]
Expand All @@ -64,6 +65,7 @@ def __init__(self, max_evals: int = 1000) -> None: # pylint: disable=unused-arg
NLoptOptimizerType.GN_DIRECT_L: nlopt.GN_DIRECT_L,
NLoptOptimizerType.GN_ESCH: nlopt.GN_ESCH,
NLoptOptimizerType.GN_ISRES: nlopt.GN_ISRES,
NLoptOptimizerType.LN_SBPLX: nlopt.LN_SBPLX,
}

@abstractmethod
Expand Down
37 changes: 37 additions & 0 deletions qiskit_algorithms/optimizers/nlopts/sbplx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2025.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Sbplx (Subplex) optimizer."""

from .nloptimizer import NLoptOptimizer, NLoptOptimizerType


class SBPLX(NLoptOptimizer):
"""
Subplex optimizer.

"Subplex (a variant of Nelder-Mead that uses Nelder-Mead on a sequence of subspaces)
is claimed to be much more efficient and robust than the original Nelder-Mead,
while retaining the latter's facility with discontinuous objectives,
and in my experience these claims seem to be true in many cases.
(However, I'm not aware of any proof that Subplex is globally convergent,
and perhaps it may fail for some objectives like Nelder-Mead; YMMV.)"
Description by Steven G. Johnson, author of NLopt library.

NLopt local optimizer, derivative-free.
For further detail, please refer to
https://nlopt.readthedocs.io/en/latest/NLopt_Algorithms/#sbplx-based-on-subplex
"""

def get_nlopt_optimizer(self) -> NLoptOptimizerType:
"""Return NLopt optimizer type."""
return NLoptOptimizerType.LN_SBPLX
8 changes: 8 additions & 0 deletions releasenotes/notes/sbplx_optimizer-a27361fc4ac8de8c.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
features:
- |
Support for SBPLX optimizer from NLopt library has been added.
SBPLX is a local gradient-free optimizer based on Nelder-Mead and
is expected to show better convergence behaviour.
Further information about this and all other optimizers can be found
`in the API ref. here <https://qiskit-community.github.io/qiskit-algorithms/apidocs/qiskit_algorithms.optimizers.html>__`.
4 changes: 3 additions & 1 deletion test/optimizers/test_optimizers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2018, 2024.
# (C) Copyright IBM 2018, 2025.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -42,6 +42,7 @@
Optimizer,
P_BFGS,
POWELL,
SBPLX,
SLSQP,
SPSA,
QNSPSA,
Expand Down Expand Up @@ -224,6 +225,7 @@ def test_scipy_optimizer_parse_bounds(self):
(CRS, False),
(DIRECT_L, False),
(DIRECT_L_RAND, False),
(SBPLX, True),
)
@unpack
def test_nlopt(self, optimizer_cls, use_bound):
Expand Down
Loading