Skip to content

fix: warm the likelihood up in the parent before forking workers - #1715

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/finufft-cpu-nufft-backend
Oct 24, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/finufft-cpu-nufft-backend

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Before forking likelihood workers, a search now runs the likelihood once in the parent (Fitness.prepare_for_fork, NumPy path only). This fixes multi-core Nautilus fits segfaulting with ≥16 workers when nothing in the parent had used numba yet.

Root cause (confirmed on RAL): since PyAutoArray 2026.8.20.1, numba_util defers import numba to the first numba call. Imaging parents always run numba before the search (the Overlay/Hilbert source mesh), so workers inherit it. An interferometer setup whose preprocessing and mesh are NumPy-only never touches numba in the parent, so numba's first import and LLVM initialisation happen inside every forked worker at once and they segfault (about 8 survive, 16+ crash).

28-core numba Nautilus, interferometer, parent before fork Result
numba never imported (with or without JAX) segfault, 12/12 runs
import numba only OK 2/2
trivial njit compile OK 2/2
this PR (automatic warm-up), no script changes OK 2/2, 33–34 evals/s, 0 worker deaths

It also moves the first numba compile from N workers into one parent call.

Part of PyAutoLabs/PyAutoArray#654 (companion PR there: finufft CPU NUFFT).

API Changes

  • New Fitness.prepare_for_fork() — runs the likelihood once at the prior medians on the NumPy path (no-op for JAX, once per Fitness, non-fatal on failure, not recorded in history / quick-update state), then imports numba as a backstop.
  • Called automatically before every likelihood pool fork: Nautilus fit_multiprocessing, PoolFactory.__call__ (Zeus, Dynesty), SneakyPool (Emcee, initializer).
  • Nautilus dead-worker watchdog: a SIGSEGV (-11) death now gets a specific message (native-library initialisation after fork; what to do). Other exit codes keep the existing message.
    See full details below.

Test Plan

  • pytest test_autofit: full suite green (see ship log)
  • New test_prepare_for_fork.py (7 tests) + 3 Nautilus tests
  • Emulated no-JAX leg on touched files: passed, JAX tests skip cleanly
  • RAL witness: 28-core interferometer Nautilus without any workaround — 2/2 clean (previously 12/12 segfaults)
Full API Changes (for automation & release notes)

Added

  • Fitness.prepare_for_fork().
  • PoolFactory.fitness attribute and PoolFactory.prepare_for_fork(fitness=None).

Changed

  • PoolFactory.__call__ and SneakyPool.__init__ (processes > 1) warm the fitness up before forking.
  • search/execution.py sets pools.fitness after make_fitness.
  • Nautilus fit_multiprocessing warms up before building its pool; watchdog SIGSEGV message.

Not covered (follow-up)

  • analysis/multiprocessing.py (AnalysisPool / AnalysisProcess, summed analyses) forks without a Fitness; could hit the same failure with many numba-backed analyses and no numba in the parent.

Migration

  • None. Users no longer need a manual likelihood call before multi-core fits.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

https://claude.ai/code/session_013C7Zd6ibK9J4V8CFEUzrJU

…utoArray#654)

numba is imported lazily since autoarray 2026.8.20.1; when nothing in the
parent ran numba, every forked Nautilus worker imported/initialised it at once
and >=16 workers segfaulted. Fitness.prepare_for_fork runs the likelihood once
on the NumPy path (and imports numba) before any likelihood pool forks:
Nautilus, PoolFactory and SneakyPool. The watchdog gets a specific SIGSEGV
message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013C7Zd6ibK9J4V8CFEUzrJU
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Oct 24, 2026
@Jammy2211
Jammy2211 merged commit ceef8af into main Oct 24, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the feature/finufft-cpu-nufft-backend branch October 24, 2026 16:57
@pyautolabs-bot pyautolabs-bot Bot removed the pending-release PR queued for the next release build label Oct 25, 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.

1 participant