Skip to main content

CheckpointManager

Struct CheckpointManager 

Source
pub struct CheckpointManager {
    pub base_dir: String,
    pub max_checkpoints: usize,
    /* private fields */
}
Expand description

Manages a rolling window of simulation checkpoints stored in memory.

In a real deployment base_dir would name a directory on disk; here the data is kept in an internal HashMap so the module has no I/O dependency.

Fields§

§base_dir: String

Base directory for checkpoint files (informational, not used for in-memory store).

§max_checkpoints: usize

Maximum number of checkpoints to retain.

Implementations§

Source§

impl CheckpointManager

Source

pub fn new(base_dir: impl Into<String>, max_checkpoints: usize) -> Self

Create a new manager for base_dir retaining at most max_checkpoints.

Source

pub fn save_checkpoint(&mut self, step: usize, data: &[f64]) -> String

Save a checkpoint for step, returning the logical path string.

Source

pub fn list_checkpoints(&self) -> Vec<usize>

Return all checkpoint step numbers in ascending order.

Source

pub fn load_checkpoint(&self, step: usize) -> Option<Vec<f64>>

Load the data for step, or None if no such checkpoint exists.

Source

pub fn cleanup_old(&mut self)

Remove old checkpoints so that at most max_checkpoints are kept.

Trait Implementations§

Source§

impl Debug for CheckpointManager

Source§

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

Formats the value using the given formatter. 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> 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

Source§

type Output = T

Should always be Self
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, 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.