Repository navigation
Description
Overview
Two things the CLI tells a user during a non-linear search are wrong, and both cost the user the same thing: they cannot tell what the run is doing, or how long a silence will last.
- A variable name reaches the terminal instead of its value. 23 workspace scripts print
On-the-fly updates every iterations_per_quick_update are printed to the notebook.— the literal token, not the cadence. - The JAX compile message fires before any compilation happens.
autofit/non_linear/fitness.py:508/528/549log at wrapper-construction time, butjax.jit(...)returns instantly; tracing, lowering and XLA compilation all happen on the first call to the returned function (fitness.py:310). The user sees "applied in 0.0002 seconds", then sits through an unexplained wait that can run to minutes.
A complication found while scoping: the packaged default for iterations_per_quick_update is 1e99 (config/general.yaml, updates: block) — the codebase's documented inf-like "never" sentinel (see the _steps_until_full_update docstring, abstract_search.py:1040-1088). Only hpc_mode sets a real value (250000). So for almost every user the truthful message is not a number at all: it is "these updates are off". A naive f-string would render 1e+99, which is worse than the placeholder it replaces.
Decision: the library owns the cadence message. PyAutoFit logs it once at search start; the 23 workspace scripts drop that sentence entirely — one source of truth instead of the same conditional pasted into 23 files. This issue is Phase 1 (PyAutoFit); the workspace sweep is Phase 2, a separate follow-up issue.
Plan
- Add an
AbstractSearch.quick_update_messageproperty that renders the real integer cadence, or — when the value is the1e99"never" sentinel — states plainly that on-the-fly updates are disabled and names the config key that enables them. - Log that message once at search start, alongside the existing "Starting non-linear search…" line.
- Replace the three misleading JAX pre-wrap log pairs with a one-shot wrapper that logs
JAX jit compiling <what>, could take seconds or minutes...on the first call — where the wait actually is — and reports the true elapsed compile time after it. - Cover both with unit tests (neither needs JAX installed).
- File Phase 2 (remove the now-duplicated sentence from 23 workspace scripts, regenerate notebooks/markdown) as a follow-up.
Detailed implementation plan
Affected Repositories
- PyAutoFit (primary, Phase 1 — this issue)
- autolens_workspace / autogalaxy_workspace / HowToLens (Phase 2, separate issue)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main | clean |
| ./autolens_workspace | main | clean |
| ./autogalaxy_workspace | main | clean |
| ./HowToLens | main | clean |
Suggested branch: feature/sampler-cli-output-numbers
Phase 2 is additionally gated on contention: autolens_workspace currently has two live worktree claims (multi-galaxy-slam-followup, scaling-relation-degraded-profile-fixes).
Brain scored this large (8) and wanted a phase split. The score comes from its repo-count proxy; the library change is one property plus one wrapper. Size overridden to medium, split kept.
Implementation Steps
1a — cadence message. autofit/non_linear/search/abstract_search.py
Add a module constant:
#: Values at or above this disable periodic updates. The packaged config
#: default is the inf-like ``1e99`` sentinel documented on
#: ``_steps_until_full_update`` — kept as a float so ``search.json`` stores a
#: readable ``1e99`` rather than a 99-digit integer.
ITERATIONS_NEVER = 1e90and a property on AbstractSearch:
@property
def quick_update_message(self) -> str:
n = self.iterations_per_quick_update
if not np.isfinite(n) or n >= ITERATIONS_NEVER:
return (
"On-the-fly updates of the maximum likelihood model are disabled. "
"Set `updates: iterations_per_quick_update` in config/general.yaml "
"to a finite number of iterations to enable them."
)
return (
"On-the-fly updates of the maximum likelihood model every "
f"{int(n)} iterations."
)np is already imported (abstract_search.py:6). Log it in fit() immediately after the existing "Starting non-linear search…" block (abstract_search.py:496-510):
logger.info(self.quick_update_message)Unconditional, matching the adjacent call — not gated on self.silence.
1b — JAX compile message. autofit/non_linear/fitness.py
Add a one-shot wrapper helper on Fitness:
def _log_on_first_compile(self, func, description):
"""Wrap ``func`` so its first invocation reports the JAX compile it triggers.
``jax.jit`` / ``jax.vmap`` / ``jax.grad`` return immediately — tracing,
lowering and XLA compilation all happen on the first call to the returned
function. This is therefore the only point at which the user can be told
why the run appears to hang.
"""
state = {"compiled": False}
def wrapper(*args, **kwargs):
if state["compiled"]:
return func(*args, **kwargs)
logger.info(
f"JAX jit compiling {description}, could take seconds or minutes..."
)
start = time.time()
try:
result = func(*args, **kwargs)
# JAX dispatches asynchronously; block once so the reported time is
# the real wall-clock wait rather than the dispatch latency.
try:
import jax
jax.block_until_ready(result)
except Exception:
pass
finally:
state["compiled"] = True
logger.info(
f"JAX jit compilation of {description} complete in "
f"{time.time() - start:.1f} seconds."
)
return result
return wrapperThen collapse the three cached_property bodies (currently fitness.py:494-553) to use it, deleting the misleading pre-wrap timing logs:
_vmap→jax.vmap(jax.jit(self.call)), description"vectorized (vmap) likelihood function"_jit→jax.jit(self.call), description"likelihood function"_grad→jax.grad(self.call), description"likelihood function gradient"
Constraints that shaped this (all verified against the source):
fitness._jitis passed to scipy asfun=inautofit/non_linear/search/mle/bfgs/search.py:183— the wrapper must stay a plain callable, which it is.__getstate__/__setstate__(fitness.py:474-491) already strip and lazily rebuild_call/_jit/_vmap/_grad, so the non-picklable closure never reaches pickle and the flag resets per process — correct, since an unpickled process really does recompile. Keepstest_autofit/non_linear/test_fitness_jax_dispatch.pygreen._warmup_visualization(fitness.py:177-200) already logs "Warming up visualization (one-time JAX compilation)…" — left as is; the new wording is consistent with it.
1c — tests. test_autofit/non_linear/
_log_on_first_compile: wrap a plainlambda, assert the "could take seconds or minutes" line is logged exactly once across two calls (viacaplog) and the return value passes through. No JAX needed.quick_update_message: parametrize a finite cadence (renders the integer, no.0) against the1e99sentinel (renders the disabled wording naming the config key).
Key Files
autofit/non_linear/search/abstract_search.py—ITERATIONS_NEVER,quick_update_message, thefit()log call (~line 510)autofit/non_linear/fitness.py—_log_on_first_compile, and the_jit/_vmap/_gradcached propertiesautofit/non_linear/search/mle/bfgs/search.py:183— consumer offitness._jit, constrains the wrapper to a plain callabletest_autofit/non_linear/test_fitness_jax_dispatch.py— existing pickle-roundtrip coverage that must stay green
Verification
cd PyAutoFit
NUMBA_CACHE_DIR=/tmp/numba_cache MPLCONFIGDIR=/tmp/matplotlib \
python -m pytest test_autofit/Then end-to-end, which is what actually proves the fix — unit tests cannot see message ordering against a real compile:
- Run a JAX-backed fit and confirm the compile line appears before the long wait, and that the reported elapsed time matches the observed wait rather than ~0s.
- Same run under the default config: confirm the "updates are disabled" wording naming
iterations_per_quick_update. - Re-run with
iterations_per_quick_updateset to a small finite value: confirm the printed integer matches the config and that quick updates then actually occur at that cadence.
Original Prompt
Click to expand starting prompt
On-the-fly updates every iterations_per_quick_update is the command line output
when a sampler runs, the actuallyh number should be printed to the CLI should say
the actual number
follow up, when JAX compiles a LH function it should say Should say "JAX jit
compiling likelihood function, could take seconds or minutes..." in output so user
knows why theres a small wait so a user knows they are waiting
Activity
Jammy2211 commentedon Jul 30, 2026
quick_update_messagegives inert advice for the multi-start gradient searchesSurfaced from #1433 (per-step progress logging for
MultiStartProdigy/MultiStartAdam/MultiStartADABelief/MultiStartLion), which runs in parallel with this task on disjoint PyAutoFit files. Flagging rather than fixing, since this file is yours.The new
NonLinearSearch.quick_update_messageproperty logs, on the disabled branch:That is correct and actionable for the samplers. For the four multi-start gradient searches it is inert advice — a user who follows it changes the config, sees no updates, and has no way to learn why. Two independent reasons, either one sufficient:
1. The searches never wire the knob into their
Fitness.AbstractMultiStartGradient._fitconstructs it without the kwarg (autofit/non_linear/search/mle/multi_start_gradient/search.py:234-241):Every other search passes it through — e.g.
nest/nautilus/search.py:195,216useiterations_per_quick_update=self.iterations_per_quick_update. SinceFitness.__init__defaults it toNone(fitness.py:47),Fitness.quick_update()hits itsif self.iterations_per_quick_update is None: returnguard (fitness.py:378) on every call, whateverconfig/general.yamlsays.2. Even wired, the counter cannot run.
The counting lives inside
fitness.call, which these searches trace underjax.jit(jax.vmap(...))(search.py:260-261). The Python-sideself.quick_update_count += total_updatesexecutes once at trace time and never again — andif best_log_likelihood > self.quick_update_max_lh:on a traced value would not survive as a Python branch anyway.Suggested handling
The honest message for these searches is "not available", not "disabled — enable it here". Options, cheapest first:
quick_update_messageconsult whether the search actually wires the knob through (e.g. a class-level flag such assupports_quick_update = FalseonAbstractMultiStartGradient), and emit a third branch naming the real reason — the objective is JIT-traced, so per-iteration Python callbacks cannot fire.Either way it belongs on this issue's side of the seam, since #1433 does not touch
abstract_search.py.For context: #1433 is adding per-step progress logging plus two JAX-compile notices directly inside
_fit, because these searches bypassfitness._jit/_vmap/_gradentirely — so the compile-message fix planned here will not reach them either. Detail in #1433 (comment). Wording will be matched to whatever this task lands.Jammy2211 commentedon Jul 30, 2026
Scope grew during verification — two real defects found behind the cosmetic one
The planned output fixes are done, but verifying them end-to-end (rather than only by unit test) turned up two substantive bugs that the cosmetic fix would otherwise have made worse. Both are now fixed here, with the wiring expansion human-approved before it was made.
1. Quick updates were silently dead for 7 of 8 searches
Only
Nautilusforwardediterations_per_quick_updatewhen constructing itsFitness. Dynesty, Emcee, Zeus, BlackJAX NUTS, BFGS, Drawer and MultiStartGradient all omitted it, soFitness.iterations_per_quick_updatewasNoneandmanage_quick_updatereturned at its first guard (fitness.py:378). The search ran perfectly and simply never updated.Control test — same model, same cadence of 25, fresh output directory, only the search differs:
NautilusDynestyStaticSo announcing the cadence in the startup log would have turned a dead feature into an active lie. Fixed by forwarding
iterations_per_quick_update/background_quick_update/live_visual_updateat the 6 remaining search construction sites. Before/after on identical input: 0 quick updates → 1.multi_start_gradient/search.pyis deliberately not wired — it differentiatesfitness.callinside its own jit/vmap step loop, so the Python-side counter would run once at trace time. Its progress reporting is #1433's. The exemption is recorded with that reason in the new wiring test.2. Wiring it up exposed a latent crash in
manage_quick_updateSearches hand over parameters in whatever type they hold: ndarray (Nautilus), JAX array, or a plain Python list (Dynesty's initializer).
.tolist()assumed the array case — which held only while Nautilus was the sole caller. Normalized withnp.asarray(...).tolist().3. Same misleading-message bug in the latent path
analysis/latent.pyhad the identical pattern — "may take a few seconds", reported0.0011seconds, then compiled later. The helper is now a sharedautofit/non_linear/jax_compile.py(log_on_first_compile) used by bothfitness.pyandlatent.py, rather than duplicated.Verified
Real
DynestyStatic+ JAX fit, clean output directory:Isolated probe against a genuinely expensive
jax.jitfunction: nothing logged at wrap time; reported 0.7s matched the real 0.7s wall-clock; second call silent and 64x faster.Both new detectors were checked against the pre-fix source and do fail there — the wiring test on 6 sites, the parameter-container test on the
listandtuplecases.Full suite: 1615 passed, 2 skipped.
Default config still reports
On-the-fly updates ... are disabled. Set 'updates: iterations_per_quick_update' in config/general.yaml ..., since the packaged default is the1e99never-sentinel.Jammy2211 commentedon Jul 30, 2026
Library PR Created
PyAutoFit#1436 — #1436 (OPEN,
pending-release)Heart gated YELLOW, acknowledged by the human before shipping. The three reasons were unrelated to this change:
manifest drift: tenant firewall (organ code) — 1 mismatch(es) vs PyAutoMind/repos.yaml, plus two stale markers (test run status unknown (no report.json),release validation stale: source moved since rehearsal). No RED reasons. PyAutoFit's own suite is green at 1615 passed / 2 skipped.Workspace impact
Option (i)/(ii)-adjacent: no API migration is required, but 23 workspace scripts now carry a sentence the library emits itself, and theirs still names the variable instead of the value. Phase 2 removes it.
autolens_workspaceautogalaxy_workspaceHowToLensPlus 23 generated
.ipynband 14.mdto regenerate.Phase 2 prompt is filed at
PyAutoMind/draft/docs/autolens_workspace/sampler_cli_output_workspace_sweep.mdand should not start until #1436 merges — until then the workspace sentence is wrong but harmless, whereas removing it early would leave users with no cadence message at all.Mind state:
library-shipped, workspace-pending.Jammy2211 commentedon Jul 30, 2026
CI green
PR #1436 — all three legs pass on
daa0dbc:unittest / unittest (3.12)unittest / unittest (3.13)docs / docs-buildPR state
MERGEABLE/CLEAN. Awaiting human merge — Phase 2 (the 23 workspace scripts) stays parked until it lands.Jammy2211 commentedon Jul 30, 2026
Shipped
PyAutoFit#1436 MERGED 2026-07-30 (merge commit
39cbce779). CI green on all three legs before merge; issue auto-closed.Cleanup done: worktree removed,
feature/sampler-cli-output-numbersdeleted locally and on origin, canonical PyAutoFit synced to main.Completion record:
PyAutoMind/complete/2026/07/sampler-cli-output-numbers.md(lifecycle check: OK, index refreshed).Follow-up still open
Phase 2 — remove the now-duplicated sentence from 23 workspace scripts (
autolens_workspace14+,autogalaxy_workspace3+,HowToLens1) and regenerate the 23.ipynb/ 14.mdcounterparts. Prompt filed atPyAutoMind/draft/docs/autolens_workspace/sampler_cli_output_workspace_sweep.md; needs its own issue viastart_dev. Now unblocked, since the library side has merged.Note for #1433: the compile-message wording that landed is
JAX jit compiling <what>, could take seconds or minutes...via the sharedautofit/non_linear/jax_compile.pyhelper (log_on_first_compile). Reuse it rather than adding a second phrasing.