Struct StopHandle
pub struct StopHandle(/* private fields */);Expand description
Asks a Study handle to start no more trials.
Study::stop_handle returns a clone
that shares the handle’s flag. Once stop is called,
that handle’s next ask returns Ok(None) —
before it creates a trial, resumes a paused one, or claims a replacement —
so optimize ends normally after the
trials already running finish. No trial is created and failed to signal the
stop, unlike ending a study by returning
Error::SpaceExhausted from a
sampler.
The flag belongs to one handle and is not persisted: another handle on the
same study, or a later load, starts
unstopped. A stop is final for the handle; it cannot be cleared.
use atune_core::clock::ManualClock;
use atune_core::space::Scale;
use atune_core::study::{Budget, Study, StudyConfig};
use std::sync::Arc;
let study = Study::builder()
.clock(Arc::new(ManualClock::new(0)))
.budget(Budget::new_with_trials(100))
.create(StudyConfig::new("stop-early"))?;
let stop = study.stop_handle();
study.optimize(move |ctx| {
let x = ctx.suggest_f64("x", -1.0..=1.0, Scale::Linear)?;
if ctx.meta().number.get() == 4 {
stop.stop();
}
Ok(x.into())
})?;
assert_eq!(study.trial_count()?, 5);Implementations§
§impl StopHandle
impl StopHandle
pub fn new() -> Self
pub fn new() -> Self
A fresh, unstopped flag.
pub fn stop(&self)
pub fn stop(&self)
Stops the handle: its next ask starts no work.
pub fn is_stopped(&self) -> bool
pub fn is_stopped(&self) -> bool
Whether stop has been called.
Trait Implementations§
§impl Clone for StopHandle
impl Clone for StopHandle
§fn clone(&self) -> StopHandle
fn clone(&self) -> StopHandle
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read more§impl Debug for StopHandle
impl Debug for StopHandle
§impl Default for StopHandle
impl Default for StopHandle
§fn default() -> StopHandle
fn default() -> StopHandle
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for StopHandle
impl RefUnwindSafe for StopHandle
impl Send for StopHandle
impl Sync for StopHandle
impl Unpin for StopHandle
impl UnsafeUnpin for StopHandle
impl UnwindSafe for StopHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more