Skip to main content

Crate phasesmith_persistence

Crate phasesmith_persistence 

Source
Expand description

Canonical, Python-free project persistence and stable summary reporting.

Project bundles are directories containing manifest.json plus a numeric arrays.npz. Wire records are explicit and versioned; live domain types do not derive serialization directly. Applications normally use this crate through phasesmith::persistence.

§Bundle contract

  • manifest.json contains the format version, explicit wire records, array descriptors, shapes, dtypes, and hashes.
  • arrays.npz contains typed little-endian numeric arrays.
  • loads validate the exact member set, hashes, shapes, dtypes, finiteness, cross-record identities, and caller-selected ProjectReadLimits.
  • overwrite replaces only the two library-owned files and preserves unrelated application content in the directory.

§Saving and loading

use std::collections::BTreeMap;
use phasesmith_model::{ProjectRecord, RecordId};
use phasesmith_persistence::{
    ProjectReadLimits, ProjectSaveOptions, load_project, save_project,
};

let project = ProjectRecord {
    project_id: RecordId::new("example")?,
    revision: 0,
    name: "Example".into(),
    histograms: Vec::new(),
    tof_histograms: Vec::new(),
    phases: Vec::new(),
    metadata: BTreeMap::new(),
};
save_project("example.psproj", &project, ProjectSaveOptions::default())?;
let restored = load_project("example.psproj", ProjectReadLimits::default())?;
assert_eq!(restored.project_id, project.project_id);

Use save_rietveld_project / load_rietveld_project or save_tof_lebail_project / load_tof_lebail_project when the bundle must retain runnable single-histogram analyses. Joint TOF geometry state uses save_tof_multibank_geometry_project and load_tof_multibank_geometry_project. Structural multi-bank TOF state uses save_structural_tof_multibank_project and load_structural_tof_multibank_project. TOF histograms keep microseconds separate from constant-wavelength degree coordinates. Reporting functions produce stable JSON summaries without exposing internal wire records.

Structs§

HistogramSummary
One histogram entry in a project summary.
PhaseSummary
One phase entry in a project summary.
ProjectReadLimits
Resource limits applied before allocating project records and arrays.
ProjectReportSaveOptions
Project-summary report write behavior.
ProjectSaveOptions
Native project save behavior.
ProjectSummaryReport
Versioned, display-safe project summary without bulk numerical arrays.

Enums§

PersistenceError
Structured native persistence failure.

Constants§

PROJECT_ARRAYS_NAME
Canonical NumPy archive filename within a project directory.
PROJECT_FORMAT_VERSION
Current native project bundle wire version.
PROJECT_MANIFEST_NAME
Canonical manifest filename within a project directory.

Functions§

load_project
Load and fully validate one canonical native project directory.
load_rietveld_project
Load and validate one project plus all native Rietveld analyses.
load_structural_tof_multibank_project
Load and validate one project plus all resumable structural multi-bank TOF analyses.
load_tof_lebail_project
Load and validate one project plus all resumable fixed-instrument TOF Le Bail analyses.
load_tof_multibank_geometry_project
Load and validate one project plus all resumable joint multi-bank TOF analyses.
project_summary_json
Serialize one validated summary to deterministic pretty JSON.
save_project
Save one validated native project as canonical JSON plus NPZ.
save_rietveld_project
Save one validated project and all runnable native Rietveld analyses.
save_structural_tof_multibank_project
Save one validated project and all resumable structural multi-bank TOF analyses.
save_tof_lebail_project
Save one validated project and all resumable fixed-instrument TOF Le Bail analyses.
save_tof_multibank_geometry_project
Save one validated project and all resumable joint multi-bank TOF analyses.
write_project_summary_json
Write one validated project summary as JSON.
write_project_summary_json_with_options
Write one validated project summary with an explicit overwrite policy.