Skip to content

Commit 2247207

Browse files
authored
Merge pull request #386 from joshspeagle/resuming
Resuming of interrupted runs
2 parents a72c173 + 68cfa83 commit 2247207

File tree

15 files changed

+1646
-1056
lines changed

15 files changed

+1646
-1056
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ All notable changes to dynesty will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
*IMPORTANT* This release includes some major refactoring of class structure in dynesty in to implement the check-pointing. While we haven't seen any breakage in our tests, it is possible that some of more-unusual workflows may be affected. Please submit a bug report on github if you see anything that doesn't look correct. Also, while every effort was made that checkpointing works correctly, it is possible that some corner-cases have been missed. Please report if you see any issues.
89

910
### Added
11+
- The nested samplers can now be saved and restored from the file using .save()
12+
.restore() interface
13+
- When sampling is performed using run_nested() it is now possible to perform checkpoints at regular intervals, allowing you then resume sampling if it was interrupted
14+
1015
### Fixed
1116
- Sampler.n_effective is no longer unnecessarily computed when sampling with
1217
an infinite limit on n_effective.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[![Build Status](https://github.com/joshspeagle/dynesty/workflows/Dynesty/badge.svg)](https://github.com/joshspeagle/dynesty/actions)
22
[![Documentation Status](https://readthedocs.org/projects/dynesty/badge/?version=latest)](https://dynesty.readthedocs.io/en/latest/?badge=latest)
3-
[![Coverage Status](https://coveralls.io/repos/github/joshspeagle/dynesty/badge.svg?branch=master)](https://coveralls.io/github/joshspeagle/dynesty?branch=master)
3+
[![Coverage Status](https://coveralls.io/repos/github/joshspeagle/dynesty/badge.svg?branch=master)](https://coveralls.io/github/joshspeagle/dynesty?branch=master)[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.6609296.svg)](https://doi.org/10.5281/zenodo.6609296)
4+
45

56
dynesty
67
=======

RELEASE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ This is an internal memo for things that need to be done for the release
33
Essential steps (order is important):
44

55
* update the changelog.md and changelog in the docs
6-
* change the internal version number ( py/dynesty/__init__.py )
6+
* change the internal version number ( py/dynesty/_version.py )
77
* git tag
88
* release on pypi and github
99

docs/source/dynamic.rst

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ using the :meth:`~dynesty.dynamicsampler.DynamicSampler.run_nested` function::
339339

340340
dsampler.run_nested()
341341

342-
or externally as a generator::
342+
or externally as a generator (not recommended)::
343343

344344
from dynesty.dynamicsampler import stopping_function, weight_function
345345

@@ -442,6 +442,41 @@ could be added to the previous set of samples using::
442442

443443
dsampler.add_batch(nlive=250, maxiter=1000)
444444

445+
Adding more batches
446+
-------------------
447+
448+
To add more points to the posterior you should be using the :meth:`~dynesty.dynamicsampler.DynamicSampler.add_batch` function. This function has an important parameter that affects how those samples will be generated::
449+
450+
dsampler.add_batch(mode='auto')
451+
dsampler.add_batch(mode='full')
452+
dsampler.add_batch(mode='manual', logl_bounds=[-4,1])
453+
454+
The default mode auto will use the weight function described previously to find the best log-likelihood interval to place a batch.
455+
The full mode will place add a batch that covers the full posterior, i.e. this is equivalent to adding another static nested run to what you have already.
456+
Finally the manual mode allows you to add a batch that covers a certain specific log-likelihood range.
457+
458+
It is important to understand that there multiple reasons to add batches to a dynamic nested run. One is just to reduce the noise in the posterior/increase the number of effective posterior samples, but another reason is that if you have a very multi-modal problem and you are worried whether you fully sample all the modes, you can do a dynamic run and then keep adding batches till you are satisfied with the result.
459+
460+
461+
Checkpointing with the dynamic sampler
462+
--------------------------------------
463+
464+
Similarly to static nested sampler, the dynamic sampler supports periodic check-pointing into a file if you are sampling using run_nested() interface::
465+
466+
# initialize our sampler
467+
sampler = DynamicNestedSampler(loglike, ptform, ndim, nlive=1000, pool=pool)
468+
# run the sampler with checkpointing
469+
sampler.run_nested(checkpoint_file='dynesty.save')
470+
471+
And to restore::
472+
473+
# initialize the sampler
474+
sampler = NestedSampler.restore('dynesty.save', pool =mypool)
475+
# resume
476+
sampler.run_nested(resume=True)
477+
478+
479+
445480
Dynamic vs Static
446481
-----------------
447482

docs/source/quickstart.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ users an option as to whether they want to parallelize `dynesty` *during*
453453
runtime (using a user-provided `pool`) or *after* runtime (by merging
454454
the runs together).
455455

456+
456457
Running Internally
457458
------------------
458459

@@ -520,6 +521,35 @@ to add new samples based on where they left off. This is as easy as::
520521
sampler.run_nested(dlogz=0.01)
521522
res3 = sampler.results
522523

524+
Checkpointing
525+
--------------
526+
527+
While running the sampler using run_nested() interface it is possible to check-point (or save) the state of the sampler into a file at regular intervals. This file can then be used to restart/resume the sampling::
528+
529+
# initialize our sampler
530+
sampler = NestedSampler(loglike, ptform, ndim, nlive=1000)
531+
# run the sampler with checkpointing
532+
sampler.run_nested(checkpoint_file='dynesty.save')
533+
534+
535+
You can then restore it now and resume sampling::
536+
537+
# restore our sampler
538+
sampler = NestedSampler.restore('dynesty.save')
539+
# resume
540+
sampler.run_nested(resume=True)
541+
542+
543+
If you used the pool in the sampler and you want to use the pool after restoring, you need to specify it when restoring::
544+
545+
mypool = multiprocessing.Pool(6)
546+
# restore the sampler
547+
sampler = NestedSampler.restore('dynesty.save', pool =mypool)
548+
# resume
549+
sampler.run_nested(resume=True)
550+
551+
The checkpointing may be helpful if you are running dynesty on HPC with a queue system that has a limit on a wall-time that your jobs can run.
552+
523553
Running Externally
524554
------------------
525555

py/dynesty/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
from . import bounding
1111
from . import utils
1212

13-
__version__ = "1.2.3"
13+
from ._version import __version__

py/dynesty/_version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "1.2.3"

0 commit comments

Comments
 (0)