Manopt Solver Callbacks

The callback functionality is meant to provide a user with direct access to the solver (problem and state) at certain points of a solver run to inspect or modify it.

Functions

Manopt.provided_callbacksMethod
provided_callbacks(state_type::Type{S}) where {S<:AbstractManoptSolverState})

For a solver of type S return the callbacks the solver provides, i.e. all ones that are called during the solver run. This function returns a vector Symbols representing the hooks. These can be kays in a dictionary of callbacks.

source

Internal functions

Manopt._callbacks_summaryMethod
_callbacks_summary(state::AbstractManoptSolverState)

Generate callback summary for a given solver state s. This function returns a string that contains the active callbacks in the solver state. If no callbacks are active, an empty string is returned.

source
Manopt.callbackMethod
callback(name::Symbol, problem::AbstractManoptProblem, state::AbstractManoptState, iteration::Int)

Perform a callback.

This function performs a call to both possible approaches

  • if a callback exists in the dictionary under the symbol name it is called with the parameters problem, state, iteration
  • if a callback exists in the dictionary that shall be called :Any time, this one is called with name, problem, state, iteration
source
Manopt.process_callbacks_argFunction
process_callbacks_arg(callbacks::Vector, statetype=missing)
process_callbacks_arg(callbacks::Dict, statetype=missing) = callbacks

Given a vector callbacks a user has passed to a solver, this helper function processes the vector in the following way

  • a pair :Hook => fct is kept as is, where the fct` can also be some callable structure
  • a single element function is turned into :Any => fct allowing the case a single callback to be specified just with the function
  • a pair [Hook1, Hook2] => fct is a shortcut for an array of pairs and split into these here.

The result is then wrapped into a dictionary. Be aware that from an array of pairs this function reduces, the dictionary “takes” the last :Hook pair as the entry in the dictionary. This function does not check for duplicates.

This function keeps a dictionary unchanged. Hence they are only processed once even if this function is applied multiple times.

If a statetype is provided, the final dictionary of callbacks is validated against the provided callback hooks by that state and a warning is issued if there are hooks that do not have an effect.

source