Skip to content

fix(dynesty): run serially at number_of_cores=1, build no Pool(1) - #1632

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/dynesty-single-core-no-pool
Sep 15, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/dynesty-single-core-no-pool

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

af.DynestyStatic(number_of_cores=1) / af.DynestyDynamic(number_of_cores=1) built a real forked Pool(1) through _fork_pool_cls(), falling back to serial only when pool construction raised RuntimeError. A Pool(1) forces every likelihood call through a forked worker: that deadlocks in XLA compilation when the likelihood touches JAX without use_jax=True on the analysis, and hangs forever if the single worker dies, because multiprocessing.Pool replaces 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 <= 1 Dynesty now builds no pool and runs fully serially, via the existing pool=None, queue_size=None branch (which already writes uses_pool=False). The fork-context pool is unchanged for genuine multi-core runs, and the RuntimeError fallback for broken multiprocessing (Windows) stays.

Trade-off, deliberate: a run started with number_of_cores=1 can no longer be resumed with more cores; check_pool raises the existing SearchException, exactly as on the force_x1_cpu path. The old docstring justified the Pool(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_unchanged for #1608, which carried a comment excusing the Pool(1); that test now takes the no_forking fixture.

Closes #1630

API Changes

None — internal behaviour change only. No public symbol added, removed or re-signed. DynestyStatic / DynestyDynamic with number_of_cores=1 now run serially with no multiprocessing pool (previously a forked Pool(1)). A single-core run resumed with number_of_cores > 1 now raises SearchException from check_pool instead 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 on main with AssertionError: fork_context must not be used when number_of_cores == 1 (raised from ForkPool.__enter__), passes on this branch.
  • test__ep_single_core_search_unchanged now runs under the no_forking fixture and passes.
  • pytest test_autofit/non_linear -x: 864 passed, 1 skipped.
  • CI green on all legs.
Full API Changes (for automation & release notes)

Removed

  • None

Added

  • None

Changed (behaviour only)

  • AbstractDynesty.fit: number_of_cores <= 1 joins the force_x1_cpu / analysis._use_jax serial pre-emption; no Pool(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.
  • Resume semantics: a Dynesty run started with number_of_cores=1 cannot be resumed with number_of_cores > 1 (check_pool raises SearchException). Start multi-core runs multi-core.

Migration

  • None required. Users relying on starting a Dynesty run single-core and resuming it multi-core must restart the run with the final number_of_cores.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

`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>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Sep 15, 2026
@Jammy2211
Jammy2211 merged commit b82fb3f into main Sep 15, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/dynesty-single-core-no-pool branch September 15, 2026 20:14
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 26, 2026
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.

fix(dynesty): run serially at number_of_cores=1, build no Pool(1)

1 participant