Skip to content

Commit edbc1ab

Browse files
timmensclaude
andcommitted
Add documentation for scipy_cobyqa
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 8af006e commit edbc1ab

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

docs/source/algorithms.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,35 @@ automatically installed when you install optimagic.
313313
314314
```
315315

316+
```{eval-rst}
317+
.. dropdown:: scipy_cobyqa
318+
319+
**How to use this algorithm:**
320+
321+
.. code-block::
322+
323+
import optimagic as om
324+
om.minimize(
325+
...,
326+
algorithm=om.algos.scipy_cobyqa(stopping_maxfun=1_000, ...)
327+
)
328+
329+
or
330+
331+
.. code-block::
332+
333+
om.minimize(
334+
...,
335+
algorithm="scipy_cobyqa",
336+
algo_options={"stopping_maxfun": 1_000, ...}
337+
)
338+
339+
**Description and available options:**
340+
341+
.. autoclass:: optimagic.optimizers.scipy_optimizers.ScipyCOBYQA
342+
343+
```
344+
316345
```{eval-rst}
317346
.. dropdown:: scipy_truncated_newton
318347

src/optimagic/optimizers/scipy_optimizers.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -544,24 +544,17 @@ class ScipyCOBYQA(Algorithm):
544544
545545
"""
546546

547-
stopping_maxfun: PositiveInt | None = None
548-
"""Maximum number of function evaluations.
549-
550-
Defaults to 500 * n, where n is the number of variables.
551-
552-
"""
553-
554-
stopping_maxiter: PositiveInt | None = None
555-
"""Maximum number of iterations.
556-
557-
Defaults to 1000 * n, where n is the number of variables.
547+
stopping_maxfun: PositiveInt = STOPPING_MAXFUN
548+
"""Maximum number of function evaluations."""
558549

559-
"""
550+
stopping_maxiter: PositiveInt = STOPPING_MAXITER
551+
"""Maximum number of iterations."""
560552

561553
convergence_ftol_abs: NonNegativeFloat | None = None
562-
"""Tolerance for the objective function value.
554+
"""Target objective function value.
563555
564556
The algorithm stops when the objective function value is below this threshold.
557+
Disabled by default.
565558
566559
"""
567560

@@ -597,17 +590,15 @@ def _solve_internal_problem(
597590
radius = self.trustregion_initial_radius
598591

599592
options: dict[str, Any] = {
593+
"maxfev": self.stopping_maxfun,
594+
"maxiter": self.stopping_maxiter,
600595
"initial_tr_radius": radius,
601596
"final_tr_radius": self.trustregion_final_radius,
602597
"feasibility_tol": self.feasibility_tol,
603598
"scale": self.scale,
604599
"disp": self.display,
605600
}
606601

607-
if self.stopping_maxfun is not None:
608-
options["maxfev"] = self.stopping_maxfun
609-
if self.stopping_maxiter is not None:
610-
options["maxiter"] = self.stopping_maxiter
611602
if self.convergence_ftol_abs is not None:
612603
options["f_target"] = self.convergence_ftol_abs
613604

0 commit comments

Comments
 (0)