Skip to content

Add live_visual_update flag for opt-in on-the-fly visualization - #1293

Merged
Jammy2211 merged 3 commits into
mainfrom
feature/live-visual-update
May 22, 2026
Merged

Jammy2211 merged 3 commits into
mainfrom
feature/live-visual-update

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Adds live_visual_update (default False) to NonLinearSearch. When True:

  • Script mode — a lightweight python -m autofit.non_linear.live_viewer subprocess opens a matplotlib window that polls subplot_fit.png for mtime changes and redraws on each quick-update.
  • Jupyter / Colab — the existing display_id-stable cell update fires.

When False (the default), only disk PNG writes happen — no live surface is opened.

Behaviour change to call out: today's implicit "if a kernel is detected, push image to cell" is now opt-in. Notebook users who relied on the implicit path must add live_visual_update=True to their search constructor to keep the old experience. Disk-only workflows need no change.

API Changes

NonLinearSearch.__init__ gains optional live_visual_update kwarg (default None, falls back to general.updates.live_visual_update in config — defaults false). Fitness.__init__ and BackgroundQuickUpdate.__init__ gain the same flag. A new LiveDisplay helper class composes the display surfaces and replaces the inline IPython-push logic that lived on BackgroundQuickUpdate. New standalone module autofit.non_linear.live_viewer for the script-mode subprocess. New config default general.updates.live_visual_update: false. See full details below.

Test Plan

  • pytest test_autofit/ — 1226 passed, 1 skipped
  • pytest test_autofit/non_linear/test_quick_update.py — 14 passed; new TestLiveVisualUpdateFlag covers the opt-in gate (default does not push to a simulated kernel) and the script-mode viewer subprocess spawn
  • python -m autofit.non_linear.live_viewer /tmp/nonexistent.png under MPLBACKEND=Agg exits 0 with a single warning (headless backend safety check)
  • Manual: run start_here.py in autolens_workspace with live_visual_update=True on af.Nautilus(...) and confirm a matplotlib window appears and refreshes every quick update
  • Manual: run the same script in a Jupyter notebook with live_visual_update=True and confirm the cell output refreshes in place
Full API Changes (for automation & release notes)

Added

  • autofit.non_linear.search.NonLinearSearch(..., live_visual_update: Optional[bool] = None, ...) — new kwarg. When None, reads general.updates.live_visual_update from config (defaults false). Stored as self.live_visual_update.
  • autofit.non_linear.fitness.Fitness(..., live_visual_update: bool = False) — new kwarg threaded through from the search.
  • autofit.non_linear.quick_update.LiveDisplay(live_visual_update=False, display_id="pyauto_fit_progress") — new helper class that owns kernel-vs-script dispatch and (in script mode) lazily spawns the viewer subprocess on first update.
  • autofit.non_linear.quick_update.BackgroundQuickUpdate(..., live_visual_update: bool = False) — new kwarg; composes a LiveDisplay internally.
  • autofit.non_linear.live_viewer — new module. Run as python -m autofit.non_linear.live_viewer <png_path>. Polls the file on disk every 0.5s and redraws a matplotlib window on mtime change. Exits cleanly on headless backends (Agg/PDF/SVG/etc.) with a single warning.
  • Config: general.updates.live_visual_update: false in autofit/config/general.yaml.

Changed Behaviour

  • The previously-implicit "if a Jupyter / Colab kernel is detected, push the image to a cell via display_id" behaviour is now gated on live_visual_update=True. Existing notebook users who relied on the implicit path must opt in explicitly.
  • The IPython push logic (_push_to_ipython, kernel detection, image-path resolution) moved off BackgroundQuickUpdate and into a new LiveDisplay helper / module-level functions. These are all private (_-prefixed) APIs; tests that referenced them have been updated.
  • Disk PNG writes (subplot_fit.png, fit.png, subplot_tracer.png) continue every quick update regardless of the flag.

Migration

  • Before (notebook user, implicit live cell updates):
    search = af.Nautilus(name=..., iterations_per_quick_update=1000)
  • After (to keep the same behaviour):
    search = af.Nautilus(name=..., iterations_per_quick_update=1000, live_visual_update=True)
  • Disk-only workflows need no change — the default (False) preserves "write PNG, no live surface".

🤖 Generated with Claude Code

NonLinearSearch gains a `live_visual_update` flag (default False) that
opens a matplotlib viewer subprocess in script mode and enables Jupyter
cell live-updates inside a kernel. fit.png on-disk writes are unaffected.

The previously-implicit "push image to Jupyter cell when a kernel is
detected" behaviour is now gated on this flag — notebook users who
relied on it must now pass live_visual_update=True explicitly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label May 22, 2026
Jammy2211 and others added 2 commits May 22, 2026 19:20
`subplot_fit.png` was the first candidate in `_DISPLAY_CANDIDATES` but
no plotter writes that filename — PyAutoGalaxy and PyAutoLens
`subplot_fit` functions all call `_save_subplot(fig, output_path,
"fit", ...)` which produces `fit.png`. The display path worked by
accident via the fallback to the second candidate.

Drop the phantom, put `fit.png` first, update tests to write the real
filename, fix the live_viewer docstring.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The lens imaging plotter (and every other model plotter) short-circuits
with `if quick_update: return` immediately after `subplot_fit`, so the
tracer subplot is never written during a quick update. The fallback was
also stale: the `subplot_` prefix was dropped from all PNG outputs
across the codebase — the file is `tracer.png` now, not
`subplot_tracer.png`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Jammy2211
Jammy2211 merged commit 55f5e30 into main May 22, 2026
7 checks passed
@Jammy2211
Jammy2211 deleted the feature/live-visual-update branch May 22, 2026 18:36
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 4, 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