Skip to content

fix: JIT-cache probe in delaunay/rectangular viz scripts times a cold analysis - #376

Open
Jammy2211 wants to merge 2 commits into
mainfrom
feature/jit-cache-modeling-visualization
Open

Jammy2211 wants to merge 2 commits into
mainfrom
feature/jit-cache-modeling-visualization

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Closes #375. Un-parks imaging/visualization/modeling_visualization_{delaunay,rectangular}_jit.

What re-traced between calls

Nothing in the fit. The JIT cache is hit. The probe was timing two warm calls:

  • Since PyAutoFit#1297 (May 2026), Analysis.fit_for_visualization is an eager fit_from served by per-function JAX JIT caches, not one jax.jit(self.fit_from).
  • Both scripts ran _assert_likelihood_sanity("JAX", analysis_probe, …), which calls analysis_probe.fit_from(...), before the timing block. That warmed every per-function cache, so the timed "compile" call was already warm. On main: rectangular 0.450s → 0.389s, delaunay 0.808s → 0.720s, failing the 0.5x assertion.
  • On a fresh analysis, the first call takes 11.9s (rectangular) / 16.9s (delaunay) and the second 0.46s / 0.75s.

The producer that fixed it is the probe ordering in these two scripts (commit 093abd6). The timing block now runs on a cold analysis_probe, ahead of the Likelihood Sanity block. The module docstrings no longer describe the old jax.jit(self.fit_from) design. The MGE sibling's docstring got the same correction; it has no sanity block and stays parked as SLOW.

What does re-trace, separately (not fixed here). jax_log_compiles on warm calls shows a few eager lax control-flow primitives recompiling on every call, because their closures are rebuilt each call:

  • jit(while) in the positive-only solver: PyAutoArray util/jax_active_set.py cond_fun/body_fun, util/jax_nnls.py converged_check.
  • For Delaunay, also pure_callback, scan and the walk's while: inversion/mesh/interpolator/delaunay.py.

That costs about 0.2s of a 0.48s rectangular warm call and about 0.5s of a 0.9s Delaunay one. It does not affect the assertion, and it lives in PyAutoArray, outside this task's repos. It is filed as the follow-up draft draft/bug/autoarray/eager_lax_control_flow_recompiles_per_visualization_call.md.

Second fix: the zero_contour perf guard was hidden behind the first failure

With the probe fixed, both scripts reached their Visualization Sanity perf guard, a fixed _warm_dt < 0.1 (100 ms). On this laptop it failed at 108 ms / 128 ms. jax_log_compiles shows zero recompiles on warm zero_contour calls, so the time is honest execution on a loaded machine, not PyAutoGalaxy#433 cache-busting. Commit 04dce54 switches the guard to the hardware-independent cold/warm ratio the point_source and interferometer siblings already use (#148).

Decisions taken (decide-and-flag; please confirm at /prm)

  1. Fixed the test, not the library. The draft assumed closure cache-busting in the fit. The evidence shows the assertion failure was the probe order, so the fix is workspace-only. The real per-call eager recompiles in PyAutoArray are filed as a follow-up draft, not fixed here.
  2. Changed the zero_contour perf guard from a fixed 100 ms to the established cold/warm ratio (fix: zero_contour warm-perf assertion uses cold/warm ratio #148 pattern). Without this, the un-parked scripts fail on loaded machines.

Witness

== rectangular   exit=0 wall=173s
First call (compile + run): 11.728s
Second call (cached):       0.644s
Speedup:                    18.2x
PASS: rectangular jit-cached fit_for_visualization works and is reused.
  PASS Visualization Sanity (perf): warm 150.8 ms vs cold 7229.6 ms (ratio 0.02)
fit.png files produced: 1
== delaunay      exit=0 wall=152s
First call (compile + run): 21.199s
Second call (cached):       0.909s
Speedup:                    23.3x
PASS: Delaunay jit-cached fit_for_visualization works and is reused.
  PASS Visualization Sanity (perf): warm 203.3 ms vs cold 8301.1 ms (ratio 0.02)
fit.png files produced: 1

Wall times are from a loaded single-core sandbox with other shift workers running. The 2026-07-30 CI sweep timed these scripts at 36–52s.
The NEEDS_FIX lines for both scripts are removed from config/build/no_run.yaml, and no other config entry excludes them.

Checks

  • Targeted smoke: no curated script references the change, so it ran the import check imaging/jax_likelihood/delaunay.py: PASS (57.3s).
  • Independent review (leg 3): CLEAN on both commits.
  • Tests: workspace scripts only; the witness above is the test.

🤖 Generated with Claude Code

Jammy2211 and others added 2 commits November 26, 2026 21:31
…lar viz scripts

Since PyAutoFit#1297, fit_for_visualization is an eager fit_from served by
per-function JIT caches. The Likelihood Sanity block ran
analysis_probe.fit_from() before the timing block, warming every cache, so
the probe timed two warm calls and failed its speedup assertion. Move the
probe ahead of the sanity block, correct the docstrings, and un-park both
scripts from config/build/no_run.yaml.

Closes #375

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tangular viz scripts

With the JIT-cache probe fixed, the scripts reached their Visualization Sanity
perf guard, a fixed 100 ms budget on the warm zero_contour call. Warm calls
log zero recompiles (jax_log_compiles), but take 108-203 ms on a loaded
machine. Use the hardware-independent cold/warm ratio the point_source and
interferometer siblings adopted in #148.

Refs #375

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

decision-taken Autonomous run took a flagged decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: JIT-cache probe in delaunay/rectangular viz scripts times a warm call

1 participant