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();