SFI.inference.serialization module¶
Save / load helpers for inference results.
Two complementary routes:
Lightweight (save_results / load_results): Saves the scalar + array summary produced by
report_dict()to a NumPy.npzarchive with a JSON sidecar. Useful for archival and cross-language interop. Does not preserve the callable model.Equinox model (save / load on
InferenceResultSF): Serializes the full JAX pytree (leaf arrays + metadata) so the fitted model can be reloaded and called for prediction.
- SFI.inference.serialization.load_model(path, template)[source]¶
Reload an
InferenceResultSFfrom files written bysave_model().- Parameters:
path (str or Path) – Base path (without extension).
template (InferenceResultSF) – A skeleton instance providing the PSF / Basis structure. Typically built from the same PSF / Basis used at training time:
template = InferenceResultSF(SF(psf, dummy_params)).
- Return type:
- SFI.inference.serialization.load_results(path)[source]¶
Reload a dict saved by
save_results().- Parameters:
path (str or Path) – Base path (without extension).
- Returns:
The merged dictionary of arrays and scalars.
- Return type:
dict
- SFI.inference.serialization.save_model(result_sf, path)[source]¶
Serialize an
InferenceResultSF(params array + metadata).Creates
<path>.params.npz(the fitted parameter arrays) and<path>.meta.json(param_cov + non-array metadata).The PSF/Basis structure is not saved — it must be supplied again as a
templatewhen callingload_model().- Parameters:
result_sf (InferenceResultSF) – The fitted model to save.
path (str or Path) – Base path (without extension).
- Returns:
The base path used.
- Return type:
Path
- SFI.inference.serialization.save_results(inferer, path)[source]¶
Save
inferer.report_dict()to<path>.npz+<path>.json.- Parameters:
inferer (BaseLangevinInference) – Any inference object that exposes
report_dict().path (str or Path) – Base path (without extension). Two files are created:
<path>.npzfor arrays,<path>.jsonfor scalars/metadata.
- Returns:
The base path used.
- Return type:
Path