Repository navigation
fix(dynesty): run serially at number_of_cores=1, build no Pool(1) - #1632
Merged
Merged
Conversation
`AbstractDynesty.fit` built a forked `Pool(1)` even at `number_of_cores=1`, dropping to serial only when pool construction raised `RuntimeError`. A `Pool(1)` forces every likelihood call through a forked worker, which deadlocks in XLA compilation when the likelihood touches JAX and hangs forever if that worker dies (the pool replaces it, never re-issues its task). Nautilus received the same fix in #1442/#1443; Dynesty had not. - `number_of_cores <= 1` now joins the `force_x1_cpu` / `analysis._use_jax` pre-emption, so the existing `pool=None, queue_size=None` branch runs and `uses_pool.save` records False; a dedicated log line replaces the misleading "pool could not be created" message. - Docstrings: drop the paragraph justifying the `Pool(1)` (resume-with-more- cores), state the new serial behaviour and its consequence: a run started single-core cannot be resumed multi-core (`check_pool` raises), as on the `force_x1_cpu` path already. - `test__single_core_builds_no_pool` (DynestyStatic + DynestyDynamic) mirrors the Nautilus test: `fork_context` patched to raise, a number_of_cores=1 fit must complete. Red on the unfixed source, green after. - `test__ep_single_core_search_unchanged` now takes the `no_forking` fixture and loses the comment excusing the `Pool(1)`. Closes #1630 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
af.DynestyStatic(number_of_cores=1)/af.DynestyDynamic(number_of_cores=1)built a real forkedPool(1)through_fork_pool_cls(), falling back to serial only when pool construction raisedRuntimeError. APool(1)forces every likelihood call through a forked worker: that deadlocks in XLA compilation when the likelihood touches JAX withoutuse_jax=Trueon the analysis, and hangs forever if the single worker dies, becausemultiprocessing.Poolreplaces the worker but never re-issues its in-flight task. Nautilus received the same fix in #1442/#1443; Dynesty had not.At
number_of_cores <= 1Dynesty now builds no pool and runs fully serially, via the existingpool=None, queue_size=Nonebranch (which already writesuses_pool=False). The fork-context pool is unchanged for genuine multi-core runs, and theRuntimeErrorfallback for broken multiprocessing (Windows) stays.Trade-off, deliberate: a run started with
number_of_cores=1can no longer be resumed with more cores;check_poolraises the existingSearchException, exactly as on theforce_x1_cpupath. The old docstring justified thePool(1)with that resume path; Nautilus accepted the same trade-off in #1443, and JAX-safety plus no silent hangs win.Found while writing
test__ep_single_core_search_unchangedfor #1608, which carried a comment excusing thePool(1); that test now takes theno_forkingfixture.Closes #1630
API Changes
None — internal behaviour change only. No public symbol added, removed or re-signed.
DynestyStatic/DynestyDynamicwithnumber_of_cores=1now run serially with no multiprocessing pool (previously a forkedPool(1)). A single-core run resumed withnumber_of_cores > 1now raisesSearchExceptionfromcheck_poolinstead of silently continuing on a pool.See full details below.
Test Plan
test_autofit/non_linear/search/nest/test_dynesty.py::test__single_core_builds_no_pool[DynestyStatic|DynestyDynamic]— fails onmainwithAssertionError: fork_context must not be used when number_of_cores == 1(raised fromForkPool.__enter__), passes on this branch.test__ep_single_core_search_unchangednow runs under theno_forkingfixture and passes.pytest test_autofit/non_linear -x: 864 passed, 1 skipped.Full API Changes (for automation & release notes)
Removed
Added
Changed (behaviour only)
AbstractDynesty.fit:number_of_cores <= 1joins theforce_x1_cpu/analysis._use_jaxserial pre-emption; noPool(1)is built. New log line "Running Dynesty single-CPU (number_of_cores=1, no pool)." replaces the misleading "pool could not be created" message on this path.number_of_cores=1cannot be resumed withnumber_of_cores > 1(check_poolraisesSearchException). Start multi-core runs multi-core.Migration
number_of_cores.Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code