Skip to content

Commit d61648b

Browse files
committed
moved to Sampler class from Core
1 parent a472411 commit d61648b

4 files changed

Lines changed: 136 additions & 104 deletions

File tree

pixi.lock

Lines changed: 12 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/easyreflectometry/analysis/bayesian.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,8 +1332,9 @@ def load_posterior(path: str, skip: int = 0) -> 'PosteriorResults':
13321332
"""Reload a trace saved by :func:`save_posterior` into a
13331333
:class:`PosteriorResults`.
13341334
1335-
The returned object's ``sampler_state`` can be fed back into
1336-
``MultiFitter.mcmc_sample(..., resume_state=...)`` to extend the chain.
1335+
The returned object's ``sampler_state`` can be fed back into the core
1336+
``Sampler`` (via ``Sampler.load_state(...)`` / ``Sampler.extend(...)``)
1337+
to extend the chain.
13371338
13381339
:param path: File path prefix used in :func:`save_posterior`.
13391340
:type path: str

src/easyreflectometry/fitting.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import scipp as sc
1111
from easyscience.fitting import AvailableMinimizers
1212
from easyscience.fitting import FitResults
13+
from easyscience.fitting import Sampler
1314
from easyscience.fitting.multi_fitter import MultiFitter as EasyScienceMultiFitter
1415

1516
from easyreflectometry.data import DataSet1D
@@ -419,14 +420,22 @@ def mcmc_sample(
419420
y.append(y_eff)
420421
dy.append(weights)
421422

422-
# Delegate the actual BUMPS/DREAM sampling to the core MultiFitter
423+
# Delegate the actual BUMPS/DREAM sampling to the core ``Sampler``.
424+
# The core API moved from ``MultiFitter.mcmc_sample()`` to a dedicated
425+
# ``Sampler`` class: construct it with the configured fitter and the
426+
# bound data, then call ``sample()``. ``Sampler`` handles the
427+
# multi-dataset reshaping internally.
423428
sampler_kwargs = {}
424429
if initializer is not None:
425430
sampler_kwargs['init'] = initializer
426-
return self.easy_science_multi_fitter.mcmc_sample(
431+
432+
sampler = Sampler(
433+
self.easy_science_multi_fitter,
427434
x=x,
428435
y=y,
429436
weights=dy,
437+
)
438+
results = sampler.sample(
430439
samples=samples,
431440
burn=burn,
432441
thin=thin,
@@ -435,6 +444,12 @@ def mcmc_sample(
435444
progress_callback=progress_callback,
436445
abort_test=abort_test,
437446
)
447+
return {
448+
'draws': results.draws,
449+
'param_names': results.param_names,
450+
'state': results.state,
451+
'logp': results.logp,
452+
}
438453

439454
@property
440455
def chi2(self) -> float | None:

0 commit comments

Comments
 (0)