Skip to content

research(interferometer): numba vs FFT CPU crossover + CPU lever list — campaign 3/3 phase 2 #332

Closed

Description

@Jammy2211

Overview

Phase 2 of the interferometer likelihood campaign 3/3 (epic interferometer-likelihood-campaign). Phase 1 (#326 / #328) measured numba direct_conv vs the NumPy FFT sparse route at mask r3.5 only; this phase measures the numba-vs-FFT crossover in situ across alma mask radii (nnz/col ~10 -> ~120) for both meshes, re-runs the RAL CPU numba rows on PyAutoArray main >= e281abf3 (which now caches F / D, removing a ~40 % redundant F evaluation — folds in the sparse-cache after-measurement), and measures the cheap CPU levers (prange thread scaling, fnnls warm-start memo, Cholesky reuse, kernel_index_arrays marshalling). The result decides whether the packaged gate interferometer_numba_nnz_per_source_max = 60.0 is right.

Plan

  • Fix the harness call counter for cached_property (fold-in diff) and make the F-alone / D-alone sub-rows time the computation, with a unit test.
  • Calibrate on the laptop (2-3 instances, alma, cached code) and choose alma radii so each mesh's crossover is bracketed by two measured points; sweep alma r2.0 / 3.5 / 5.0 + bracketing radii, alma_high r3.5 and sma r3.5, both meshes, numba vs NumPy FFT, recording nnz/col (rect re-derived in situ), masked pixels and the phase-1 row each replaces.
  • Guard the adapt image: record the lensed_source.fits md5; a missing cache at a non-preset radius is a hard error, never a silent regeneration.
  • Add opt-in lever arms (alma r3.5, both meshes, own JSON): prange at 1 / 2 / 4 numba threads, memo on / off (iid + local-walk streams), reused vs fresh Cholesky log-det, marshalling split; MGE+mesh numba route as a static read.
  • RAL CPU submits (gpu partition, no --gres, 1 thread pinned; the lever job declares its numba pool), check_submits.py --check green; submit on the RAL mirror synced to the local mains.
  • After the rows land (next session): verdict-note crossover section (confirm 60 / ~77 or file the general.yaml retune prompt), results/notes/interferometer_mesh_cpu_breakdown_2026_09.md with ranked levers + per-lever draft prompts, README dashboards, ship.
Detailed implementation plan

Affected Repositories

  • autolens_profiling (primary)

Branch Survey

Repository Current Branch Dirty?
./lens/autolens_profiling main untracked dataset/abell_1201/ only

Parallel claim (human-approved 2026-09-27): point-source-source-plane-p2c (#329 / PR #331) also holds autolens_profiling; its files are scripts/point_source_source/**, results/breakdown/point_source_source/** and point-source notes — disjoint from this phase's. README dashboards are regenerated at ship.

Suggested branch: feature/interferometer-mesh-numba-p2

Implementation Steps

  1. scripts/misc/likelihood_breakdown/interferometer_pixelized_numpy.py: cached_property-aware counter (unwrap .func, re-wrap in the original descriptor type, functools.wraps so the autonerves CachedProperty keeps its cache key); sub-rows pop curvature_matrix_diag / data_vector before each repeat; previous_row (the replaced JSON's full calls + revisions); adapt_image provenance (md5, hard error when the cache is missing at a non-preset radius); host name in configuration.
  2. Same harness: --levers threads,memo,logdet,marshal and --lever-threads 1,2,4 writing a levers block (headline steps unchanged). The wrappers scripts/interferometer/likelihood_breakdown/{delaunay,pixelization}_numba.py size the numba pool from AUTOLENS_PROFILING_LEVER_NUMBA_THREADS (default 1); the main arms run the serial kernel.
  3. scripts/misc/test/test_interferometer_pixelized_numpy.py: counter test on a stub class with CachedProperty + property (counts, cache key, restore), sub-row pop test, submit rules for the new submits.
  4. Laptop calibration probe (alma, 2-3 instances) -> radii; hpc/batch_cpu/submit_breakdown_interferometer_{delaunay,pixelization}_numba_ral_crossover_fp64 (array over instrument x radius) and hpc/batch_cpu/submit_breakdown_interferometer_numba_levers_ral_alma_fp64.
  5. Lint as CI; logical local commits.
  6. RAL: HPCPullPyAuto, verify PyAutoArray >= e281abf3 + floors, bundle the branch to /mnt/ral/jnightin/autolens_profiling_wt/interferometer-mesh-numba-p2, copy datasets + May-18 adapt caches from the p1 RAL worktree, submit.
  7. Next session: pull, notes, README dashboards, ship_workspace.

Key Files

  • scripts/misc/likelihood_breakdown/interferometer_pixelized_numpy.py — the NumPy / numba harness
  • scripts/interferometer/likelihood_breakdown/{delaunay,pixelization}_numba.py — thin cells
  • hpc/batch_cpu/submit_breakdown_interferometer_* — RAL CPU submits
  • results/breakdown/interferometer/**/*_numba_* — rows
  • results/notes/numba_interferometer_verdict.md, results/notes/interferometer_mesh_cpu_breakdown_2026_09.md — notes

Original Prompt

Click to expand starting prompt

Interferometer likelihood campaign 3/3 — phase 2: numba vs FFT CPU crossover + CPU lever list

Type: research
Target: autolens_profiling
Repos:

  • autolens_profiling
    Themes:
  • interferometer
  • numba-cpu
  • likelihood-profiling
    Difficulty: medium
    Autonomy: supervised
    Priority: high
    Status: formalised
    Consequence: glance
    Witness: for each mesh (Delaunay-1500, rectangular 39²) the numba / NumPy-FFT full-call ratio from the RAL CPU crossover rows crosses 1 between two measured alma mask radii (one row < 1, the next > 1), each row recording nnz/col and masked pixels; and every RAL CPU numba row on PyAutoArray main >= e281abf3 reads evaluations_per_figure_of_merit {1, 1} with the sma prior-median figure of merit unchanged against the pins -3162.627234657415 (Delaunay) / -3168.595092417778 (rectangular).
    Review-minutes: 8
    Lane: local-dev
    Epic: interferometer-likelihood-campaign
    Filed: 2026-09-27
    Issued: 2026-09-27
    Issue: (this issue)
    Campaign: draft/research/autolens_profiling/interferometer_mesh_breakdown_numba_cpu_decision_matrix.md

Phase 2 of the campaign prompt above (retained in draft/ as the campaign intent; its
campaign contract and #235 discipline govern). Plan approved by the human 2026-09-27. Folds in
draft/research/autolens_profiling/interferometer_sparse_cache_after_measurement.md (retired
on filing; its content is carried verbatim under "Folded in" below).

Context

Phase 1 (autolens_profiling#328, ea2711d9) landed the library-dispatch harness
scripts/misc/likelihood_breakdown/interferometer_pixelized_numpy.py with --mask-radius, and
RAL CPU rows at r3.5: numba / FFT full-call ratio 0.25 sma Delaunay (nnz/col 6.2), 0.47 alma
Delaunay (29.1), 0.62 alma rect (40.4), 1.52 alma_high Delaunay (117.6), 2.05 alma_high rect
(161.9). Since then PyAutoArray#582 (main e281abf3) made curvature_matrix / data_vector
cached_propertys on the sparse inversions: in phase 1 every NumPy figure_of_merit evaluated
F and D twice (the reconstruction and fast_chi_squared), so both arms' full calls drop and the
ratios shift. The phase-1 harness counter wraps property.fget, which breaks on the autonerves
CachedProperty (it has .func, no .fget).

From the phase-1 F-alone sub-rows, numba F scales as nnz x masked pixels and FFT F as the
extent area, so at a fixed pixel scale the F ratio scales with nnz/col alone: predicted
crossover nnz/col ~70 (Delaunay, ~r5.4 at alma) and ~71 (rect, ~r4.6) — above the packaged
gate 60.0, near the #226 rect ~77. The sweep measures it.

What

  1. Counter fix (fold-in) — the cached_property-aware call counter (diff below) plus a
    unit test; the F-alone / D-alone sub-rows pop the cached value before each repeat so they
    time the computation, not a dict lookup.
  2. Crossover sweep — numba vs NumPy FFT, both meshes, alma at r2.0 / 3.5 / 5.0 plus the
    radii that bracket the measured crossover (chosen from a 2-3 instance laptop calibration
    probe on the cached code; candidates r4.25 / r6.0), alma_high r3.5 and sma r3.5 (the
    fold-in's re-run). Every row records nnz/col (re-derived in situ, incl. rect), masked
    pixels, extent, and the phase-1 row it replaces (previous_row) for the before/after
    delta. The adapt image is the May-18 lensed_source.fits cache (md5 recorded; a missing
    cache at a non-preset radius is a hard error, never a silent regeneration).
  3. CPU lever arms (separate RAL job, alma r3.5 both meshes, headline rows untouched):
    prange kernel at NUMBA_NUM_THREADS 1 / 2 / 4 (F alone + implied full call), fnnls
    warm-start memo on vs off on the iid stream and a local-walk stream, Cholesky-reuse check
    (reused log-det vs a fresh dense Cholesky: time + agreement), kernel_index_arrays
    marshalling split into its instance-independent part (extent index) vs the per-instance
    CSR / CSC build. MGE+mesh numba route: static read only (never routed), in the lever list.
  4. RAL CPU submits (gpu partition, no --gres, 1 thread pinned except the lever job's
    declared numba pool) with WALL-BASIS rows; check_submits.py --check green.
  5. Notes (after the RAL rows land) — new in-situ crossover section in
    results/notes/numba_interferometer_verdict.md (confirm 60 / ~77 or file the PyAutoArray
    general.yaml retune prompt); results/notes/interferometer_mesh_cpu_breakdown_2026_09.md
    with ranked levers (step / bound / gain) and one draft prompt per worthwhile lever; README
    dashboards regenerated.

Verification

  • Local sma smoke of every new arm; counter unit test green; {1, 1} counts locally.
  • Repo lint as CI: ruff, ruff format --check, build_readme.py --check,
    check_submits.py --check, pytest scripts/misc/test/, smoke scripts.
  • RAL: HPCPullPyAuto so the mirror equals the local mains (PyAutoArray >= e281abf3), pip freeze
    vs floors (numba, nufftax); jobs 0 Tracebacks; JSON source_revisions match the mains.

Out of scope

A100 mask-radius jobs (phase 3), the decision matrix (phase 4), any library edit (a gate
retune is filed as a prompt, not made here).

Folded in: interferometer_sparse_cache_after_measurement.md (verbatim)

Retired from draft/research/autolens_profiling/ on filing phase 2 (2026-09-27).

Witness: RAL CPU numba rows at sma / alma / alma_high, both meshes, measured on PyAutoArray main at or after e281abf3, show evaluations_per_figure_of_merit {1, 1}. The full call drops by roughly the redundant share. The figure of merit is unchanged against the pins -3162.627234657415 / -3168.595092417778.

What

  1. Apply the harness counter fix below to
    scripts/misc/likelihood_breakdown/interferometer_pixelized_numpy.py. The current counter
    wraps each attribute in property(... .fget), and that breaks on cached_property, which
    has no .fget. The fix unwraps .func and re-wraps the counter in the original descriptor
    type. The "F alone" / "D alone" sub-rows also have to pop the cached value before each repeat.
    Without that, they time a dict lookup instead of the computation.
  2. Re-run the RAL CPU numba breakdown rows on merged PyAutoArray main (at or after e281abf3):
    sma, alma and alma_high, for both meshes. The result paths are
    results/breakdown/interferometer/{,sma/,alma_high/}*_numba_hpc_ral_cpu_fp64.json.
  3. Regenerate the README dashboards (build_readme.py), then record the before/after full-call
    deltas.

Harness counter fix

Taken verbatim from PyAutoLabs/PyAutoArray#581 (comment):

diff --git a/scripts/misc/likelihood_breakdown/interferometer_pixelized_numpy.py b/scripts/misc/likelihood_breakdown/interferometer_pixelized_numpy.py
index de7d80f..516ec3a 100644
--- a/scripts/misc/likelihood_breakdown/interferometer_pixelized_numpy.py
+++ b/scripts/misc/likelihood_breakdown/interferometer_pixelized_numpy.py
@@ -89,6 +89,7 @@ is the headline (``steps`` / ``total_step_by_step``), the FFT arm is under
 
 from __future__ import annotations
 
+import functools
 import gc
 import json
 import os
@@ -409,13 +410,15 @@ def run(
             (InversionInterferometerSparse, "data_vector"),
         ):
             original = cls.__dict__[name]
+            _fn = original.fget if isinstance(original, property) else original.func
 
-            def getter(self, _original=original, _name=name):
+            @functools.wraps(_fn)
+            def getter(self, _fn=_fn, _name=name):
                 counts[_name] += 1
-                return _original.fget(self)
+                return _fn(self)
 
             patched.append((cls, name, original))
-            setattr(cls, name, property(getter))
+            setattr(cls, name, type(original)(getter))
         try:
             fom = float(fit_from(median_instance, arm).figure_of_merit)
         finally:
@@ -530,8 +533,8 @@ def run(
         inv = fit_from(median_instance, arm).inversion
         mapper = inv.cls_list_from(cls=Mapper)[0]
         rows_arm = {
-            "F alone (curvature_matrix_diag)": repeat_s(lambda inv=inv: inv.curvature_matrix_diag),
-            "D alone (data_vector = Lᵀ d~)": repeat_s(lambda inv=inv: inv.data_vector),
+            "F alone (curvature_matrix_diag)": repeat_s(lambda inv=inv: (inv.__dict__.pop("curvature_matrix_diag", None), inv.curvature_matrix_diag)),
+            "D alone (data_vector = Lᵀ d~)": repeat_s(lambda inv=inv: (inv.__dict__.pop("data_vector", None), inv.data_vector)),
         }
         if arm == "numpy_fft":
             rows_arm["Sparse triplets alone (extent grid)"] = repeat_s(

Done when

The witness holds. The before/after numbers must be recorded in the breakdown JSONs and in the
campaign's notes.

Activity

  1. Jammy2211 commented on Sep 27, 2026

    @Jammy2211
    ContributorAuthor

    Progress (2026-09-27): implementation done, RAL CPU jobs running

    Branch feature/interferometer-mesh-numba-p2 has 2 local commits, not pushed yet:

    • 5d806c4: the harness changes.
      • The fold-in counter fix makes the counter aware of cached_property. The F-alone and D-alone sub-rows now pop the cached value before each repeat.
      • Adds an adapt_image md5 guard. If the cache is missing at a non-preset radius, the run fails instead of regenerating it.
      • Adds previous_row, which records the before/after delta against the row being replaced.
      • Adds opt-in --levers threads,memo,logdet,marshal.
      • Adds unit tests.
    • 92a2061: the RAL CPU crossover arrays and the alma lever submit.

    Local checks (laptop, library mains, PyAutoArray e281abf3)

    • sma, both meshes: evaluations_per_figure_of_merit is {1, 1}. The pins hold: Delaunay is 2e-7 nat off -3162.627234657415, and rect matches -3168.595092417778 exactly. numba vs FFT differ by 0 nat. All four levers run.
    • Calibration probe, alma r5.0, 3 instances, laptop load ~4.4, cached code:
    Mesh nnz/col numba / FFT full call
    Delaunay 55.6 1.04
    rect 82.7 1.08
    • Estimated cached ratios at r3.5 are ~0.40 (Delaunay) and ~0.72 (rect).
    • Chosen radii: alma r2.0 / 3.5 / 4.25 / 5.0 / 6.0, plus sma r3.5 and alma_high r3.5, for both meshes. This brackets any crossover between r3.5 and r6.0 with two measured points.
    • Lint as CI is green: ruff, format, build_readme.py --check, check_submits.py --check, pytest (944 passed) and the smoke scripts.

    RAL (the mirror matches the local mains; numba 0.65.1, nufftax 0.6.1; the three May-18 adapt caches have matching md5s). Worktree: /mnt/ral/jnightin/autolens_profiling_wt/interferometer-mesh-numba-p2.

    • 358985: Delaunay crossover array, tasks 0-6.
    • 358986: rect crossover array, tasks 0-6.
    • Both arrays run on euclid-ral-gpu-1.
    • 359000: lever job, alma r3.5, both meshes. It runs on the idle euclid-ral-gpu-2 so the thread-scaling timings are clean. The original lever job, 358987, was cancelled because it landed on the busy node.

    Next: pull the results, check the witness, write the verdict-note crossover section and interferometer_mesh_cpu_breakdown_2026_09.md (ranked levers plus draft prompts), regenerate the README, then /ship_workspace.

  2. Jammy2211 commented on Sep 27, 2026

    @Jammy2211
    ContributorAuthor

    Shipped — PR #333 is open, awaiting a human /prm

    All RAL CPU jobs completed with 0 Tracebacks: 358985 (Delaunay crossover), 358986 (rect crossover) and 359000 (levers). The rows are committed.

    • Crossover: nnz/col ≈ 66 (Delaunay) and ≈ 72 (rect), each bracketed by two measured alma radii.

      • Delaunay: r5.0 0.886 → r6.0 1.169.
      • rect: r4.25 0.749 → r5.0 1.225.
    • Gate: 60 routes every measured cell to the faster arm. A single gate of about 70 fits both meshes best; a retune prompt is drafted, low priority.

    • Caching fix (PyAutoArray#582): every NumPy full call drops to 0.51–0.88× of its phase-1 value. The counts go from F 2× / D 4× per evaluation to {1, 1}.

    • Levers, in rank order:

      1. fnnls memo guard. On the local walk the solve drops to 0.68× (Delaunay) and 0.13× (rect). On the iid stream it is 2.17× slower for Delaunay.
      2. Gate retune.
      3. prange load balance. Delaunay reaches only 1.02× at 2 threads.
      4. Cholesky reuse on the edge-zeroed rect log det, currently missed (at most 2.7 % of the call).

      Marshalling (0.4 % of the call) and an MGE+mesh numba route are not levers.

    • Follow-ups filed in Mind as drafts (Mind f91500ed):

      • draft/research/autolens_profiling/interferometer_nnls_memo_scattered_stream_guard.md
      • draft/feature/autoarray/interferometer_numba_gate_retune_70.md
      • draft/feature/autoarray/interferometer_direct_conv_prange_load_balance.md
      • draft/feature/autoarray/edge_zeroed_log_det_cholesky_reuse.md

    Full notes: results/notes/interferometer_mesh_cpu_breakdown_2026_09.md and numba_interferometer_verdict.md §8.

  3. added a commit that references this issue on Sep 27, 2026
  4. Jammy2211 commented on Sep 27, 2026

    @Jammy2211
    ContributorAuthor

    Shipped

    PR #333 merged (merge f075a6c5, 2026-09-27) — interferometer mesh numba CPU campaign, phase 2.

    What shipped

    • Crossover measured on the cached library: Delaunay nnz/col ~66-67, rectangular ~72-73 (bracketed: Delaunay r5.0 0.886 / r6.0 1.169; rect r4.25 0.749 / r5.0 1.225).
    • Gate 60 routes every measured cell correctly; single-gate minimax is ~70 (retune filed as a draft).
    • Caching fix confirmed on RAL (0.5-0.6x at alma / alma_high).
    • alma baseline: numba 1.26 s vs FFT 2.59 s (Delaunay), 1.83 s vs 2.94 s (rect).
    • Lever ranking: fnnls memo guard, gate retune, prange load balance, rect edge-zeroed log-det Cholesky miss. Not levers: marshalling, MGE+mesh route, FFT size (already drafted).

    Follow-ups filed (PyAutoMind drafts)

    • draft/research/autolens_profiling/interferometer_nnls_memo_scattered_stream_guard.md
    • draft/feature/autoarray/interferometer_numba_gate_retune_70.md
    • draft/feature/autoarray/interferometer_direct_conv_prange_load_balance.md
    • draft/feature/autoarray/edge_zeroed_log_det_cholesky_reuse.md

    Caveat: the phase-1 alma N-sweep rows are still on the uncached library.

    Next: phase 3 (A100 mask-radius sweep), then phase 4 (decision matrix).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions