opytimizer.utils.callback

Callbacks.

class opytimizer.utils.callback.Callback

A Callback class that handles additional variables and methods manipulation that are not provided by the library.

__init__()

Initialization method.

on_task_begin(opt_model: Opytimizer) → None

Performs a callback whenever a task begins.

Parameters:opt_model – An instance of the optimization model.
on_task_end(opt_model: Opytimizer) → None

Performs a callback whenever a task ends.

Parameters:opt_model – An instance of the optimization model.
on_iteration_begin(iteration: int, opt_model: Opytimizer) → None

Performs a callback whenever an iteration begins.

Parameters:
  • iteration – Current iteration.
  • opt_model – An instance of the optimization model.
on_iteration_end(iteration: int, opt_model: Opytimizer) → None

Performs a callback whenever an iteration ends.

Parameters:
  • iteration – Current iteration.
  • opt_model – An instance of the optimization model.
on_evaluate_before(*evaluate_args) → None

Performs a callback prior to the evaluate method.

on_evaluate_after(*evaluate_args) → None

Performs a callback after the evaluate method.

on_update_before(*update_args) → None

Performs a callback prior to the update method.

on_update_after(*update_args) → None

Performs a callback after the update method.

class opytimizer.utils.callback.CallbackVessel(callbacks: List[opytimizer.utils.callback.Callback])

Wraps multiple callbacks in an ready-to-use class.

__init__(callbacks: List[opytimizer.utils.callback.Callback]) → None

Initialization method.

Parameters:callbacks – List of Callback-based childs.
callbacks

List of Callback-based childs.

on_task_begin(opt_model: Opytimizer) → None

Performs a list of callbacks whenever a task begins.

Parameters:opt_model – An instance of the optimization model.
on_task_end(opt_model: Opytimizer) → None

Performs a list of callbacks whenever a task ends.

Parameters:opt_model – An instance of the optimization model.
on_iteration_begin(iteration: int, opt_model: Opytimizer) → None

Performs a list of callbacks whenever an iteration begins.

Parameters:
  • iteration – Current iteration.
  • opt_model – An instance of the optimization model.
on_iteration_end(iteration: int, opt_model: Opytimizer) → None

Performs a list of callbacks whenever an iteration ends.

Parameters:
  • iteration – Current iteration.
  • opt_model – An instance of the optimization model.
on_evaluate_before(*evaluate_args) → None

Performs a list of callbacks prior to the evaluate method.

on_evaluate_after(*evaluate_args) → None

Performs a list of callbacks after the evaluate method.

on_update_before(*update_args) → None

Performs a list of callbacks prior to the update method.

on_update_after(*update_args) → None

Performs a list of callbacks after the update method.

class opytimizer.utils.callback.CheckpointCallback(file_path: Optional[str] = None, frequency: Optional[int] = 0)

A CheckpointCallback class that handles additional logging and model’s checkpointing.

__init__(file_path: Optional[str] = None, frequency: Optional[int] = 0) → None

Initialization method.

Parameters:
  • file_path – Path of file to be saved.
  • frequency – Interval between checkpoints.
file_path

File’s path.

frequency

Interval between checkpoints.

on_iteration_end(iteration: int, opt_model: Opytimizer) → None

Performs a callback whenever an iteration ends.

Parameters:
  • iteration – Current iteration.
  • opt_model – An instance of the optimization model.
class opytimizer.utils.callback.DiscreteSearchCallback(allowed_values: List[Union[int, float]] = None)

A DiscreteSearchCallback class that handles mapping floating-point variables to discrete values.

__init__(allowed_values: List[Union[int, float]] = None) → None

Initialization method.

Parameters:allowed_values – Possible values between lower and upper bounds that variables can be mapped.
allowed_values

Allowed values between lower and upper bounds.

on_task_begin(opt_model: Opytimizer) → None

Performs a callback whenever a task begins.

Parameters:opt_model – An instance of the optimization model.
on_evaluate_before(*evaluate_args) → None

Performs a callback prior to the evaluate method.