pub trait Observe<I> {
fn observe_init(&mut self, _name: &str, _kv: &KV) -> Result<(), Error> { ... }
fn observe_iter(&mut self, _state: &I, _kv: &KV) -> Result<(), Error> { ... }
}
Expand description
An interface which every observer is required to implement
Example
use argmin::core::{Error, KV, State};
use argmin::core::observers::Observe;
struct MyObserver {}
impl<I> Observe<I> for MyObserver
where
// Optional constraint on `I`. The `State` trait, which every state used in argmin needs to
// implement, offers a range of methods which can be useful.
I: State,
{
fn observe_init(&mut self, name: &str, kv: &KV) -> Result<(), Error> {
// Do something with `name` and/or `kv`
// Is executed after initialization of a solver
Ok(())
}
fn observe_iter(&mut self, state: &I, kv: &KV) -> Result<(), Error> {
// Do something with `state` and/or `kv`
// Is executed after each iteration of a solver
Ok(())
}
}
Provided Methods
Called once after initialization of the solver.
Has access to the name of the solver via name
and to a key-value store kv
with entries
specific for each solver.
Implementors
impl<I> Observe<I> for WriteToFile where
I: State,
<I as State>::Param: Serialize,
WriteToFile
only implements observer_iter
and not observe_init
to avoid saving the
initial parameter vector. It will only save if there is a parameter vector available in the
state, otherwise it will skip saving silently.