• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

qiskit-community / qiskit-algorithms / 15802199099

13 Jun 2025 01:21PM CUT coverage: 90.448%. Remained the same
15802199099

push

github

web-flow
Fix getter/setter type mismatch (#232)

1 of 1 new or added line in 1 file covered. (100.0%)

6401 of 7077 relevant lines covered (90.45%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.17
/qiskit_algorithms/optimizers/bobyqa.py
1
# This code is part of a Qiskit project.
2
#
3
# (C) Copyright IBM 2019, 2023.
4
#
5
# This code is licensed under the Apache License, Version 2.0. You may
6
# obtain a copy of this license in the LICENSE.txt file in the root directory
7
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8
#
9
# Any modifications or derivative works of this code must retain this
10
# copyright notice, and modified files need to carry a notice indicating
11
# that they have been altered from the originals.
12

13
"""Bound Optimization BY Quadratic Approximation (BOBYQA) optimizer."""
14

15
from __future__ import annotations
1✔
16

17
from collections.abc import Callable
1✔
18
from typing import Any
1✔
19

20
import numpy as np
1✔
21
from qiskit_algorithms.utils import optionals as _optionals
1✔
22
from .optimizer import Optimizer, OptimizerSupportLevel, OptimizerResult, POINT
1✔
23

24

25
@_optionals.HAS_SKQUANT.require_in_instance
1✔
26
class BOBYQA(Optimizer):
1✔
27
    """Bound Optimization BY Quadratic Approximation algorithm.
28

29
    BOBYQA finds local solutions to nonlinear, non-convex minimization problems with optional
30
    bound constraints, without requirement of derivatives of the objective function.
31

32
    Uses skquant.opt installed with pip install scikit-quant.
33
    For further detail, please refer to
34
    https://github.com/scikit-quant/scikit-quant and https://qat4chem.lbl.gov/software.
35
    """
36

37
    def __init__(
1✔
38
        self,
39
        maxiter: int = 1000,
40
    ) -> None:
41
        """
42
        Args:
43
            maxiter: Maximum number of function evaluations.
44

45
        Raises:
46
            MissingOptionalLibraryError: scikit-quant not installed
47
        """
48
        super().__init__()
×
49
        self._maxiter = maxiter
×
50

51
    def get_support_level(self):
1✔
52
        """Returns support level dictionary."""
53
        return {
×
54
            "gradient": OptimizerSupportLevel.ignored,
55
            "bounds": OptimizerSupportLevel.required,
56
            "initial_point": OptimizerSupportLevel.required,
57
        }
58

59
    @property
1✔
60
    def settings(self) -> dict[str, Any]:
1✔
61
        return {"maxiter": self._maxiter}
×
62

63
    def minimize(
1✔
64
        self,
65
        fun: Callable[[POINT], float],
66
        x0: POINT,
67
        jac: Callable[[POINT], POINT] | None = None,
68
        bounds: list[tuple[float, float]] | None = None,
69
    ) -> OptimizerResult:
70
        from skquant import opt as skq
×
71

72
        res, history = skq.minimize(
×
73
            func=fun,
74
            x0=np.asarray(x0),
75
            bounds=np.array(bounds),
76
            budget=self._maxiter,
77
            method="bobyqa",
78
        )
79

80
        optimizer_result = OptimizerResult()
×
81
        optimizer_result.x = res.optpar
×
82
        optimizer_result.fun = res.optval
×
83
        optimizer_result.nfev = len(history)
×
84
        return optimizer_result
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc