Expand description
Restart functionality Checkpoint system for saving and restarting MECP calculations.
This module provides functionality to save the complete state of a MECP optimization calculation and restart from that state later. This is essential for:
- Long calculations: Save progress periodically
- Interrupted jobs: Restart from the last checkpoint
- Parameter testing: Resume with different settings
- Convergence recovery: Restart from near-converged geometries
§Checkpoint Format
Checkpoints are stored as JSON files containing:
- Step number: Current optimization step
- Geometry: Current molecular geometry
- Optimization history: Geometries, gradients, Hessians (for DIIS)
- Hessian matrix: Current approximate Hessian
- Configuration: Complete calculation settings
§Serialization Strategy
The checkpoint system uses serde for serialization. Since some types (DVector, DMatrix) from nalgebra don’t directly serialize, wrapper types are used:
SerializableGeometry: Converts DVector coords toVec<f64>SerializableOptimizationState: Converts collections of DVector/DMatrix to Vec
§Usage
Checkpoints are automatically created during optimization but can also be used manually:
use omecp::checkpoint::{Checkpoint, CheckpointLoad};
use omecp::geometry::Geometry;
use omecp::optimizer::OptimizationState;
use omecp::config::Config;
use nalgebra::{DMatrix, DVector};
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create test data
let elements = vec!["H".to_string()];
let coords = vec![0.0, 0.0, 0.0];
let geometry = Geometry::new(elements, coords);
let x_old = DVector::from_vec(vec![0.0, 0.0, 0.0]);
let hessian = DMatrix::identity(3, 3);
let opt_state = OptimizationState::new(5);
let config = Config::default();
// Save checkpoint
let checkpoint = Checkpoint::new(1, &geometry, &x_old, &hessian, &opt_state, &config);
checkpoint.save(Path::new("mecp.chk"))?;
// Load checkpoint
let loaded: CheckpointLoad = Checkpoint::load(Path::new("mecp.chk"))?;
println!("Loaded step: {}", loaded.step);
std::fs::remove_file("mecp.chk")?;
Ok(())
}§File Location
Checkpoint files are typically saved as mecp.chk or a user-specified name
in the running_dir/ directory for easy management.
Checkpoint system for restarting MECP optimizations.
This module provides functionality to save and restore optimization state including geometry, gradients, Hessian, and history for recovery.
Structs§
- Checkpoint
- Checkpoint structure for saving/restoring MECP calculations.
- Checkpoint
Load - Loaded checkpoint contents returned by
Checkpoint::load. - Serializable
Geometry - Serializable wrapper for Geometry.
- Serializable
Optimization State - Serializable wrapper for OptimizationState.
Functions§
- default_
version 🔒 - Default checkpoint version for backward compatibility.