SFI.inference.serialization module

Save / load helpers for inference results.

Two complementary routes:

  1. Lightweight (save_results / load_results): Saves the scalar + array summary produced by report_dict() to a NumPy .npz archive with a JSON sidecar. Useful for archival and cross-language interop. Does not preserve the callable model.

  2. 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 InferenceResultSF from files written by save_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:

InferenceResultSF

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 template when calling load_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>.npz for arrays, <path>.json for scalars/metadata.

Returns:

The base path used.

Return type:

Path