Expand description


Argmin offers an interface to observe the state of the solver at initialization as well as after every iteration. This includes the parameter vector, gradient, Jacobian, Hessian, iteration number, cost values and many more as well as solver-specific metrics. This interface can be used to implement loggers, send the information to a storage or to plot metrics.

The observer WriteToFile saves the parameter vector to disk and as such requires the parameter vector to be serializable. Hence this feature is only available with the serde1 feature.

The observer SlogLogger logs the progress of the optimization to screen or to disk. This requires the slog-logger feature. Writing to disk in addtion requires the serde1 feature.

For each observer it can be defined how often it will observe the progress of the solver. This is indicated via the enum ObserverMode which can be either Always, Never, NewBest (whenever a new best solution is found) or Every(i) which means every ith iteration.

Custom observers can be used as well by implementing the crate::core::observers::Observe trait.


// [...]

let res = Executor::new(problem, solver)
    .configure(|config| config.param(init_param).max_iters(2))
    // Add an observer which will log all iterations to the terminal (without blocking)
    .add_observer(SlogLogger::term_noblock(), ObserverMode::Always)
    // Log to file whenever a new best solution is found
    .add_observer(SlogLogger::file("solver.log", false)?, ObserverMode::NewBest)
    // Write parameter vector to `params/param.arg` every 20th iteration
        WriteToFile::new("params", "param", WriteToFileSerializer::JSON),
    // run the solver on the defined problem

// [...]


pub use file::*;
pub use slog_logger::*;


Write parameter vectors to a file during optimization.

Loggers based on the slog crate


Container for observers.


Indicates when to call an observer.


An interface which every observer is required to implement