diff --git a/.tools/envs/testenv-linux.yml b/.tools/envs/testenv-linux.yml index f80b48eb8..827c56d40 100644 --- a/.tools/envs/testenv-linux.yml +++ b/.tools/envs/testenv-linux.yml @@ -28,7 +28,7 @@ dependencies: - jinja2 # dev, tests - annotated-types # dev, tests - pip: # dev, tests, docs - - DFO-LS # dev, tests + - DFO-LS>=1.5.3 # dev, tests - Py-BOBYQA # dev, tests - fides==0.7.4 # dev, tests - kaleido # dev, tests diff --git a/.tools/envs/testenv-numpy.yml b/.tools/envs/testenv-numpy.yml index f54e96c17..ef75ece28 100644 --- a/.tools/envs/testenv-numpy.yml +++ b/.tools/envs/testenv-numpy.yml @@ -26,7 +26,7 @@ dependencies: - jinja2 # dev, tests - annotated-types # dev, tests - pip: # dev, tests, docs - - DFO-LS # dev, tests + - DFO-LS>=1.5.3 # dev, tests - Py-BOBYQA # dev, tests - fides==0.7.4 # dev, tests - kaleido # dev, tests diff --git a/.tools/envs/testenv-others.yml b/.tools/envs/testenv-others.yml index 0fc410f86..9b81be122 100644 --- a/.tools/envs/testenv-others.yml +++ b/.tools/envs/testenv-others.yml @@ -26,7 +26,7 @@ dependencies: - jinja2 # dev, tests - annotated-types # dev, tests - pip: # dev, tests, docs - - DFO-LS # dev, tests + - DFO-LS>=1.5.3 # dev, tests - Py-BOBYQA # dev, tests - fides==0.7.4 # dev, tests - kaleido # dev, tests diff --git a/.tools/envs/testenv-pandas.yml b/.tools/envs/testenv-pandas.yml index 6918bafae..d7e99f2be 100644 --- a/.tools/envs/testenv-pandas.yml +++ b/.tools/envs/testenv-pandas.yml @@ -26,7 +26,7 @@ dependencies: - jinja2 # dev, tests - annotated-types # dev, tests - pip: # dev, tests, docs - - DFO-LS # dev, tests + - DFO-LS>=1.5.3 # dev, tests - Py-BOBYQA # dev, tests - fides==0.7.4 # dev, tests - kaleido # dev, tests diff --git a/docs/source/algorithms.md b/docs/source/algorithms.md index 363ce5faf..006e25402 100644 --- a/docs/source/algorithms.md +++ b/docs/source/algorithms.md @@ -1083,6 +1083,8 @@ install each of them separately: ```{eval-rst} .. dropdown:: nag_dfols + *Note*: We recommend to install `DFO-LS` version 1.5.3 or higher. Versions of 1.5.0 or lower also work but the versions `1.5.1` and `1.5.2` contain bugs that can lead to errors being raised. + .. code-block:: "nag_dfols" diff --git a/docs/source/installation.md b/docs/source/installation.md index 1c4ea3ac5..912e213b6 100644 --- a/docs/source/installation.md +++ b/docs/source/installation.md @@ -40,6 +40,10 @@ pip install Py-BOBYQA pip install DFO-LS ``` +*Note*: We recommend to install `DFO-LS` version 1.5.3 or higher. Versions of 1.5.0 or +lower also work but the versions `1.5.1` and `1.5.2` contain bugs that can lead to +errors being raised. + ``` conda install -c conda-forge petsc4py ``` diff --git a/environment.yml b/environment.yml index 562d1c9cd..a608d5540 100644 --- a/environment.yml +++ b/environment.yml @@ -38,7 +38,7 @@ dependencies: - furo # dev, docs - annotated-types # dev, tests - pip: # dev, tests, docs - - DFO-LS # dev, tests + - DFO-LS>=1.5.3 # dev, tests - Py-BOBYQA # dev, tests - fides==0.7.4 # dev, tests - kaleido # dev, tests diff --git a/src/optimagic/optimizers/nag_optimizers.py b/src/optimagic/optimizers/nag_optimizers.py index a83ac7900..e708b5915 100644 --- a/src/optimagic/optimizers/nag_optimizers.py +++ b/src/optimagic/optimizers/nag_optimizers.py @@ -630,7 +630,7 @@ def nag_dfols_internal( fun=res["solution_criterion"], success=res["success"], message=res["message"], - n_iterations=int(res["n_iterations"]), + n_iterations=res["n_iterations"], n_fun_evals=res["n_fun_evals"], ) return out @@ -857,7 +857,7 @@ def nag_pybobyqa_internal( fun=res["solution_criterion"], success=res["success"], message=res["message"], - n_iterations=int(res["n_iterations"]), + n_iterations=res["n_iterations"], ) return out @@ -890,9 +890,8 @@ def _process_nag_result(nag_result_obj, len_x): "diagnostic_info": nag_result_obj.diagnostic_info, } try: - processed["n_iterations"] = nag_result_obj.diagnostic_info["iters_total"].iloc[ - -1 - ] + n_iterations = int(nag_result_obj.diagnostic_info["iters_total"].iloc[-1]) + processed["n_iterations"] = n_iterations except (KeyboardInterrupt, SystemExit): raise except Exception: diff --git a/tests/optimagic/optimization/test_many_algorithms.py b/tests/optimagic/optimization/test_many_algorithms.py index 52b7df33c..1882aeb08 100644 --- a/tests/optimagic/optimization/test_many_algorithms.py +++ b/tests/optimagic/optimization/test_many_algorithms.py @@ -86,3 +86,15 @@ def test_global_algorithms_on_sum_of_squares(algorithm): ) assert res.success in [True, None] aaae(res.params, np.array([0.2, 0]), decimal=1) + + +def test_nag_dfols_starting_at_optimum(): + # From issue: https://github.com/optimagic-dev/optimagic/issues/538 + params = np.zeros(2, dtype=float) + res = minimize( + fun=sos, + params=params, + algorithm="nag_dfols", + bounds=Bounds(-1 * np.ones_like(params), np.ones_like(params)), + ) + aaae(res.params, params)