Repository navigation
Description
Overview
Nautilus.fit_multiprocessing hands its fork-context Pool(number_of_cores) to nautilus as pool=pool, so nautilus uses the same pool for likelihood calls and for sampler calculations, including NeuralNetworkEmulator.train (nautilus/neural.py:96), which pool.maps n_networks sklearn MLP fits. If any worker dies (e.g. a per-job OOM kill on a cluster), multiprocessing.Pool spawns a replacement but never re-issues the lost task, so pool.map blocks forever. Observed 2026-08-29 on RAL: three 8-core subhalo SLaM runs idle for hours at ~0.7 % CPU, py-spy showing main in neural.py:96 train → pool.map, all workers waiting on the task queue, and a _repopulate_pool replacement worker per job.
Plan
- Pass
pool=(pool, None)to nautilus whennumber_of_cores > 1: likelihoods stay parallel, bound training runs serially in the parent (4 small MLPs on ≤ a few hundred points — negligible cost). - Keep the
number_of_cores <= 1path exactly as is (pool=None, fix: single-core Nautilus fits build no pool (release-integrate corrective, #1442) #1443). - Unit test that the tuple is passed and that the single-core path still passes
None. - Comment explaining the dead-worker hang so the tuple is not "simplified" away.
Detailed implementation plan
Affected Repositories
- PyAutoFit (primary)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main | clean |
Suggested branch: feature/nautilus-serial-bound-training
Implementation Steps
autofit/non_linear/search/nest/nautilus/search.pyfit_multiprocessing(~L341-352): replacepool=poolwithpool=(pool, None) if pool is not None else None(or buildsampler_poolnext topool_context), and extend the existing comment block (L332-340) with the dead-worker rationale.test_autofit/non_linear/search/nest/test_nautilus.py: addtest__multi_core_passes_serial_sampler_pool— monkeypatchsearch.sampler_clswith a stub capturing kwargs (and arun/result stub, or intercept beforerun),number_of_cores=2, assertkwargs["pool"][1] is Noneandkwargs["pool"][0]is a pool. Mirror the style oftest__single_core_builds_no_pool(L69-104).- Run
pytest test_autofit/non_linear/search/nest/test_nautilus.py.
Key Files
autofit/non_linear/search/nest/nautilus/search.py— pool construction and sampler kwargstest_autofit/non_linear/search/nest/test_nautilus.py— existing pool tests- nautilus
sampler.py:281-295(pooltuple semantics),neural.py:96(bound training map) — reference only
Original Prompt
Click to expand starting prompt
PyAutoFit: Nautilus multiprocessing — run neural-bound training serially in the parent (pass pool=(pool, None)) so a dead fork-pool worker cannot hang Pool.map during bound construction; keep likelihood evaluation parallel. Found on RAL 2026-08-29 in subhalo_validation job B (py-spy: main in nautilus/neural.py:96 train → pool.map, workers idle, _repopulate_pool replacement worker). Change is at autofit/non_linear/search/nest/nautilus/search.py ~L352 (pool=pool).
Activity
Jammy2211 commentedon Aug 29, 2026
Library PR Created
PR: #1548 (branch
feature/nautilus-serial-bound-training, commit1f7808e)fit_multiprocessingnow passes nautiluspool=(pool, None)— the fork pool stays on likelihood evaluation (pool_l), while sampler calculations includingNeuralNetworkEmulator.trainrun serially in the parent (pool_s = None). Thenumber_of_cores <= 1path is unchanged (pool=None). The comment block records the dead-worker hang so the tuple is not simplified away.Tests (in the task worktree,
activate.shsourced):pytest test_autofit/non_linear/search/nest/test_nautilus.py -q→ 5 passedpytest test_autofit/non_linear/search -q -x→ 325 passed, 2 skippedHeart readiness at ship time: YELLOW (
workspace validation not passing (0 failed, 1 timeout, cloud#33229145647: autolens_test scripts/multi_dataset/delaunay_mge.py); stale:release validation incomplete: no rehearsal for current source) — both unrelated to this change. Not merged.fix(nautilus): dispatch likelihood_worker so the Fitness is not pickl…
Jammy2211 commentedon Aug 30, 2026
Second root cause on the same code path: the
Fitnessis pickled into every taskThe serial-bound-training fix (1f7808e) removes the hang, but py-spy on the RAL runs showed a second, independent problem on the same line of nautilus.
Evidence. Sampling workers were not sitting in the likelihood at all — at minute 22 of a run a worker was inside
psf.reversed_kernelbuilding aConvolver, i.e. constructing the dataset, which should happen once per fit and never inside a likelihood evaluation. That is a fresh dataset being materialised per call.Cause.
Nautilus.fit_multiprocessinghas passed aPoolobject since #1439 / e6279c5 (2026-07-31, the Py3.14 fork-context pin). Innautilus/pool.py, only anintpool takes thePool(n, initializer=initialize_worker, initargs=(likelihood,))branch, after whichsampler.likelihoodis swapped for the module-levellikelihood_workerand tasks carry nothing but parameter vectors. A pool object falls straight through toself.pool.map(func, iterable), andsampler.pycalls it asself.pool_l.map(self.likelihood, args)withself.likelihood = fitness.call_wrap.multiprocessingpickles that bound method into every task chunk, so the parent serialises — and each worker unpickles — the entireFitness: analysis, dataset (with the PSFConvolver), sparse operator, adapt images, grids, for every likelihood call.Symptoms this explains.
Fix (56fb8b6, on
feature/nautilus-serial-bound-training): build the fork pool with nautilus's owninitialize_workerandinitargs=(fitness.call_wrap,)— underforkthe initargs are inherited by the child, never pickled — and hand nautilus a small_LikelihoodWorkerPoolwrapper whosemapignores the function it is given and dispatcheslikelihood_worker, restoring exactly what thepool=<int>path did before #1439.pool_sstaysNone, so the first fix is unchanged.Regression test
test__likelihood_pool_does_not_pickle_fitnessmaps a likelihood whose__getstate__raises through the wrapper on a real forkPool(2); a control run confirms the same object mapped through a plainpool.mapdoes raise, so the test is not vacuous.Commit: 56fb8b63b — PR #1548.
Merge pull request #1548 from PyAutoLabs/feature/nautilus-serial-boun…
Jammy2211 commentedon Aug 30, 2026
Shipped
Merged in #1548 (
e6ff1e65onmain):_LikelihoodWorkerPool+initialize_worker: nautilus's likelihood pool now dispatcheslikelihood_worker, so theFitness(analysis, dataset, PSF, sparse operator, adapt images — 173.7 MB at HST/3.5") is no longer pickled into every task chunk. Measured: +59.5 MB/call/worker linear → flat; per-call 1.7 s → 0.25 s in the harness; on RAL 8-core runs went from ~2.4 to ~6 busy cores with memory flat at ~6 GB/task (was 100 GB → OOM).pool=(pool, None): neural-bound training runs serially in the parent, so a dead worker can no longer hangPool.map.Regression introduced by fix: pin multiprocessing pools to the fork start method (Python 3.14) #1439 (2026-07-31). Tests: 6 nautilus, 326
non_linear/searchpassing; CI green on 3.12 / 3.13 / nojax.