diff --git a/pybop/_optimisation.py b/pybop/_optimisation.py index d5114b28..04e0b4ad 100644 --- a/pybop/_optimisation.py +++ b/pybop/_optimisation.py @@ -175,15 +175,16 @@ def _run_pybop(self): final_cost : float The final cost associated with the best parameters. """ - x, final_cost = self.optimiser.optimise( + result = self.optimiser.optimise( cost_function=self.cost, x0=self.x0, bounds=self.bounds, maxiter=self._max_iterations, ) self.log = self.optimiser.log + self._iterations = result.nit - return x, final_cost + return result.x, self.cost(result.x) def _run_pints(self): """ diff --git a/pybop/optimisers/base_optimiser.py b/pybop/optimisers/base_optimiser.py index 29cc219a..f8796bc9 100644 --- a/pybop/optimisers/base_optimiser.py +++ b/pybop/optimisers/base_optimiser.py @@ -38,7 +38,7 @@ def optimise(self, cost_function, x0=None, bounds=None, maxiter=None): self.cost_function = cost_function self.x0 = x0 self.bounds = bounds - self.maxiter = maxiter + self._max_iterations = maxiter # Run optimisation result = self._runoptimise(self.cost_function, x0=self.x0, bounds=self.bounds) diff --git a/pybop/optimisers/scipy_optimisers.py b/pybop/optimisers/scipy_optimisers.py index f4ea49a7..5fc12ea6 100644 --- a/pybop/optimisers/scipy_optimisers.py +++ b/pybop/optimisers/scipy_optimisers.py @@ -80,7 +80,7 @@ def cost_wrapper(x): else: self.options.pop("maxiter", None) - output = minimize( + result = minimize( cost_wrapper, x0, method=self.method, @@ -89,11 +89,7 @@ def cost_wrapper(x): callback=callback, ) - # Get performance statistics - x = output.x - final_cost = cost_function(x) - - return x, final_cost + return result def needs_sensitivities(self): """ @@ -182,7 +178,7 @@ def callback(x, convergence): (lower, upper) for lower, upper in zip(bounds["lower"], bounds["upper"]) ] - output = differential_evolution( + result = differential_evolution( cost_function, bounds, strategy=self.strategy, @@ -191,11 +187,7 @@ def callback(x, convergence): callback=callback, ) - # Get performance statistics - x = output.x - final_cost = output.fun - - return x, final_cost + return result def set_population_size(self, population_size=None): """