Repository navigation
Description
Overview
Phase 3 (#267) took the production numba CPU fixed-light call from 413.3 to 230.0 ms, leaving two dominant sites: sparse_numba.curvature_matrix at 87.8 ms (38 %) and solver.fnnls_cholesky at 61.1 ms (27 %). This phase takes those two as levers 4a and 4b. Lever 4a is a measurement, not a rewrite: curvature_matrix_via_sparse_operator_from already dispatches between a two-stage kernel and a direct quadruple loop on a pixel-count cap that was calibrated on the HST rectangular fiducial and never measured on the Delaunay fixed-light cell. Lever 4b is A′ — permute the active columns last and take one potrf, measured at 41 ms against fnnls_cholesky's 61.1 ms during lever 3's design, at the cost of a 5e-13 perturbation to the passive factor, so it needs a witness definition before it gets a kernel.
Plan
- Cap fix first. The cell's
MAX_INSTRUMENTATION_OVERHEAD = 1.03is a fixed ~6–8 ms cost read as a ratio; it killed RAL job 343355 at 224 ms and will kill anything shorter. Restate it as a millisecond budget before measuring anything. - Two waves, sequential PRs, never stacked (the research: fixed-light follow-up round 3 — the non-solver levers on numba CPU and the A100 together (phase 3) #267 lesson: stacked profiling PRs go red-by-construction once the library moves). Wave A ships and merges before wave B starts.
- Prototype in
autolens_profiling, promote conditionally. Kernels are prototyped behind the existing injection seam and A/B'd in one process as extra routes of thefixed_light_numba.pycell (the phase 2–3 pattern); a PyAutoArray change lands only when a kernel is proven, as its own small PR. - Wave A — overhead gate as an ms budget, a curvature-kernel injection seam with three kernels (
two_stagecontrol,direct,two_stage_touched), cell routesb_direct/b_touched, an s4 witness, a RAL CPU-only leg, the note; then a conditional PyAutoArray PR. - Wave B (after wave A merges) — the 4b witness definition first, then
fnnls_cholesky_permutedbehind lever 3's solver seam, then its own A/B and its own conditional PyAutoArray PR. - Verdict rule, written before the run: a kernel is a lever if it beats route
bby ≥ 5 % on the whole call with the ABBA gate PASS. Below that the answer is "two-stage is right on Delaunay too" and the PyAutoArray work shrinks to the docstring fix. - The docstring fix at
inversion_imaging_numba_util.py:781ships regardless of the numbers.
Detailed implementation plan
Affected Repositories
- autolens_profiling (primary) — the cell, the kernel seam, the witness, the submit, the tests, the note.
- PyAutoArray (conditional) — the docstring fix always; a kernel/dispatch change only if a prototyped kernel beats
bby ≥ 5 %.
Branch Survey
| Repository | Branch | Dirty | Claim |
|---|---|---|---|
| autolens_profiling | main @ cea41bb | clean | claimed by hst-gpu-residue-p2 (#273, feature/hst-gpu-residue-p2) |
| PyAutoArray | main @ 91240e43 | clean | unclaimed (delaunay-area-magnification-audit worktree exists on another branch, no active.md conflict) |
worktree_check_conflict fixed-light-numba-s4 autolens_profiling PyAutoArray exits 1 on the p2 claim. Its branch touches fixed_light_trace.py, host_callback_probe.py, library_solver_injection.py, test_fixed_light_cell.py, test_fixed_light_vmap_submit.py, a vmap submit; this task touches none of those. Shared generated surfaces: README.md (regenerate after whichever merges second) and one hpc/README.md route row. Waived on the human's approval 2026-09-17, fresh parallel worktree off origin/main — the same call p2 itself recorded against #267.
Suggested branch: feature/fixed-light-numba-s4 (in both repos). Worktree: ~/Code/PyAutoLabs-wt/fixed-light-numba-s4/ (autolens_profiling first; PyAutoArray added via worktree_add_repo when step 8 starts).
Implementation Steps
Wave A — cap fix + lever 4a (autolens_profiling PR, then optional PyAutoArray PR)
- Cell: overhead gate as a millisecond budget (
scripts/imaging/likelihood_breakdown/fixed_light_numba.py:409-424,:1888-1894,:2014-2020, JSON:1965,:2249). Replace the ratio gate withMAX_INSTRUMENTATION_OVERHEAD_MS = 12.0(= 1.03 × 400 ms, the calibration the ratio encoded; measured fixed cost 6–8 ms) onoverhead_ms = (ratio − 1) × mean clean call. Keep the ratio recorded, keepMIN_BLOCKS_FOR_OVERHEAD_ASSERT = 3, record both ingate_thresholds. Updatetest_fixed_light_numba.py::test_the_overhead_gate_is_repeat_conditionaland add one test that a 1.037 ratio at 224 ms PASSES and a 1.037 at 400 ms FAILS. - Curvature-kernel injection seam — new
scripts/misc/likelihood_breakdown/fixed_light_numpy_kernels.py, mirroringfixed_light_numpy_solvers.numpy_solver_injected(:371): a context managercurvature_kernel_injected(kernel, *, label)that rebindsinversion_imaging_numba_util.curvature_matrix_via_sparse_operator_from(attribute access fromsparse.py:385, so rebinding works), counts calls, restores by identity. Three kernels it can install:two_stage— library dispatcher withtwo_stage_max_pix_pixels=10**9(what production runs; control);direct— dispatcher withtwo_stage_max_pix_pixels=0(library's own direct kernel);two_stage_touched— a numba copy of the two-stage kernel whose stage 2 scatters only over the indices stage 1 touched (tracked in a small index list) and zeroes only those. Same per-element summation order ⇒ expected bit-identical totwo_stage(adding exact zeros is a no-op); asserted, not assumed.
- Cell routes — add
b_directandb_touchedtoALL_ROUTE_KEYS(:223; excluded fromDEFAULT_ROUTE_KEYSliked_np), both_ROUTES_LIKE_B, entered outsidecall_accounting.installexactly asd_npis (:1785-1789,:2027); JSONinjected_kernelblock per row (kernel dotted name, n_calls > 0 hard-asserted, mirroringinjected_solver:2030-2047). One process, rowsb,b_direct,b_touchedunder the ABBA harness = the A/B. - Witness — new
scripts/imaging/likelihood_breakdown/fixed_light_numba_s4_witness.py(CLI as the l3 witness:--mesh --dataset --threads --config-name, smoke exit,verdictPASS/FAIL, non-zero exit on FAIL): W1 each injected kernel fires once perfigure_of_merit; W2curvature_matrixdirect vs two-stage max-rel ≤ 1e-9 and touched vs two-stage bit-identical; W3 log evidence ≤ 1e-9 relative across the three; W4 site medians of 20 for the three kernels on identical inputs (RECORDED). - RAL submit — new
hpc/batch_cpu/submit_breakdown_imaging_fixed_light_numba_s4_delaunay_ral_hst_fp64(single library, one arm:--routes b,b_direct,b_touched --threads 1 --n-repeats 64 --nnls-warm-start on --instances iid,gpupartition CPUs-only, thread env pins and NUMBA cache dir as the l3 submit, then the witness) with a# WALL-BASIS:block (check_submits.pycontract; the l3 submit has none). Name deliberately avoids the_numba_levers_infix (that family's test asserts two library arms) and lives inbatch_cpu(not globbed bytest_fixed_light_cell.py). Static testscripts/misc/test/test_fixed_light_s4.py: kernels agree on a tiny fixture (reusetest_fixed_light_numba.py'stiny/tiny_s3_pairfixtures), touched bit-identical, seam restores by identity, submitbash -n+ runs scripts that exist. - Run + harvest —
hpc/sync push-submit-style submission from this CLI session, poll, pullresults/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_s4_*JSON/PNG + witness JSON. Verdict rule, written before the run: a kernel is a lever if it beatsbby ≥ 5 % on the whole call with the ABBA gate PASS; below that the answer is "two-stage is right on Delaunay too" and item 7 shrinks to the docstring. - Note + dashboards — new
results/notes/fixed_lens_light_s4_2026_09.md(Scope / Provenance / Gate roll-up / 4a headline / decomposition / verdict / Next, the levers-note shape),build_readme.pyregenerated;hpc/README.mdroute row. - PyAutoArray PR (wave A, conditional) — always: fix the stale docstring at
inversion_imaging_numba_util.py:781(names aCURVATURE_TWO_STAGE_COST_RATIO_THRESHOLDthat does not exist; code branches onpix_pixels). Ifdirectwins on Delaunay: replace the pixel-count cap with a geometry rule (mean mappings per data pixelu0frompix_lengths, threshold set from the measurement), keepingtwo_stage_max_pix_pixelsas the test override. Iftwo_stage_touchedwins: it becomes the two-stage body (bit-identical, sotest__…two_stage_from__matches_reference_kernel:829and the dispatch test:947stand; add a touched-vs-untouched bit-identity test). Pending-release, library CI green, then the profiling note's "library state" line updated in the same wave A PR before merge.
Wave B — lever 4b, A′ (after wave A merges)
- Witness design first, as a note section + test, no kernel yet — define "same active set at 5e-13" on the cell's seeded draw set (
--instances iid, the phase-2 graded draws): per draw, active-set Jaccard vs the libraryfnnls_cholesky(expect 1.0; report every draw < 1.0 with the KKT residual of both solutions), Δ log evidence in nats (gate ≤ 1e-9 relative like W3), PDIP fallback count unchanged,solver_statsiteration counts. Written intofixed_lens_light_s4_2026_09.md"4b witness" and reviewed by the human before step 10. - Kernel —
fnnls_cholesky_permutedinfixed_light_numpy_solvers.pynext tonnls_factor_reuse: the warm-start factorisation atfnnls.py:127-137(ZTZ[P_inorder][:, P_inorder], double fancy-index) and the per-iteration row gather:199-201replaced by one symmetric permutation ofZTZto passive-first order and onepotrfon the leading block; outer loop:185-234otherwise unchanged;stats/factorpublished in the same shape so lever 3'slog_det_from_passive_cholesky_fromstill reads it. Injected as routed_permthroughnumpy_solver_injected(signaturesolver(ZTZ, ZTx, *, stats),:453-458). - A/B + witness on RAL — same submit family, rows
bvsd_perm,--n-repeats 64; witness scriptfixed_light_numba_s4b_witness.pyimplementing step 9's metrics. Verdict: lever if ≥ 5 % on the whole call AND the witness passes on every draw. Promote to PyAutoArrayfnnls_choleskyonly then, as its own PR. - Close: note "Phase 4 — the whole campaign" table chaining from 413.3 ms;
/prm.
Key Files
autolens_profiling (wave A): scripts/imaging/likelihood_breakdown/fixed_light_numba.py, new scripts/misc/likelihood_breakdown/fixed_light_numpy_kernels.py, new scripts/imaging/likelihood_breakdown/fixed_light_numba_s4_witness.py, new hpc/batch_cpu/submit_breakdown_imaging_fixed_light_numba_s4_delaunay_ral_hst_fp64, new scripts/misc/test/test_fixed_light_s4.py, scripts/misc/test/test_fixed_light_numba.py, new results/notes/fixed_lens_light_s4_2026_09.md, results JSON/PNG, README.md (generated), hpc/README.md.
PyAutoArray: autoarray/inversion/inversion/imaging_numba/inversion_imaging_numba_util.py (+ test_autoarray/.../test_inversion_imaging_util.py if a kernel is promoted).
Verification
- Local (laptop, 1 thread):
pytest scripts/misc/test/test_fixed_light_s4.py scripts/misc/test/test_fixed_light_numba.py;ruff check . && ruff format --check .;build_readme.py --check;check_submits.py --check; the cell with--routes b,b_direct,b_touched --n-repeats 6and the witness run to completion locally before any RAL submit. - RAL: one job for 4a (cell + witness), ABBA gate PASS both ways,
overhead_msrecorded; the note quotes control/feature ms, site ms, and the W2/W3 numbers. - Pins: log evidence ≤ 1e-9 relative on every row; touched kernel bit-identical to two-stage;
log_likelihoodnot compared across processes. - Ship:
/ship_workspacefor the profiling PR (Heart RED ack),/ship_libraryfor the PyAutoArray PR;/prmeach in turn, never stacked.
Original Prompt
Click to expand starting prompt
Fixed-light numba CPU round 4 — the curvature-matrix kernel A/B on Delaunay, then permute-active-last
Type: research
Target: autolens_profiling
Repos:
- autolens_profiling
- PyAutoArray
Themes: - profiling
- pixelization
- cpu
- numba
- inversion
Difficulty: large
Sizing-note: the intake sizing faculty derived too-large (score 12); large is kept — the two levers are
ordered and 4a is a measurement of two kernels that already exist; if it must be split, split between
lever 4a and lever 4b, never between a lever and its witness.
Autonomy: human-required
Priority: high
Status: formalised
Epic: fixed-lens-light-numba-cpu
Phase: 4
Consequence: judge
Witness: On HST Delaunay N=1500 numba CPU (RAL gpu partition CPUs-only, 1 thread), each lever carries a
before/after whole-call table with thread and backend recorded per leg; lever 4a returns the library's log
evidence to <= 1e-9 relative; lever 4b keeps the active set on every seeded draw within the witness's declared
tolerance with the PDIP fallback count unchanged; the note chains the cumulative from 413.3 ms.
Review-minutes: 30
Unattended: never
Filed: 2026-09-16
Original request (verbatim)
and you think theres nowhere else tp gp wotj numba? without digging through deeper stuff is level 4 not low hanging
[...] i think 1 and 2 are worth doing
Context
Phase 3 (#267, complete/2026/09/fixed-light-numba-levers.md) took the production numba CPU
fixed-light call from 413.3 to 230.0 ms. Its residue, from the lever-3 decomposition
(results/notes/fixed_lens_light_levers_2026_09.md, "Next"): sparse_numba.curvature_matrix
87.8 ms (38 %), solver.fnnls_cholesky 61.1 ms (27 %), delaunay.triangulation 18.9 ms (8 %),
everything else under 9 ms a site. This phase inserts ahead of the renumbered memo / scaling /
verdict phases of fixed-lens-light-numba-cpu, which become 5, 6 and 7. Two levers, measurement
first, in order.
Lever 4a — A/B the two existing curvature kernels on Delaunay (low-hanging)
curvature_matrix_via_sparse_operator_from (PyAutoArray
inversion/inversion/imaging_numba/inversion_imaging_numba_util.py) dispatches on a pixel-count cap
(two_stage_max_pix_pixels = CURVATURE_TWO_STAGE_MAX_PIX_PIXELS) between the two-stage kernel and
the direct quadruple loop. The two-stage docstring itself says it wins for bilinear rectangular
(u0 = 4, 2.9x at the HST rectangular fiducial) and can lose for barycentric Delaunay (u0 ~ 1.55),
because stage 2 does a dense pix_pixels-long AXPY per mapping of every data pixel and then
re-zeroes the full accumulator, regardless of how few indices stage 1 touched. The choice was
never measured on the Delaunay fixed-light cell.
- A/B the two existing kernels on the HST Delaunay N=1500 fixed-light cell (route b, memo ON):
RALgpupartition CPUs-only, 1 thread across numba and BLAS, the research: fixed-light follow-up round 3 — the non-solver levers on numba CPU and the A100 together (phase 3) #267 two-arm harness with a
private merge-base PyAutoArray on PYTHONPATH as control,--n-repeats 64. The direct kernel is
already reachable by passingtwo_stage_max_pix_pixels=0; no library change is needed for the
measurement. - If neither pure form wins, a touched-index variant of stage 2: record the indices stage 1
touched, scatter only over them, zero only them. Same inputs, same outputs, same
halved-diagonal /A + A.Tcontract. - Fix the stale dispatcher docstring regardless: it names
CURVATURE_TWO_STAGE_COST_RATIO_THRESHOLD, the code branches onpix_pixels.
Pins: the kernels agree to floating-point reassociation (~4e-13 measured), log evidence <= 1e-9
relative, log_likelihood not comparable across arms.
Lever 4b — A-prime: permute the active columns last, one potrf
Lever 3's design measured the permuted factorisation at 41 ms against fnnls_cholesky's 61.1 ms,
reading ~15-20 ms more by folding both fancy-index copies and the second pass away. The cost: the
passive factor is perturbed at 5e-13, which reaches the active set's knife-edge inclusion
decisions, so the solve is no longer byte-identical and lever 3's cleanest property is given up.
- Witness design FIRST: what "the same active set" means at 5e-13 — active-set Jaccard across the
seeded graded draw set, evidence delta in nats, PDIP fallback count unchanged. Written down and
agreed before a kernel exists. - The kernel, on the numpy/numba path only (
fnnls_cholesky), behind the same seam lever 3 used. - The A/B on the same cell and host, control = lever 4a's merged state.
Cell prerequisite (before either lever)
The harness's max_instrumentation_overhead_ratio = 1.03 was calibrated on a ~400 ms call; its
fixed cost does not shrink with the call (1.0147 at 413 ms, 1.0366 at 224 ms) and it killed RAL
job 343355. Fix it in the cell before measuring: scale the cap with call length, or require a
minimum block count, or state it as a per-call millisecond budget (note "Next" item 6).
Out of scope
fnnls algorithm changes beyond A-prime (phase 2 closed the solver round); the edge-zeroed
generalisation and the covariance third factorisation (zero gain on the production cell); the
delaunay.triangulation / find_simplex site (a separate candidate); the JAX path (both log-det
levers proven CPU-only, the A100 has no fnnls factor to read); route a, Euclid, rectangular meshes,
the source-pixel sweep, the sparse-operator/profile-subtracted-image bug.
Witness
On HST Delaunay N=1500 numba CPU, each lever carries a before/after whole-call table with thread
and backend settings recorded per leg; 4a returns the library's log evidence to <= 1e-9 relative;
4b keeps the active set on every seeded draw within the witness's declared tolerance and the PDIP
fallback count unchanged; the note carries both tables and the cumulative chain from 413.3 ms.
Activity
Jammy2211 commentedon Sep 17, 2026
Wave A — laptop verification green, branch pushed, RAL job 343394 submitted (2026-09-17)
Branch
feature/fixed-light-numba-s4pushed atc7b72f6(six commits onorigin/main: e0ca612 ms-budget overhead gate, f88b9e0 curvature-kernel seam, 8998ec9 routesb_direct/b_touched, 960db5d s4 witness, 635a83d batch_cpu s4 submit + WALL-BASIS, c7b72f6 route-table alignment).Verification block, laptop leg (1 thread):
pytest test_fixed_light_s4.py test_fixed_light_numba.py— 42 passed.ruff checkclean,ruff format --check187 files already formatted.build_readme.py --checkclean (86 versioned artifacts);check_submits.py --check3 contracts, 0 failing.--routes b,b_direct,b_touched --n-repeats 6ran end to end (exit 0,timing_status: wiring_only_not_measured— smoke config, numbers not quotable).injected_kernel.n_calls21 / 19 on the two injected rows = host-dependent steady-state warm-up (6–12 calls, discarded) + 4 × 3 ABBA blocks; the timed counts are identical (12 each). Overhead gate PASS on all three rows under the 12 ms budget;seed_source: memoeverywhere.figure_of_meritfor all three; W2 direct vs two-stage max rel 4.05e-13 (gate 1e-9), touched vs two-stage bit-identical; W3 evidence rel 1.11e-15 (direct), 0.0 (touched); W4 laptop site medians two_stage 101.5 ms, direct 114.9 ms (0.88×), touched 126.4 ms (0.80×) — RECORDED only, the verdict is the RAL whole-call row.RAL: worktree
/mnt/ral/jnightin/autolens_profiling_wt/fixed-light-numba-s4@ c7b72f6 (lensed_source.fitspre-seeded from the levers worktree, per the #273 array-guard finding);sbatchfromhpc/batch_cpu/→ job 343394,gpupartition CPUs-only, both nodes idle at submit. WALL-BASIS estimate ~2 h. Harvest, the s4 note,/ship_workspaceand the PyAutoArray docstring PR follow in this session; the verdict rule (≥ 5 % whole-call overb, ABBA PASS) is unchanged from the plan.results(fixed-light): s4 lever 4a RAL CPU A/B + witness, job 343394 (#…
docs(fixed-light): the s4 note — lever 4a verdict, two-stage is right…
docs(fixed-light): s4 note — library state names PyAutoArray#557 (#274)
Jammy2211 commentedon Sep 17, 2026
Wave A shipped to PR-open — lever 4a verdict: no lever (2026-09-17)
PRs (independent, either merge order; neither depends on the other's code):
pending-release, lint GREEN; head7fcb3f4(8 commits: ms-budget overhead gate, kernel seam, routesb_direct/b_touched, s4 witness, batch_cpu s4 submit + WALL-BASIS, RAL job 343394 artefacts, the s4 note).inversion_imaging_numba_util.py:781),pending-release, unit tests pending at write time. No kernel or dispatch change.Verdict, RAL job 343394 (
euclid-ral-gpu-1,gpuCPUs-only, one thread,--n-repeats 64, one library one process; rule: lever iff ≥ 5 % on the whole call with ABBA PASS):bbtwo-stage (production)b_directb_touchedWitness PASS: W2 direct rel 4.100e-13, touched bit-identical; W3 rel 7.385e-16; W4 site medians 85.043 / 102.052 (0.83×) / 97.019 ms (0.88×). Two-stage is right on Delaunay too (u0 = 1.604); the two-stage docstring's Delaunay prediction is refuted at this cell and #557 corrects it. Control
breproduces lever 3's 230.031 ms at +0.05 %; the campaign chain 413.301 → 230.031 ms is unchanged. Full record:results/notes/fixed_lens_light_s4_2026_09.md(Scope / Provenance / Gate roll-up / headline / decomposition / verdict / campaign / Next / Artifacts).Findings recorded in the note's Next: the submit's WALL-BASIS (7200 s) overestimated the one-arm job by ~44× (measured 162 s) — re-pin in a follow-up, not in this PR; the laptop and RAL W4 agree on the winner only, the ranking of the two losers is host-dependent; the touched variant loses because index bookkeeping costs more than the L1-resident dense zero-and-AXPY it saves.
Heart gate: RED with exactly
install verification FAILED (testpypi; checks F)andrelease validation FAILED (stage integrate)(released Colab bootstrap, unrelated); shipped to PR-open on the human's instruction against theactive.mdnote naming these two; two transient "N commit(s) behind origin" reasons were local staleness, cleared by fast-forwarding the canonical PyAutoFit/PyAutoArray mains. Merge stays with/prm.Next: human
/prmon #275 and #557; then wave B (lever 4b, A′ — witness definition first, plan steps 9–12) as a new sequential PR after #275 merges. RAL worktree/mnt/ral/jnightin/autolens_profiling_wt/fixed-light-numba-s4(job logs inhpc/batch_cpu/output|error/*.343394.*) is left for cleanup at close-out.Merge pull request #275 from PyAutoLabs/feature/fixed-light-numba-s4
Jammy2211 commentedon Sep 17, 2026
Shipped
Wave A of phase 4 (
fixed-lens-light-numba-cpu) is merged:92f1fadd): overhead gate as a 12 ms budget,fixed_light_numpy_kernels.pyseam with three kernels, routesb_direct/b_touched, the s4 witness, the batch_cpu s4 submit, RAL job 343394 artefacts,results/notes/fixed_lens_light_s4_2026_09.md.192d4b70): docstring-only; the two-stage kernel's docstring now states the real dispatch rule (pix_pixelsvsCURVATURE_TWO_STAGE_MAX_PIX_PIXELS) and records the measurement in place of the refuted Delaunay prediction. Pending release.Lever 4a verdict: no lever.
b230.149 ms,b_direct244.924 (+6.42 %),b_touched236.913 (+2.94 %), ABBA PASS on every row; witness PASS (touched bit-identical, direct 4.1e-13; evidence 7.4e-16). Two-stage is right on Delaunay too; the campaign chain 413.301 → 230.031 ms is unchanged.Wave B (lever 4b, A′) was not started under this issue. It is re-filed as
PyAutoMind/draft/research/autolens_profiling/fixed_light_numba_s4b_permute_active_last.md(issue plan steps 9–12, witness definition first) and will get its own issue. Closing this one as the wave A record; completion recordPyAutoMind/complete/2026/09/fixed-light-numba-s4.md.