pub struct FileCheckpoint {
pub frequency: CheckpointingFrequency,
pub directory: PathBuf,
pub filename: PathBuf,
}
Expand description
Handles saving a checkpoint to disk as a binary file.
Fields§
§frequency: CheckpointingFrequency
Indicates how often a checkpoint is created
directory: PathBuf
Directory where the checkpoints are saved to
filename: PathBuf
Name of the checkpoint files
Implementations§
source§impl FileCheckpoint
impl FileCheckpoint
sourcepub fn new<N: AsRef<str>>(
directory: N,
name: N,
frequency: CheckpointingFrequency,
) -> Self
pub fn new<N: AsRef<str>>( directory: N, name: N, frequency: CheckpointingFrequency, ) -> Self
Create a new FileCheckpoint
instance
§Example
use argmin_checkpointing_file::{FileCheckpoint, CheckpointingFrequency};
let directory = "checkpoints";
let filename = "optimization";
// When passed to an `Executor`, this will save a checkpoint in the file
// `checkpoints/optimization.arg` in every iteration.
let checkpoint = FileCheckpoint::new(directory, filename, CheckpointingFrequency::Always);
Trait Implementations§
source§impl<S, I> Checkpoint<S, I> for FileCheckpoint
impl<S, I> Checkpoint<S, I> for FileCheckpoint
source§fn save(&self, solver: &S, state: &I) -> Result<(), Error>
fn save(&self, solver: &S, state: &I) -> Result<(), Error>
Writes checkpoint to disk.
If the directory does not exist already, it will be created. It uses bincode
to serialize
the data.
It will return an error if creating the directory or file or serialization failed.
§Example
use argmin_checkpointing_file::{FileCheckpoint, CheckpointingFrequency, Checkpoint};
checkpoint.save(&solver, &state);
source§fn load(&self) -> Result<Option<(S, I)>, Error>
fn load(&self) -> Result<Option<(S, I)>, Error>
Load a checkpoint from disk.
If there is no checkpoint on disk, it will return Ok(None)
.
Returns an error if opening the file or deserialization failed.
§Example
use argmin_checkpointing_file::{FileCheckpoint, CheckpointingFrequency, Checkpoint};
let (solver, state) = checkpoint.load()?.unwrap();
source§fn frequency(&self) -> CheckpointingFrequency
fn frequency(&self) -> CheckpointingFrequency
Returns the how often a checkpoint is to be saved.
Used internally by save_cond
.
source§impl Clone for FileCheckpoint
impl Clone for FileCheckpoint
source§fn clone(&self) -> FileCheckpoint
fn clone(&self) -> FileCheckpoint
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for FileCheckpoint
impl Debug for FileCheckpoint
source§impl Default for FileCheckpoint
impl Default for FileCheckpoint
source§fn default() -> FileCheckpoint
fn default() -> FileCheckpoint
Create a default FileCheckpoint
instance.
This will save the checkpoint in the file .checkpoints/checkpoint.arg
.
§Example
use argmin_checkpointing_file::FileCheckpoint;
let checkpoint = FileCheckpoint::default();
source§impl Hash for FileCheckpoint
impl Hash for FileCheckpoint
source§impl PartialEq for FileCheckpoint
impl PartialEq for FileCheckpoint
impl Eq for FileCheckpoint
impl StructuralPartialEq for FileCheckpoint
Auto Trait Implementations§
impl Freeze for FileCheckpoint
impl RefUnwindSafe for FileCheckpoint
impl Send for FileCheckpoint
impl Sync for FileCheckpoint
impl Unpin for FileCheckpoint
impl UnwindSafe for FileCheckpoint
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.