Skip to main content

SelectedFirstOrderState

Struct SelectedFirstOrderState 

Source
pub struct SelectedFirstOrderState<V, F: Scalar = f64> { /* private fields */ }
Expand description

Solver-selected constrained progress with a matching objective gradient.

Construction provides an unevaluated seed. replace checks point and gradient dimensions before publishing a complete current record, while select_current explicitly chooses an incumbent. Selection can increase the objective to improve feasibility, so this state does not implement super::ObjectiveIncumbentState. The solver supplies a ViolationReport describing the measure, scaling, and transformation, and defines its eligibility rules.

Current records contain a point, objective, gradient, and violation. Best records contain the selected point, objective, and violation; their raw counts and iteration are stamped by the executor at publication. Selection events follow SelectedState, including preservation when current progress changes before publication. Derivatives are advertised only for current evaluated progress. All six evaluation categories retain their raw values.

Fresh initialization calls reset and reevaluates the seed. Exact continuation retains the solver and state together. With serde, serialization is available when V and F support it.

§Backends

Vec<F>, nalgebra DVector<F>, ndarray Array1<F>, and faer Col<F>, for F = f64 (default) or f32. Replacement requires VectorLen; state capabilities require only V: Clone.

ⓘ
use basin::{RunControl, SelectedFirstOrderState};
let _ = RunControl::<SelectedFirstOrderState<Vec<f64>>>::new().target_objective(0.0);

Implementations§

Source§

impl<V, F: Scalar> SelectedFirstOrderState<V, F>

Source

pub fn new(param: V) -> Self

Construct an unevaluated seed with no selected incumbent.

Source

pub fn reset(&mut self)

Clear records and bookkeeping, retaining the parameter as a fresh seed.

Source

pub fn current(&self) -> Option<(&V, F, &V, &ViolationReport<F>)>

Matching point, objective, gradient, and violation report, or None for a seed.

Source

pub fn best(&self) -> Option<(&V, F, &ViolationReport<F>)>

Selected point, objective, and violation report, or None before selection.

Source

pub fn counts(&self) -> &EvalCounts

All six raw evaluation categories at the current publication boundary.

Source

pub fn best_counts(&self) -> Option<&EvalCounts>

Raw counts recorded when the selected incumbent was published.

Source§

impl<V: VectorLen, F: Scalar> SelectedFirstOrderState<V, F>

Source

pub fn replace( &mut self, param: V, cost: F, gradient: V, violation: ViolationReport<F>, ) -> Result<(), GradientDimensionMismatch>

Replace current progress atomically, preserving any pending selection. A dimension mismatch leaves every record and counter unchanged.

Source§

impl<V: Clone, F: Scalar> SelectedFirstOrderState<V, F>

Source

pub fn select_current(&mut self) -> bool

Select the current evaluated record for the next publication boundary. Returns false for an unevaluated seed. Repeated observation does not refresh the selected record’s metadata.

Trait Implementations§

Source§

impl<V: Clone, F: Clone + Scalar> Clone for SelectedFirstOrderState<V, F>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<V: Clone, F: Scalar> ConstraintViolationState for SelectedFirstOrderState<V, F>

Source§

fn current_violation(&self) -> Option<&ViolationReport<F>>

Borrow the report matching the current evaluated point, or None.
Source§

fn incumbent_violation(&self) -> Option<&ViolationReport<F>>

Borrow the report matching the selected incumbent, or None.
Source§

impl<V: Clone, F: Scalar> CountsMirror for SelectedFirstOrderState<V, F>

Source§

fn mirror(&mut self, counts: &EvalCounts)

Overwrite the state’s counters from the per-run wrapper delta. Called by the executor after every successful Solver::init / Solver::next_iter.
Source§

impl<V: Debug, F: Debug + Scalar> Debug for SelectedFirstOrderState<V, F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, V, F> Deserialize<'de> for SelectedFirstOrderState<V, F>
where V: Deserialize<'de>, F: Deserialize<'de> + Scalar,

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<V: Clone, F: Scalar> EvaluatedGradientState for SelectedFirstOrderState<V, F>

Source§

fn current_gradient_record(&self) -> Option<(&V, F, &V)>

Borrow the matching point, cost, and gradient, or None for a seed.
Source§

impl<V: Clone, F: Scalar> EvaluatedState for SelectedFirstOrderState<V, F>

Source§

fn current_record(&self) -> Option<(&V, F)>

Borrow the complete current record’s point and cost, if available.
Source§

impl<V: Clone, F: Scalar> GradientState for SelectedFirstOrderState<V, F>

Source§

fn gradient(&self) -> Option<&V>

Gradient at the current param, if populated.
Source§

fn gradient_evals(&self) -> u64

Cumulative derivative work under the state’s CountsMirror mapping. In Basin 1.x this can include Jacobian, Hessian, and Hessian-product evaluations as well as gradient calls. Read more
Source§

fn best_gradient_evals(&self) -> u64

gradient_evals at the publication boundary that recorded the incumbent, the companion to State::best_cost_evals. This is not necessarily the count at the precise evaluation that found the point.
Source§

impl<V: Clone, F: Scalar> IncumbentState for SelectedFirstOrderState<V, F>

Source§

fn incumbent_record(&self) -> Option<IncumbentRef<'_, V, F>>

Borrow the selected record, if one has been established.
Source§

impl<V: PartialEq, F: PartialEq + Scalar> PartialEq for SelectedFirstOrderState<V, F>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<V: Clone, F: Scalar> RawEvaluationState for SelectedFirstOrderState<V, F>

Source§

fn raw_counts(&self) -> &EvalCounts

All six raw categories, without folding or reconstruction.
Source§

impl<V, F> Serialize for SelectedFirstOrderState<V, F>
where V: Serialize, F: Serialize + Scalar,

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<P, V, F> Solver<P, SelectedFirstOrderState<V, F>> for Slsqp<F>
where F: Scalar, P: CostFunction<Param = V, Output = F> + Gradient<Gradient = V>, P::Constraints: SlsqpSet<P, V, F>, V: Clone + VectorLen + VectorIndex<F>,

Source§

type Error = ConstraintSolveError<<P as CostFunction>::Error>

Hard-abort error type, mirroring the underlying problem’s type Error. See the trait docs.
Source§

fn init( &mut self, problem: &mut Problem<P>, state: SelectedFirstOrderState<V, F>, ) -> Result<SelectedFirstOrderState<V, F>, ConstraintSolveError<P::Error>>

One-time setup before the iteration loop. Read more
Source§

fn next_iter( &mut self, problem: &mut Problem<P>, state: SelectedFirstOrderState<V, F>, ) -> Result<SolverStep<SelectedFirstOrderState<V, F>>, ConstraintSolveError<P::Error>>

Advance one iteration. Read more
Source§

fn terminate( &self, _state: &SelectedFirstOrderState<V, F>, ) -> Option<Termination<F>>

Optional pre-iteration solver-specific termination test. Read more
Source§

fn reset_convergence(&mut self)

Reset per-run convergence history without changing algorithm state. Read more
Source§

fn should_check_iterate_change(&self) -> bool

Whether the current boundary can enter cost- and step-change checks. Read more
Source§

fn check_convergence( &mut self, _problem: &Problem<P>, state: &S, ) -> Option<Termination<S::Float>>

Check convergence at an initialized iteration boundary. Read more
Source§

impl<V: Clone, F: Scalar> State for SelectedFirstOrderState<V, F>

Source§

type Param = V

The parameter type the solver iterates over (e.g. Vec<f64>, nalgebra::DVector<f64>).
Source§

type Float = F

The scalar type of the objective, such as f64 or f32.
Source§

fn iter(&self) -> u64

Number of fully completed iterations. A Solver::next_iter that bails mid-iteration with Some(reason) does not increment this counter; see the executor module for the exact ordering.
Source§

fn increment_iter(&mut self)

Increment iter by one. Called by the executor after a successful Solver::next_iter.
Source§

fn param(&self) -> &V

Current iterate. Stable between Solver::next_iter calls; available after successful initialization, including iter 0. Some constructors supply it immediately, while an empty population such as PopulationProgress::empty must first be initialized.
Source§

fn cost(&self) -> F

Cost at the current param. Read more
Source§

fn cost_evals(&self) -> u64

Cumulative evaluation work under the state’s CountsMirror mapping. Every shipped shared state reports only raw cost-function calls. Custom states define their mapping through CountsMirror. Diverges from iter() whenever a single iteration evaluates the cost more than once (line searches, Nelder-Mead shrinks, etc.); this is what users actually budget against. Read more
Source§

fn best_param(&self) -> &V

Selected incumbent under this state’s best-tracking rule. Read more
Source§

fn best_cost(&self) -> F

Cost of the selected incumbent. This is the historical minimum for objective-ordered states, but can increase under constrained incumbent selection.
Source§

fn best_iter(&self) -> u64

Iteration recorded by the most recent incumbent update. Objective- ordered states record strict improvements; states that mirror a solver-selected incumbent may refresh this on every publication.
Source§

fn best_cost_evals(&self) -> u64

cost_evals at the publication boundary that recorded the incumbent. This need not be the precise evaluation that found the point.
Source§

fn update_best(&mut self)

Refresh the incumbent using this state’s selection rule. Most states retain strict objective improvements; population states can also consider exposed samples, and constrained states can mirror the solver’s selected incumbent. Read more
Source§

fn reset_best(&mut self)

Reset the best-so-far slots to their pre-init defaults (best_cost = +∞, all best counters zero). Read more
Source§

impl<V: PartialEq, F: PartialEq + Scalar> StructuralPartialEq for SelectedFirstOrderState<V, F>

Auto Trait Implementations§

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> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

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

Source§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

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

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.
Source§

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

Source§

fn vzip(self) -> V