Skip to content

Commit b793f2f

Browse files
committed
Added a reset method to clear optimizer and sampler states
1 parent 5e2f995 commit b793f2f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

exoiris/exoiris.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,29 @@ def sample(self, niter: int = 500, thin: int = 10, repeats: int = 1, pool=None,
660660
self._tsa.sample_mcmc(niter=niter, thin=thin, repeats=repeats, pool=pool, lnpost=lnpost,
661661
vectorize=(pool is None), leave=leave, save=save, use_tqdm=use_tqdm)
662662

663+
def reset(self, optimizer: bool = True, sampler: bool = True) -> None:
664+
"""Reset the internal states of the optimizer and sampler.
665+
666+
Parameters
667+
----------
668+
optimizer
669+
If True, clears all the internal attributes associated with the optimizer.
670+
sampler
671+
If True, clears all the internal attributes associated with the sampler.
672+
673+
Returns
674+
-------
675+
None
676+
"""
677+
if optimizer:
678+
self._tsa.de = None
679+
self._tsa._de_population = None
680+
self._tsa._de_imin = None
681+
682+
if sampler:
683+
self._tsa.sampler = None
684+
self._tsa._mc_chains = None
685+
663686
def reset_sampler(self) -> None:
664687
"""Reset the MCMC sampler
665688

0 commit comments

Comments
 (0)