Skip to content

research(fixed-light): phase 4 wave B — A-prime permute-active-last fnnls kernel A/B (numba CPU) #276

Closed

Description

@Jammy2211

Overview

Phase 4 wave B of the fixed-lens-light-numba-cpu epic — what remains after wave A (#274 / #275, PyAutoArray#557) measured lever 4a and found no lever. The production numba CPU fixed-lens-light call is 230.0 ms (lever 3, job 343356; wave A's route b reproduces it at 230.149 ms, job 343394). After sparse_numba.curvature_matrix (87.7 ms, settled), the dominant site is solver.fnnls_cholesky at 61.1 ms (27 %). Lever 3's design measured a permuted factorisation at 41 ms and read a further ~15–20 ms from option A′: symmetrically permute ZTZ to passive-first order once, take one potrf of the leading block, folding away both fancy-index copies (fnnls.py:137) and the per-iteration row gather (fnnls.py:201). The cost: the permuted factor differs from the gathered one at ~5e-13, which can reach the active set's knife-edge inclusion decisions, so the solve is no longer byte-identical. The witness is therefore designed and human-reviewed before any kernel is written.

Plan

  1. Witness first, no kernel. A "Lever 4b — the witness, written before the kernel" section in the s4 note and a witness cell that defines "same active set at 5e-13" on the seeded iid draws (active-set Jaccard, Δ log evidence in nats, fallback count, iteration counts, factor contract), run green as an identity control (library kernel injected as itself). Human reviews the definition before step 2.
  2. Seam + kernel. A fnnls_kernel_injected seam one level below the existing numpy_solver_injected, so the library's memo seed, tolerance guard, fallback and log-det factor reuse all stay the library's; fnnls_cholesky_permuted prototype beside nnls_factor_reuse; route d_perm with a P5 evidence gate; tests; local wiring run.
  3. RAL A/B + witness, one job. New batch_cpu submit (rows b, d_perm, --n-repeats 64, own WALL-BASIS pinned from job 343394's measured 162 s) plus the s4b witness; re-pin the s4 submit's WALL-BASIS (7200 → 250 s, ref 343394) in the same PR.
  4. Verdict + note + ship. Lever iff ≥ 5 % on the whole call with ABBA PASS and the witness passes on every draw; the note's "Phase 4 — the whole campaign" table chaining from 413.3 ms; build_readme; /ship_workspace; a PyAutoArray fnnls_cholesky PR only on a win (its own PR, never stacked); /prm.

Verdict rule, written before the run: lever iff d_perm beats b by ≥ 5 % on the whole call under the cell's ABBA harness at --n-repeats 64 with the overhead budget PASS on both rows, AND the s4b witness verdict is PASS on every seeded draw. Neither alone promotes.

Detailed implementation plan

Affected Repositories

  • autolens_profiling (primary)
  • PyAutoArray (conditional — only if step 12 promotes the kernel)

Branch Survey

Repository Current Branch Dirty?
./autolens_profiling main (92f1fad) clean
./PyAutoArray main clean

Suggested branch: feature/fixed-light-numba-s4b
Worktree: ~/Code/PyAutoLabs-wt/fixed-light-numba-s4b/

Parallel claim: worktree_check_conflict fixed-light-numba-s4b autolens_profiling PyAutoArray exits 1 on hst-gpu-residue-p2 (#273, LIVE). #273 touches fixed_light_trace.py, host_callback_probe.py, library_solver_injection.py, test_fixed_light_cell.py, test_fixed_light_vmap_submit.py and a vmap A100 submit; this task touches fixed_light_numba.py, fixed_light_numpy_solvers.py, a new s4b witness / submit / test, the s4 note and one WALL-BASIS line of the s4 submit — disjoint. Shared generated surfaces only: README.md and one hpc/README.md row (regenerate after whichever merges second). Waived on the human's plan approval 2026-09-17, fresh parallel worktree off origin/main — the same call wave A (#274) recorded against #273.

What the exploration changed about the filed prompt

The prompt says "injected as route d_perm through the existing numpy_solver_injected seam". That seam (scripts/misc/likelihood_breakdown/fixed_light_numpy_solvers.py:371) rebinds the whole entry point inversion_util.reconstruction_positive_only_from and calls the kernel as solver(ZTZ, ZTx, stats=): (1) it never passes the memo seed — route b runs fnnls_cholesky(P_initial=memo) at 2 outer iterations, so a kernel behind it would re-seed from the dense sign and the b vs d_perm delta would measure the seed, not A′; (2) it factor.clear()s and forwards nothing, so the injected route loses lever 3's log_det_from_passive_cholesky_from fast path (~5 ms) and pays the dense log-det (~40 ms). A′'s whole win is the memo-seeded passive block, so the kernel must be a drop-in for fnnls_cholesky itself — same signature (ZTZ, ZTx, P_initial=, stats=, factor=), same stats keys (outer_iterations, inner_iterations, passive_set, n_passive, warm_start_errors), same factor keys (U_buffer, k_active, passive_set, matrix_shape; fnnls.py:267-270) — injected one level lower via a new seam fnnls_kernel_injected that rebinds the fnnls_cholesky name inversion_util resolves at inversion_util.py:424/443 (restoration by identity, counters asserted, mirrors numpy_solver_injected). numpy_solver_injected and route d_np are untouched.

Implementation Steps

Step 9 — witness design (human gate after).
Files: results/notes/fixed_lens_light_s4_2026_09.md (new section), new scripts/imaging/likelihood_breakdown/fixed_light_numba_s4b_witness.py, new scripts/misc/test/test_fixed_light_s4b.py.
Per seeded draw (--instances iid, iid_seed 263; --n-draws, default 8), each draw solved twice through the library entry point (memo ON, production seed): library kernel vs candidate bound through fnnls_kernel_injected:

check metric gate
W1 identity control candidate = library kernel → every metric exactly 0 / 1.0 hard
W2 active set Jaccard(passive_lib, passive_cand) per draw; every draw < 1.0 reported with both KKT residuals max(w[~P]), min(x[P]) expect 1.0; draws < 1.0 RECORDED with residuals — the human sets the tolerance at review
W3 evidence Δ log evidence (nats) and relative, per draw ≤ 1e-9 relative, hard
W4 fallback warm_start_fallback count and seed_source per draw identical; dense/PDIP fallback count unchanged hard
W5 iterations outer_iterations, inner_iterations, n_passive, warm_start_errors per draw, both kernels RECORDED
W6 factor contract factor keys present; log_det_from_passive_cholesky_from(matrix, **factor) vs slogdet ≤ 2e-12 nats hard

JSON results/breakdown/imaging/fixed_light_numba_s4b_witness_<config>.json with a verdict block; same configuration stamping as the s4 witness. --kernel library|permuted; in step 9 only library exists (W1 runs, the rest are defined and skipped "no candidate yet"). Tests: schema, identity control on the tiny fixture, --kernel parsing, seam restore-by-identity + raise on foreign rebinding, and a red-control (a deliberately perturbed kernel must FAIL W2/W3). Stop; present the section and the identity-run JSON; wait.

Step 10 — seam, kernel, route.

  • fixed_light_numpy_solvers.py: fnnls_kernel_injected(kernel, *, label); fnnls_cholesky_permuted(ZTZ, ZTx, P_initial=…, stats=None, factor=None): normalise P_initial as fnnls.py:95-107; perm = concat(P_inorder, active_idx); ZTZp = ZTZ[np.ix_(perm, perm)] once, ZTxp = ZTx[perm]; U = cholesky(ZTZp[:k, :k]) into an (n, n) U_buffer; repair loop verbatim; outer loop verbatim except cholinsertlast_inplace reads the permuted row; un-permute on exit (x[perm] = xp); publish stats (same keys; warm_start_errors against the original mask) and factor with passive_set = perm[P_inorder_p] (W6 guards this). Record n_perm_gathers = 1.
  • fixed_light_numba.py: route d_perm in ALL_ROUTE_KEYS, _ROUTE_DATASETS (b's), _ROUTE_LABELS, _ROUTES_LIKE_B; injection outside call_accounting as d_np does; fnnls_kernel JSON block; P5 gate P5_d_perm_equals_b_evidence_<formalism> mirroring _p4_equivalence at 1e-9 relative; route-table docstring row; defaults unchanged.
  • Witness gains --kernel permuted; W1–W6 all run.
  • Tests: permuted vs fnnls_cholesky on the tiny fixture (x to 1e-12, same passive set, factor keys, un-permutation on a non-identity seed), seam contract, submit bash -n; test_fixed_light_numba.py route-table assertions extended.
  • Local wiring: --routes b,d_perm --n-repeats 6 (untracked), witness --kernel permuted; ruff; build_readme.py --check; check_submits.

Step 11 — RAL.
New hpc/batch_cpu/submit_breakdown_imaging_fixed_light_numba_s4b_delaunay_ral_hst_fp64 (copy of the s4 submit; rows b,d_perm; then the s4b witness; # WALL-BASIS: wall: 300, source: measured-wall, ref: RAL-job-343394; gpu partition CPUs-only, --cpus-per-task=4 --mem=32gb, NUMBA_NUM_THREADS=1 + BLAS family pinned; kernel-provenance probe lines). Same PR re-pins the s4 submit's WALL-BASIS 7200 → 250, ref: RAL-job-343394. Push branch → RAL worktree /mnt/ral/jnightin/autolens_profiling_wt/fixed-light-numba-s4b → hpc/sync submit --cpu <name> → harvest 3 artefacts → check timing_status: measured, routes_selected, ABBA gates, witness verdict.

Step 12 — verdict, note, ship, close.
Note: "Lever 4b" section (rule, provenance table, gate roll-up, per-draw witness table), "Phase 4 — the whole campaign" cumulative table 413.301 → 230.031 → (4b), "Next". build_readme.py. PyAutoArray fnnls_cholesky PR only if ≥ 5 % AND witness PASS (/ship_library, library-first). /ship_workspace (Heart verdict re-read at PR-open), /prm.

Key Files

  • scripts/misc/likelihood_breakdown/fixed_light_numpy_solvers.py — nnls_factor_reuse (lever 3 prototype), numpy_solver_injected (existing seam); new fnnls_kernel_injected, fnnls_cholesky_permuted
  • scripts/imaging/likelihood_breakdown/fixed_light_numba.py — the A/B cell; route table, _p4_equivalence pattern
  • scripts/imaging/likelihood_breakdown/fixed_light_numba_s4_witness.py — the wave A witness the s4b witness mirrors
  • hpc/batch_cpu/submit_breakdown_imaging_fixed_light_numba_s4_delaunay_ral_hst_fp64 — submit template; WALL-BASIS re-pin
  • results/notes/fixed_lens_light_s4_2026_09.md — the phase 4 note (wave A verdict, 4b witness section, 4b verdict)
  • PyAutoArray/autoarray/util/fnnls.py — fnnls_cholesky (the kernel A′ mirrors; :95-107 seed normalisation, :137 gather, :201 row gather, :267-270 factor publish)
  • PyAutoArray/autoarray/inversion/inversion/inversion_util.py — reconstruction_positive_only_from (:398-487 memo/fallback), log_det_from_passive_cholesky_from (:607)

Original Prompt

Click to expand starting prompt

Fixed-light numba CPU round 4, wave B — A-prime: permute the active columns last, one potrf (lever 4b)

Type: research
Target: autolens_profiling
Repos:

  • autolens_profiling
  • PyAutoArray
    Themes:
  • profiling
  • pixelization
  • cpu
  • numba
  • inversion
    Difficulty: large
    Autonomy: human-required
    Priority: high
    Status: split out of fixed-light-numba-s4 at close-out 2026-09-17 — wave A (lever 4a, the curvature-kernel A/B) shipped in complete/2026/09/fixed-light-numba-s4.md (autolens_profiling#275, PyAutoArray#557); this is what remains.
    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), lever 4b carries a before/after whole-call table with thread and backend recorded per leg, keeps the active set on every seeded draw within the witness's declared tolerance with the PDIP fallback count unchanged, returns the library's log evidence to <= 1e-9 relative, and the note chains the cumulative from 413.3 ms.
    Review-minutes: 30
    Unattended: never
    Filed: 2026-09-17

Context

Wave A measured lever 4a and found no lever: two-stage is the right curvature kernel on Delaunay too
(results/notes/fixed_lens_light_s4_2026_09.md; control b 230.149 ms reproduces lever 3's 230.031 ms).
The remaining dominant site after sparse_numba.curvature_matrix (87.7 ms) is solver.fnnls_cholesky at
61.5 ms (27 %). Lever 3's design measured the permuted factorisation at 41 ms against it, reading ~15–20 ms
more by folding both fancy-index copies (ZTZ[P_inorder][:, P_inorder], fnnls.py:127-137) and the
per-iteration row gather (:199-201) into one symmetric permutation of ZTZ to passive-first order and one
potrf on the leading block. 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. That is why the witness comes before the kernel.

Plan (issue #274 steps 9–12, unchanged)

  1. 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 library fnnls_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_stats
    iteration counts. Written into the s4 note's "4b witness" section and reviewed by the human before step 10.
  2. Kernel — fnnls_cholesky_permuted in scripts/misc/likelihood_breakdown/fixed_light_numpy_solvers.py
    next to nnls_factor_reuse; outer loop otherwise unchanged; stats/factor published in the same shape
    so lever 3's log_det_from_passive_cholesky_from still reads it. Injected as route d_perm through
    numpy_solver_injected (signature solver(ZTZ, ZTx, *, stats)).
  3. A/B + witness on RAL — same submit family as s4 (new submit, own WALL-BASIS pinned from job 343394's
    measured 162 s, not from 343356), rows b vs d_perm, --n-repeats 64; witness script
    fixed_light_numba_s4b_witness.py implementing step 9's metrics. Verdict rule, written before the run:
    lever iff ≥ 5 % on the whole call AND the witness passes on every draw. Promote to PyAutoArray
    fnnls_cholesky only then, as its own PR.
  4. Close: the note's "Phase 4 — the whole campaign" table chaining from 413.3 ms; /prm.

Carried follow-ups from wave A

  • Re-pin the s4 submit's # WALL-BASIS: block (7200 s → measured 162 s × 1.5 ≈ 250 s, ref: RAL-job-343394)
    in the same PR that adds the s4b submit, so the family's contract is honest.
  • The hpc/batch_gpu array-submit dataset guard still checks data.fits (tracked) rather than the gitignored
    lensed_source.fits adapt cache (profiling: HST GPU residue phase 2 — matched vmap-vs-jit A100 experiment #273 finding) — unrelated to this lever, listed so it is not lost.

Out of scope

Everything wave A closed (the curvature kernel choice, the touched variant), fnnls changes beyond A′, the
JAX path, route a, Euclid, rectangular meshes, the source-pixel sweep.

Activity

  1. Jammy2211 commented on Sep 18, 2026

    @Jammy2211
    ContributorAuthor

    Development-shipping authorization — 2026-09-18

    The live user replied "yes" to the question: "May I commit, push, and open the #276 PR despite these Heart failures?" This authorizes commit, push and a pending-release PR for #276 only. Merge and release remain separate.

    Exact current Heart RED reasons:

    • install verification FAILED (testpypi; checks F)
    • release validation FAILED (stage integrate)

    Passed branch gates: 92 focused tests, both changed-cell import smokes, repository Ruff check/format, README idempotence, wall contracts, shell syntax, diff checks, and independent review CLEAN. RAL job 343397 COMPLETED 0:0; all eight identity/candidate witnesses PASS with exact reconstruction/evidence and passive-set agreement.

    Measured verdict: NO_LEVER. Production 226.772 ms, permutation prototype 228.576 ms, both ABBA gates PASS. No PyAutoArray change is proposed. The user also explicitly approved the roundoff-aware factor witness (max of 2e-12 nats and 32 floating-point spacings, plus a 1e-12 relative factor reconstruction residual) after the original threshold rejected the unchanged library.

    This branch does not repair Heart, and the override does not bypass CI or authorize a release.

  2. Jammy2211 commented on Sep 18, 2026

    @Jammy2211
    ContributorAuthor

    PR open: #277 (7483076, pending-release). The approved Heart RED override is recorded in this issue, the PR body, and Mind’s active entry and autonomy log. Validation remains 92 tests PASS, both post-commit smokes PASS, independent review CLEAN, and RAL witness PASS. Verdict: NO_LEVER; production unchanged. CI lint is running; no merge or release performed.

  3. Jammy2211 commented on Sep 18, 2026

    @Jammy2211
    ContributorAuthor

    Shipped — 2026-09-18

    PR #277 merged as3f3336ef after all head7483076 workflow runs/jobs succeeded, under the user's explicit wrap-up authorization.

    NO_LEVER: production226.772ms versus permuted228.576ms. Both ABBA gates and all eight witnesses passed;92 tests and both import smokes passed, independent review CLEAN. No PyAutoArray promotion. The CPU campaign is closing with phases1–6 complete and phase7 explicitly shelved; release obligations remain separate. Local ignored outputs are retained pending deletion approval.

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