Skip to main content

TrialContext

Struct TrialContext 

Source
pub struct TrialContext<'a> { /* private fields */ }
Expand description

The handle passed into the user’s objective closure.

This is where define-by-run happens: the search space is discovered by calling suggest_* methods here, not declared up front. Each call (1) asks the active Sampler for a value given the study history and the distribution, then (2) records the (name, distribution, value) on the trial. Recording after asking keeps the trial’s history accurate for the storage, pruning, and importance phases that depend on it.

The sampler is held behind a shared Mutex so the exact same context type serves both sequential and parallel execution; under sequential runs the lock is uncontended.

Implementations§

Source§

impl<'a> TrialContext<'a>

Source

pub fn number(&self) -> usize

This trial’s number within the study.

Source

pub fn suggest_float(&mut self, name: &str, low: f64, high: f64) -> f64

Suggest a continuous value uniformly over [low, high].

Source

pub fn suggest_loguniform(&mut self, name: &str, low: f64, high: f64) -> f64

Suggest a continuous value log-uniformly over [low, high] (both must be > 0). Good for scale parameters like learning rates.

Source

pub fn suggest_int(&mut self, name: &str, low: i64, high: i64) -> i64

Suggest an integer uniformly over the inclusive range [low, high].

Source

pub fn suggest_categorical(&mut self, name: &str, choices: &[&str]) -> String

Suggest one of choices, returning the chosen label.

Source

pub fn report(&mut self, step: usize, value: f64)

Report an intermediate objective value at step (e.g. per-epoch validation score). Consumed by pruners via Self::should_prune.

Source

pub fn should_prune(&self) -> bool

Ask the active pruner whether this trial should stop early, based on the intermediate values reported so far versus the rest of the study.

Source

pub fn study_state(&self) -> &StudyState

Read-only access to the study snapshot this trial sees.

Trait Implementations§

Source§

impl Suggest for TrialContext<'_>

Source§

fn suggest_float(&mut self, name: &str, low: f64, high: f64) -> f64

Suggest a continuous value uniformly over [low, high].
Source§

fn suggest_loguniform(&mut self, name: &str, low: f64, high: f64) -> f64

Suggest a continuous value log-uniformly over [low, high].
Source§

fn suggest_int(&mut self, name: &str, low: i64, high: i64) -> i64

Suggest an integer uniformly over the inclusive range [low, high].
Source§

fn suggest_categorical(&mut self, name: &str, choices: &[&str]) -> String

Suggest one of choices, returning the chosen label.
Source§

fn report(&mut self, step: usize, value: f64)

Report an intermediate objective value at step, for pruners.
Source§

fn should_prune(&mut self) -> bool

Ask whether this trial should stop early given what it has reported. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for TrialContext<'a>

§

impl<'a> !UnwindSafe for TrialContext<'a>

§

impl<'a> Freeze for TrialContext<'a>

§

impl<'a> Send for TrialContext<'a>

§

impl<'a> Sync for TrialContext<'a>

§

impl<'a> Unpin for TrialContext<'a>

§

impl<'a> UnsafeUnpin for TrialContext<'a>

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

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.