Repository navigation
Description
Overview
Adds in-cell live updating of the quick-update visualization when a search runs inside a Jupyter / Colab kernel. The background threading and JAX-fast visualization already exist (BackgroundQuickUpdate from commit 1fee93174, plus the Phase A′/B work on PyAutoGalaxy+PyAutoLens). This task wires IPython.display.update_display so the notebook cell displays and refreshes in place during the fit, instead of just writing PNGs to disk.
Phase C of z_features/fast_visualization.md. Phase A is superseded; Phase B shipped (PyAutoFit #1288, PyAutoGalaxy #435, pipeline #15).
Plan
- Add an
_is_ipython_kernel()check toBackgroundQuickUpdate— returns True when running inside a Jupyter/Colab IPython kernel, False otherwise (script mode unchanged). - Inside the daemon worker's
_process_pending, afteranalysis.perform_quick_updatereturns, push the freshly-writtensubplot_fit.pnginto the active cell usingIPython.display.update_displaywith a stabledisplay_id="pyauto_fit_progress". First call usesdisplay(..., display_id=True)to initialise; subsequent calls useupdate_display(...)to refresh in place. - Read the PNG from disk (not the matplotlib
Figureobject) — avoids cross-thread matplotlib handling since the worker is a daemon thread. - Gracefully fall back when not in an IPython kernel, when IPython isn't installed, or when the PNG hasn't been written yet — log and swallow failures so the search is never taken down by a display issue.
- Add
PYAUTO_DISABLE_IPYTHON_DISPLAY=1opt-out for users who run notebooks via papermill / scripted execution without wanting display side effects. - Three unit tests covering the kernel-detection no-op path, the missing-PNG no-op path, and the
display→update_displaysequence with a mocked IPython. - Document in
autofit_workspace— add a new__Live Quick-Update Visualization__section toscripts/cookbooks/analysis.py(after the existing__Visualization__section, line ~198). The analysis cookbook currently has zero mentions ofiterations_per_quick_update/background_quick_update/perform_quick_updatedespite these being core search-time features. Workspace work ships after the library PR lands in a release.
Detailed implementation plan
Affected Repositories
- PyAutoFit (primary, library)
- autofit_workspace (follow-up, workspace docs)
Work Classification
Both — library first, then workspace docs via /start_workspace after the library PR ships in a release.
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main | clean |
| ./autofit_workspace | main | clean (workspace docs added after library lands in a release) |
Suggested branch: feature/quick-update-display-id
Worktree root: ~/Code/PyAutoLabs-wt/quick-update-display-id/ (created later by /start_library)
Implementation Steps
-
PyAutoFit/autofit/non_linear/quick_update.py— extendBackgroundQuickUpdate:__init__gainsdisplay_id: str = "pyauto_fit_progress"and a_display_initialised: bool = Falseflag.- Add
_is_ipython_kernel()helper (try-import IPython, checkget_ipython()hasIPKernelAppin.config, swallow ImportError). - Add
_push_to_ipython(paths)helper that findssubplot_fit.png(or alternates likefit.png,subplot_tracer.pngin priority order),display(Image(filename=...), display_id=self._display_id)on first call,update_display(...)thereafter. RespectsPYAUTO_DISABLE_IPYTHON_DISPLAY=1env var. - Hook
_push_to_ipython(paths)into_process_pendingafteranalysis.perform_quick_update(paths, instance)returns successfully. Wrap in try/except so a display failure doesn't crash the worker.
-
PyAutoFit/test_autofit/non_linear/test_quick_update.py— add three tests:_is_ipython_kernel()returns False in normal pytest execution (no IPython kernel)._push_to_ipython()is a no-op when no PNG exists at the expected path.- With monkeypatched IPython modules + a synthetic PNG, the first call triggers
display(... display_id="pyauto_fit_progress")and the second triggersupdate_display(...)with the same id.
-
Verification (manual) — execute a small notebook via
jupyter nbconvert --executefitting anaf.ex.Gaussianwithn_live=25, n_like_max=200,iterations_per_quick_update=50,background_quick_update=True. Cell output should show a single self-updating image, not stacked frames. -
autofit_workspace/scripts/cookbooks/analysis.py— workspace docs (follow-up PR after library lands in a release):- Add a new
__Live Quick-Update Visualization__section after the existing__Visualization__section at line ~198. - Cover: what
iterations_per_quick_updatedoes, whatbackground_quick_update=Trueadds (daemon thread + latest-only drop), what this PR adds (cell auto-updates in place when running in a Jupyter / Colab kernel), script-mode unchanged,PYAUTO_DISABLE_IPYTHON_DISPLAY=1opt-out, plus a small commented API-shape example (do NOT include a runnable Nautilus fit — matches existing cookbook convention). - Regenerate the matching
notebooks/cookbooks/analysis.ipynbvia PyAutoBuild'spy_to_notebook(or the next/pre_build).
- Add a new
Key Files
PyAutoFit/autofit/non_linear/quick_update.py— additive changes toBackgroundQuickUpdate.PyAutoFit/test_autofit/non_linear/test_quick_update.py— three new tests.autofit_workspace/scripts/cookbooks/analysis.py— new__Live Quick-Update Visualization__section (workspace follow-up).
Out of scope
- Subprocess visualisation (deferred Phase F).
- Matplotlib figure capture across threads — sidestepped entirely by reading the PNG.
- Colab-specific tweaks beyond what the generic IPython kernel detection covers.
- Multi-figure layouts in a single cell.
Original Prompt
Click to expand starting prompt
See PyAutoPrompt/issued/quick_update_display_id.md for the verbatim authored prompt. Key reference points kept inline for issue-time visibility:
- What already exists:
BackgroundQuickUpdate(daemon thread, latest-only drop) + JAX-fastperform_quick_update(Phase A′ + B) + PNGs landing on disk. - What's missing: notebook users have to open the PNGs externally. The user-facing goal is "Jupyter cells update on the fly during modeling".
- Approach: read the PNG that
perform_quick_updatejust wrote and push it viaIPython.display.update_displaywith a stabledisplay_idso the cell refreshes in place. Thread-safe (PNG bytes only, no Figure handling). Falls back to script behaviour outside IPython.
Activity
Jammy2211 commentedon May 21, 2026
Library PR Created — 2026-05-21
PR
Status
Library code + tests shipped. CI in progress. Workspace cookbook docs follow next via
/start_workspaceonce the library PR is merged + a release ships (so the doc text matches behaviour available onpip install autofit).API Changes (purely additive)
BackgroundQuickUpdate(display_id: str = "pyauto_fit_progress").subplot_fit.pngto the cell viaIPython.display.update_displayso the cell refreshes in place during the fit.PYAUTO_DISABLE_IPYTHON_DISPLAY=1opt-out for papermill / nbconvert pipelines.Test results
test_autofit/suite). Three new tests cover kernel-detection no-op, missing-PNG no-op, and thedisplay→update_displaysequence with mocked IPython.Jammy2211 commentedon May 21, 2026
Shipped — 2026-05-21
PRs
Summary
BackgroundQuickUpdatenow pushes the freshly-writtensubplot_fit.pngto the active Jupyter / Colab cell viaIPython.display.update_displaywith a stabledisplay_id, so the cell that ransearch.fit(...)shows a single self-updating image during the fit. Script-mode execution is unchanged. The autofit_workspaceanalysiscookbook documents this plus the underlyingiterations_per_quick_update/background_quick_updatemechanics (cookbook had zero coverage of either before this).Session Notes
start_here.pyunderPYAUTO_TEST_MODE=1) earlier in the day on the Phase B work — confirms the background-thread + PNG-on-disk machinery this layer plugs into.searches/nest.py(ImportError: af.NSS requires the optional 'nss' package) — pre-existing CI infrastructure gap, identical shape to the previous task'spoint.pyCI red. Local smoke 7/7 PASS in a dev env with the NSS extras installed.ship_workspaceSonnet subagent's smoke-runner had a cwd bug that surfaced here: it ran the smoke scripts with cwd one level above the workspace, so all auto-simulationsubprocess.run([python, 'scripts/simulators/simulators.py'], ...)calls failed. Manual re-run from the correct cwd was clean. Worth tightening the subagent contract.BackgroundQuickUpdateis currently only wired into Nautilus viabackground_quick_update=True. If other samplers (Dynesty, Emcee, MLE searches) want the same in-cell live update, they need the same kwarg threading. Out of scope here.