Storage¶
storage
¶
Custom storage interface for MCMC sampling.
The custom interface is built in a way to enable storage of samples directly to the disk.
Classes:
| Name | Description |
|---|---|
MCMCStorage |
Abstract base class for storages |
NumpyStorage |
Simple in memory storage |
ZarrStorage |
Storage with a Zarr backend that saves samples to disk automatically |
ls_mcmc.storage.MCMCStorage
¶
ls_mcmc.storage.NumpyStorage
¶
Bases: MCMCStorage
In-memory storage using numpy arrays.
Methods:
| Name | Description |
|---|---|
store |
Store a new sample |
values |
return all stored samples |
flush |
Not intended to be used |
ls_mcmc.storage.ZarrStorage
¶
Bases: MCMCStorage
Disk-based storage using Zarr with chunking.
Methods:
| Name | Description |
|---|---|
store |
Store a new sample |
values |
return all stored samples |
flush |
flush samples to disk |
initialize_from_disk |
Initialize Zarr Storage from existing storage on the disk |
__init__
¶
__init__(save_directory: pathlib.Path, chunk_size: int, zarr_storage_group: zarr.Group | None = None, overwrite: bool = False) -> None
Initialize ZarrStorage with save directory and chunk size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
pathlib.Path
|
Path where the Zarr store will be created. |
required |
chunk_size
|
int
|
Number of samples to accumulate before writing to disk. Must be greater than zero. |
required |
zarr_storage_group
|
zarr.Group | None
|
If specified this zarr_storage_group is used instead of creating a new one. In this case save_directory can be set to None. |
None
|
overwrite
|
bool
|
Whether to overwrite the data at save_directory or not. Defaults to False. |
False
|
initialize_from_disk
classmethod
¶
Initializes the Zarr storage from an already existing Zarr storage on disk.
This can be used to either read the samples from the disk after a MCMC run or to restart a run and append the new samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_directory
|
pathlib.Path
|
Path where the Zarr store will be created. |
required |
chunk_size
|
int
|
Number of samples to accumulate before writing to disk. Must be greater than zero. |
1
|
store
¶
Add sample to ZarrStorage.