Skip to content

Commit 86f0222

Browse files
Update pyensmallen_optimizers.py
1 parent 0b5f667 commit 86f0222

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/optimagic/optimizers/pyensmallen_optimizers.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Implement ensmallen optimizers."""
22

33
from dataclasses import dataclass
4+
from typing import Any
45

56
import numpy as np
67
from numpy.typing import NDArray
@@ -90,11 +91,17 @@ def objective_function(
9091
grad[:] = jac
9192
return np.float64(fun)
9293

93-
raw = optimizer.optimize(objective_function, x0)
94+
# Passing a Report class to the optimizer allows us to retrieve additional info
95+
ens_res: dict[str, Any] = dict()
96+
report = pye.Report(resultIn=ens_res, disableOutput=True)
97+
best_x = optimizer.optimize(objective_function, x0, report)
9498

9599
res = InternalOptimizeResult(
96-
x=raw, # only best x is available
97-
fun=problem.fun(raw), # best f(x) value is not available
100+
x=best_x,
101+
fun=ens_res["objective_value"],
102+
n_iterations=ens_res["iterations"],
103+
n_fun_evals=ens_res["evaluate_calls"],
104+
n_jac_evals=ens_res["gradient_calls"],
98105
)
99106

100107
return res

0 commit comments

Comments
 (0)