Skip to main content

ExperimentStore

Struct ExperimentStore 

Source
pub struct ExperimentStore { /* private fields */ }
Expand description

In-memory store for experiment tracking data.

§Design

The store uses hash maps for O(1) lookups by ID, and stores metrics in a vector that can be filtered and sorted for time-series queries.

§Time-Series Optimization

The get_metrics_for_run function returns metrics ordered by step, enabling efficient time-series visualization and analysis.

Implementations§

Source§

impl ExperimentStore

Source

pub fn new() -> Self

Create a new empty experiment store.

Source

pub fn is_empty(&self) -> bool

Check if the store is empty (no experiments, runs, or metrics).

Source

pub fn experiment_count(&self) -> usize

Get the number of experiments in the store.

Source

pub fn run_count(&self) -> usize

Get the number of runs in the store.

Source

pub fn metric_count(&self) -> usize

Get the number of metrics in the store.

Source

pub fn add_experiment(&mut self, experiment: ExperimentRecord)

Add an experiment to the store.

Source

pub fn get_experiment(&self, experiment_id: &str) -> Option<&ExperimentRecord>

Get an experiment by ID.

Source

pub fn add_run(&mut self, run: RunRecord)

Add a run to the store.

Source

pub fn get_run(&self, run_id: &str) -> Option<&RunRecord>

Get a run by ID.

Source

pub fn get_runs_for_experiment(&self, experiment_id: &str) -> Vec<&RunRecord>

Get all runs for an experiment.

Source

pub fn add_metric(&mut self, metric: MetricRecord)

Add a metric to the store.

Source

pub fn get_metrics_for_run(&self, run_id: &str, key: &str) -> Vec<MetricRecord>

Get metrics for a specific run and key, ordered by step.

This is the primary query function for time-series metric data.

§Arguments
  • run_id - The ID of the run to query
  • key - The metric key/name to filter by
§Returns

A vector of metrics matching the run_id and key, sorted by step in ascending order.

§Example
use trueno_db::experiment::{ExperimentStore, MetricRecord};

let mut store = ExperimentStore::new();

// Log some training metrics
for step in 0..100 {
    let loss = 1.0 / (step as f64 + 1.0);
    store.add_metric(MetricRecord::new("run-001", "loss", step, loss));
}

// Query the loss curve
let loss_metrics = store.get_metrics_for_run("run-001", "loss");
assert_eq!(loss_metrics.len(), 100);

Trait Implementations§

Source§

impl Debug for ExperimentStore

Source§

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

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

impl Default for ExperimentStore

Source§

fn default() -> ExperimentStore

Returns the “default value” for a type. Read more

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

Source§

fn downcast(&self) -> &T

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

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,