Skip to content

Pool improvements#506

Merged
segasai merged 10 commits into
masterfrom
pool_branch
May 7, 2026
Merged

Pool improvements#506
segasai merged 10 commits into
masterfrom
pool_branch

Conversation

@segasai
Copy link
Copy Markdown
Collaborator

@segasai segasai commented May 5, 2026

  • When restoring from a checkpoint, I try to set the queue_size based on the current pool size.
  • Also improve autodetection of the pool size, as the multiprocessing.Pool supports _processes keyword
  • Use chunksize=1 with dynesty's pool

@coveralls
Copy link
Copy Markdown

coveralls commented May 5, 2026

Coverage Report for CI Build 25501343432

Coverage increased (+0.04%) to 91.962%

Details

  • Coverage increased (+0.04%) from the base build.
  • Patch coverage: 5 uncovered changes across 1 file (22 of 27 lines covered, 81.48%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
py/dynesty/utils.py 25 20 80.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 4093
Covered Lines: 3764
Line Coverage: 91.96%
Coverage Strength: 0.92 hits per line

💛 - Coveralls

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves how dynesty interacts with multiprocessing pools by centralizing pool/queue_size parsing, enhancing queue_size handling during checkpoint restore, and adjusting mapping behavior to better handle uneven task durations.

Changes:

  • Move and extend pool/queue_size parsing into a shared helper that can auto-detect pool size via pool._processes or pool.size.
  • Update checkpoint restore to reconfigure mapper/pool and set queue_size on restored samplers.
  • Update tests/docs/changelog and set chunksize=1 for dynesty.pool.Pool.map.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/test_resume.py Adds a resume test exercising restore behavior when pool size differs.
tests/test_pool.py Expands sampler coverage and adds a queue_size (specified vs auto) test.
py/dynesty/utils.py Adds shared _parse_pool_queue and updates restore logic to set queue_size on restored samplers.
py/dynesty/pool.py Forces chunksize=1 for the dynesty pool wrapper’s map.
py/dynesty/dynesty.py Removes local _parse_pool_queue and imports the shared implementation.
docs/source/quickstart.rst Adds guidance about restoring with different CPU counts/pool sizes.
docs/source/faq.rst Updates pool/queue_size guidance for variable-duration likelihoods.
CHANGELOG.md Documents the pool/restore/chunksize changes.
Comments suppressed due to low confidence (1)

tests/test_pool.py:245

  • This test creates a multiprocessing pool but doesn't call terminator(pool) afterwards. The rest of this file explicitly calls terminator(pool) even inside context managers due to the coveragepy cleanup issue noted above; skipping it here can reintroduce hanging/coverage flakiness. Consider calling terminator(pool) after run_nested for consistency.
    ctx = mp.get_context('spawn')
    with ctx.Pool(2) as pool:
        sampler = dynesty.NestedSampler(loglike_gau,
                                        prior_transform_gau,
                                        ndim,
                                        nlive=nlive,
                                        sample='rslice',
                                        pool=pool,
                                        queue_size=queue_size,
                                        rstate=rstate)
        sampler.run_nested(print_progress=printing, dlogz=10)


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread py/dynesty/utils.py
Comment on lines +2159 to +2161
if queue_size_new != queue_size_old and queue_size_old != 1:
warnings.warn(
f'Restoring the sampler with queue_size {queue_size_old}')
Comment thread py/dynesty/utils.py Outdated
Comment on lines +2243 to +2244
"`pool.size` or pool._processes has not been provided. "
"Please `define `pool.size` or specify `queue_size` "
Comment on lines +657 to +658
You should be careful when restoring the sampler on machine with different number of CPUs when using a pool.
We will still use the original queue_size unless it was 1 before.
Comment thread docs/source/faq.rst
**How to decide on the number of processes in a pool and how to set queue_size**

Assuming that you decided on the number of live-points K that you want to use and that the likelihood evaluation is not very quick, you should use as many processes as you can up to around K. The queue_size should be equal the number of processes. If you are using the the number of processes that M is smaller than K, you may want to use :math:`M=K//2` or :math:`M=K//3` i.e integer fractions. So if you are using 1024 live-points all powers of two up to 1024 would be good choice for the number of processes.
Assuming that you decided on the number of live-points K that you want to use and that the likelihood evaluation is not very quick, you should use as many processes as you can up to around K. The queue_size should be equal the number of processes. If you are using the the number of processes that M is smaller than K, you may want to use :math:`M=K//2` or :math:`M=K//3` i.e integer fractions. So if you are using 1024 live-points all powers of two up to 1024 would be good choice for the number of processes. If you have likelihood functions that take highly variable amount of time to evaluate, you may benefit from using the queue_size that is significantly larger than the number CPUs (but queue_size should be always < K)
Comment thread CHANGELOG.md Outdated
Comment on lines +10 to +12
- When restoring the sampler with the pool, try to use an updated value of queue_size based on pool size
- Use chunksize=1 for dynesty pool as that is better behaved for queue_size>nthreads and unequal duration of function evaluations
- When starting dynesty with multiprocessing pool, I now try to use the _processes keyword to find how many CPUs it is. That should reduce the need for manual queue_size specification
@segasai segasai merged commit 6f1daf7 into master May 7, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants