jexplore.backends.default#
Ths module defines the default version of a Jexplore backend for storing data in memory and on disk.
Attributes#
Default backend config parameters |
|
logger instance |
Classes#
Default backend dumping samples on disk per epoch. |
Module Contents#
- DEFAULTBKND_CONFIG#
Default backend config parameters
- logger#
logger instance
- class DefaultBackend[Tepoch: jexplore.sampling.Epoch](burn=0, **config)[source]#
Default backend dumping samples on disk per epoch.
- Parameters:
burn (int) – number of samples to burn (these will not be registered by the backend)
**config (dict) – backend configuration options.
- burn: int#
burned samples
- ingest(epoch, eind=-1)[source]#
loads and store one epoch in the backend.
- Parameters:
epoch (Tepoch | dict | str) – the epoch to be loaded. Can be an epoch
- Return type:
Self
instance, a dictionnary or the path to a backend file.
- Parameters:
eind – if epoch is the path to a backend file this
epoch (Tepoch | dict | str)
- Return type:
Self
is the index of the epoch. Same syntax that
jexplore.backend.default.DefaultBackend.read_epoch- Returns:
the backend object.
- Parameters:
epoch (Tepoch | dict | str)
- Return type:
Self
- ingest_dict(epoch, copy=True)[source]#
Loads and store one epoch dictionnary in the backend.
- Parameters:
epoch (dict) – the epoch dictionnary
copy (bool) – if true the dictionary is copied before storing
- Returns:
the backend object
- Return type:
Self
- get(ind=-1)[source]#
Loads an epoch from registry.
- Parameters:
ind (int) – index of the epoch in the registry.
- Returns:
epoch data as a dictionnary.
- Return type:
dict
- set_burn(burn)[source]#
Sets the number of samples to be burned and removes stored samples if necessary.
- Parameters:
burn (int) – number of burned samples
- Return type:
None
- update()[source]#
This implements the storing logic of this backend. It parses the registry of the ingested epochs and implements storing policies according to the configuration paremeters.
- Return type:
None
- static flatten_samples(samples)[source]#
Flatten a (chain, dim, nsamples) chain into a (n. all samples, dim) format.
- Parameters:
samples (dict[str, numpy.ndarray] | None) – the samples dictionnary
- Returns:
flatten samples dictionnary
- Return type:
dict[str, numpy.ndarray] | None
- get_samples(burn=0, thin=1, pars=None, mask=Ellipsis, flatten=False)[source]#
Get the samples from the backend.
- Parameters:
burn (int) – number of initial samples to discart. This is added on top of the backend instance burn parameter.
thin (int) – thinning factor.
pars (list[str] | None) – list of names of the sample parameters to be returned. Default: only “p”.
mask (numpy.ndarray | types.EllipsisType) – mask (boolean mask or list of index) for the chains to be retrieved.
flatten (bool) – returns flattened samples with shape (n. samples, dim).
- Returns:
a dictionnary which keys are the parameters names and values the returned chains. None if no samples could be retrieved.
- Return type:
dict[str, numpy.ndarray] | None
- get_stats(epochs=None, fname=None)[source]#
Returns a dictionnary of epoch stats. Optionnally save the dictionnary to a h5 file.
- Parameters:
epochs (list[int] | None) – list of epochs. If None (default) all non burned epochs are considered.
fname (str | None) – if not None, the epochs stats are saved to file.
- Returns:
the stats of the selected epochs.
- Return type:
dict[str, dict[str, numpy.ndarray]]
- classmethod read_epoch(fn, iepoch=-1)[source]#
Loads an epoch from a backend h5 file.
- Parameters:
fn (str) – file name
iepoch (int) – index of the epoch in the file. Note that this is the overall index in the backend that created the file. If it is a negative integer -i it takes the -ith epoch from the last (ordered by their epoch index). E.g if iepoch is -1 it takes the last epoch.
- Returns:
epoch data as a dictionnary.
- Return type:
dict
- load(iepoch=-1, eclass=None, pars=None)[source]#
Loads an epoch from a backend h5 file.
- Parameters:
iepoch (int) – index of the epoch in the file. Note that this is the overall index in the backend that created the file. If it is a negative integer -i it takes the -ith epoch from the last (ordered by their epoch index). E.g if iepoch is -1 it takes the last epoch.
eclass (type[Tepoch] | None) – epoch class.
pars (list[str] | None) – samples parameters to be loaded. Default: all.
- Returns:
the loaded epoch.
- Return type:
Tepoch
- static load_epoch(fn, iepoch=-1, eclass=None, pars=None)[source]#
Loads an epoch from a backend h5 file.
- Parameters:
fn (str) – file name
iepoch (int) – index of the epoch in the file. Note that this is the overall index in the backend that created the file. If it is a negative integer -i it takes the -ith epoch from the last (ordered by their epoch index). E.g if iepoch is -1 it takes the last epoch.
eclass (type[Tepoch] | None) – epoch class.
pars (list[str] | None) – samples parameters to be loaded. Default: all.
- Returns:
the loaded epoch.
- Return type:
Tepoch