diff --git a/src/optimagic/optimizers/nag_optimizers.py b/src/optimagic/optimizers/nag_optimizers.py index d26756292..d03ba97d6 100644 --- a/src/optimagic/optimizers/nag_optimizers.py +++ b/src/optimagic/optimizers/nag_optimizers.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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, diff --git a/tests/optimagic/optimizers/test_nag_optimizers.py b/tests/optimagic/optimizers/test_nag_optimizers.py index 827c2c68c..cd651a20d 100644 --- a/tests/optimagic/optimizers/test_nag_optimizers.py +++ b/tests/optimagic/optimizers/test_nag_optimizers.py @@ -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, @@ -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