Skip to content

Commit

Permalink
Add current_iteration option to callback args
Browse files Browse the repository at this point in the history
  • Loading branch information
schmoelder committed Jun 27, 2023
1 parent 13cc333 commit d52e14e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CADETProcess/optimization/optimizationProblem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,7 @@ def evaluate_callbacks(self, ind, current_iteration=1, force=False):
continue

callback._ind = ind
callback._current_iteration = current_iteration

try:
self._evaluate(x, callback, force)
Expand Down Expand Up @@ -3050,7 +3051,9 @@ class Callback(metaclass=StructMeta):
Callable must implement function with the following signature:
results : obj
x or final result of evaluation toolchain.
individual : Individual, optional
_current_iteration: int
Current iteration.
_individual : Individual, optional
Information about current step of optimzer.
evaluation_object : obj, optional
Current evaluation object.
Expand Down Expand Up @@ -3129,6 +3132,8 @@ def __call__(self, request, evaluation_object):
kwargs = self.kwargs

signature = inspect.signature(self.callback).parameters
if 'current_iteration' in signature:
kwargs['current_iteration'] = self._current_iteration
if 'individual' in signature:
kwargs['individual'] = self._ind
if 'evaluation_object' in signature:
Expand Down

0 comments on commit d52e14e

Please sign in to comment.