Struct argmin::core::checkpointing::FileCheckpoint
source · [−]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
sourceimpl 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::core::checkpointing::{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
sourceimpl<S, I> Checkpoint<S, I> for FileCheckpoint where
S: SerializeAlias + DeserializeOwnedAlias,
I: SerializeAlias + DeserializeOwnedAlias,
impl<S, I> Checkpoint<S, I> for FileCheckpoint where
S: SerializeAlias + DeserializeOwnedAlias,
I: SerializeAlias + DeserializeOwnedAlias,
sourcefn 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::core::checkpointing::{FileCheckpoint, CheckpointingFrequency, Checkpoint};
checkpoint.save(&solver, &state);
sourcefn 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::core::checkpointing::{FileCheckpoint, CheckpointingFrequency, Checkpoint};
let (solver, state) = checkpoint.load()?.unwrap();
sourcefn frequency(&self) -> CheckpointingFrequency
fn frequency(&self) -> CheckpointingFrequency
Returns the how often a checkpoint is to be saved.
Used internally by save_cond
.
sourceimpl Clone for FileCheckpoint
impl Clone for FileCheckpoint
sourcefn clone(&self) -> FileCheckpoint
fn clone(&self) -> FileCheckpoint
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for FileCheckpoint
impl Debug for FileCheckpoint
sourceimpl Default for FileCheckpoint
impl Default for FileCheckpoint
sourcefn default() -> FileCheckpoint
fn default() -> FileCheckpoint
Create a default FileCheckpoint
instance.
This will save the checkpoint in the file .checkpoints/checkpoint.arg
.
Example
use argmin::core::checkpointing::FileCheckpoint;
let checkpoint = FileCheckpoint::default();
sourceimpl Hash for FileCheckpoint
impl Hash for FileCheckpoint
sourceimpl PartialEq<FileCheckpoint> for FileCheckpoint
impl PartialEq<FileCheckpoint> for FileCheckpoint
sourcefn eq(&self, other: &FileCheckpoint) -> bool
fn eq(&self, other: &FileCheckpoint) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &FileCheckpoint) -> bool
fn ne(&self, other: &FileCheckpoint) -> bool
This method tests for !=
.
impl Eq for FileCheckpoint
impl StructuralEq for FileCheckpoint
impl StructuralPartialEq for FileCheckpoint
Auto Trait Implementations
impl RefUnwindSafe for FileCheckpoint
impl Send for FileCheckpoint
impl Sync for FileCheckpoint
impl Unpin for FileCheckpoint
impl UnwindSafe for FileCheckpoint
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more