Struct argmin::core::Executor

source ·
pub struct Executor<O, S, I> { /* private fields */ }
Expand description

Solves an optimization problem with a solver

Implementations§

source§

impl<O, S, I> Executor<O, S, I>
where S: Solver<O, I>, I: State,

source

pub fn new(problem: O, solver: S) -> Self

Constructs an Executor from a user defined problem and a solver.

Example
// Construct an instance of the desired solver
let solver = Newton::new();

// `Rosenbrock` implements `CostFunction` and `Gradient` as required by the
// `SteepestDescent` solver
let problem = Rosenbrock {};

// Create instance of `Executor` with `problem` and `solver`
let executor = Executor::new(problem, solver);
source

pub fn configure<F: FnOnce(I) -> I>(self, init: F) -> Self

This method gives mutable access to the internal state of the solver. This allows for initializing the state before running the Executor. The options for initialization depend on the type of state used by the chosen solver. Common types of state are IterState, PopulationState, and LinearProgramState. Please see the documentation of the desired solver for information about which state is used.

Example
// Create instance of `Executor` with `problem` and `solver`
let executor = Executor::new(problem, solver)
    // Configure and initialize internal state.
    .configure(|state| state.param(init_param).max_iters(10));
source

pub fn run(self) -> Result<OptimizationResult<O, S, I>, Error>

Runs the executor by applying the solver to the optimization problem.

Example
// Create instance of `Executor` with `problem` and `solver`
let result = Executor::new(problem, solver)
    // Configure and initialize internal state.
    .configure(|state| state.param(init_param).max_iters(100))
    // Execute solver
    .run()?;
source

pub fn add_observer<OBS: Observe<I> + 'static>( self, observer: OBS, mode: ObserverMode ) -> Self

Adds an observer to the executor. Observers are required to implement the Observe trait. The parameter mode defines the conditions under which the observer will be called. See ObserverMode for details.

It is possible to add multiple observers.

Example
// Create instance of `Executor` with `problem` and `solver`
let executor = Executor::new(problem, solver)
    .add_observer(SlogLogger::term(), ObserverMode::Always);
source

pub fn checkpointing<C: 'static + Checkpoint<S, I>>(self, checkpoint: C) -> Self

Configures checkpointing

Example
let checkpoint = FileCheckpoint::new(
    // Directory where checkpoints are saved to
    ".checkpoints",
    // Filename of checkpoint
    "rosenbrock_optim",
    // How often checkpoints should be saved
    CheckpointingFrequency::Every(20)
);

// Create instance of `Executor` with `problem` and `solver`
let executor = Executor::new(problem, solver)
    // Add checkpointing
    .checkpointing(checkpoint);
source

pub fn ctrlc(self, ctrlc: bool) -> Self

Enables or disables CTRL-C handling (default: enabled). The CTRL-C handling gracefully stops the solver if it is canceled via CTRL-C (SIGINT). Requires the optional ctrlc feature to be set.

Note that this does not work with nested Executors. If a solver executes another solver internally, the inner solver needs to disable CTRL-C handling.

Example
// Create instance of `Executor` with `problem` and `solver`
let executor = Executor::new(problem, solver).ctrlc(false);
source

pub fn timer(self, timer: bool) -> Self

Enables or disables timing of individual iterations (default: enabled).

Setting this to false will silently be ignored in case a timeout is set.

Example
// Create instance of `Executor` with `problem` and `solver`
let executor = Executor::new(problem, solver).timer(false);
source

pub fn timeout(self, timeout: Duration) -> Self

Sets a timeout for the run.

The optimization run is stopped once the timeout is exceeded. Note that the check is performed after each iteration, therefore the actual runtime can exceed the the set duration. This also enables time measurements.

Example
// Create instance of `Executor` with `problem` and `solver`
let executor = Executor::new(problem, solver).timeout(std::time::Duration::from_secs(30));

Auto Trait Implementations§

§

impl<O, S, I> !RefUnwindSafe for Executor<O, S, I>

§

impl<O, S, I> !Send for Executor<O, S, I>

§

impl<O, S, I> !Sync for Executor<O, S, I>

§

impl<O, S, I> Unpin for Executor<O, S, I>
where I: Unpin, O: Unpin, S: Unpin,

§

impl<O, S, I> !UnwindSafe for Executor<O, S, I>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> SendAlias for T

source§

impl<T> SyncAlias for T