Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/optimagic/optimizers/nag_optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ class NagPyBOBYQA(Algorithm):

"""

stopping_max_criterion_evaluations: PositiveInt = STOPPING_MAXFUN
stopping_maxfun: PositiveInt = STOPPING_MAXFUN
"""Maximum number of criterion evaluations.

If reached, the optimization stops, but this is not counted as successful
Expand Down Expand Up @@ -1184,7 +1184,7 @@ class NagPyBOBYQA(Algorithm):
- ``max_iterations_without_new_best_after_soft_reset`` (int): The maximum number
of successful steps in a given run where the new criterion value is worse than
the best value found in previous runs before terminating. The default is
``stopping_max_criterion_evaluations``.
``stopping_maxfun``.
- ``auto_detect`` (bool): Whether or not to automatically determine when to
reset. This is an additional condition and resets can still be triggered by a
small upper trust-region radius, etc. There are two criteria used: upper
Expand Down Expand Up @@ -1285,7 +1285,7 @@ def _solve_internal_problem(
noise_n_evals_per_point=self.noise_n_evals_per_point,
random_directions_orthogonal=self.random_directions_orthogonal,
seek_global_optimum=self.seek_global_optimum,
stopping_max_criterion_evaluations=self.stopping_max_criterion_evaluations,
stopping_maxfun=self.stopping_maxfun,
threshold_for_safety_step=self.threshold_for_safety_step,
trustregion_expansion_factor_successful=self.trustregion_expansion_factor_successful,
trustregion_expansion_factor_very_successful=self.trustregion_expansion_factor_very_successful, # noqa: E501
Expand Down Expand Up @@ -1320,7 +1320,7 @@ def nag_pybobyqa_internal(
noise_n_evals_per_point,
random_directions_orthogonal,
seek_global_optimum,
stopping_max_criterion_evaluations,
stopping_maxfun,
threshold_for_safety_step,
trustregion_expansion_factor_successful,
trustregion_expansion_factor_very_successful, # noqa: E501
Expand Down Expand Up @@ -1402,7 +1402,7 @@ def nag_pybobyqa_internal(
criterion,
x0=x,
bounds=(lower_bounds, upper_bounds),
maxfun=stopping_max_criterion_evaluations,
maxfun=stopping_maxfun,
rhobeg=trustregion_initial_radius,
user_params=advanced_options,
scaling_within_bounds=False,
Expand Down
13 changes: 13 additions & 0 deletions tests/optimagic/optimizers/test_nag_optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest

from optimagic import mark
from optimagic.config import IS_PYBOBYQA_INSTALLED
from optimagic.optimization.optimize import minimize
from optimagic.optimizers.nag_optimizers import (
IS_DFOLS_INSTALLED,
Expand Down Expand Up @@ -94,3 +95,15 @@ def test_nag_dfols_starting_at_optimum():
bounds=Bounds(-1 * np.ones_like(params), np.ones_like(params)),
)
aaae(res.params, params)


@pytest.mark.skipif(not IS_PYBOBYQA_INSTALLED, reason="Py-BOBYQA is not installed.")
def test_nag_pybobyqa_respects_stopping_maxfun_from_algo_options():
res = minimize(
fun=lambda x: x @ x,
params=np.arange(1.0, 6.0),
algorithm="nag_pybobyqa",
algo_options={"stopping_maxfun": 15},
)
assert res.history is not None
assert len(res.history.fun) <= 15
Loading