diff --git a/hpc/batch_cpu/submit_breakdown_imaging_fixed_light_numba_levers_delaunay_ral_hst_fp64 b/hpc/batch_cpu/submit_breakdown_imaging_fixed_light_numba_levers_delaunay_ral_hst_fp64 new file mode 100755 index 000000000..12a3c1aca --- /dev/null +++ b/hpc/batch_cpu/submit_breakdown_imaging_fixed_light_numba_levers_delaunay_ral_hst_fp64 @@ -0,0 +1,251 @@ +#!/bin/bash -l +# +# 2026-09 fixed-lens-light numba LEVERS, lever 1 (autolens_profiling#267). +# +# Lever 1 replaced the two pure-Python loops in PyAutoArray's split- +# regularization assembly — `regularization_util.reg_split_np_from` (the split- +# point stencil completion) and +# `regularization_util.pixel_splitted_regularization_matrix_np_from` (the dense +# (P, P) scatter) — with numba kernels, keeping the original loop bodies verbatim +# as `_reg_split_reference` / `_pixel_splitted_regularization_matrix_reference` +# as the bit-identity ground truth. The JAX branch of both functions (`xp != np`) +# is untouched. +# +# This job is the CPU A/B row for that lever, and it is ONE job with TWO ARMS run +# back-to-back so both arms share a host, a core count and a load: +# +# CONTROL ARM PyAutoArray at 5e2bc0f4 — the merge base of the lever branch +# with main, i.e. the library WITHOUT the kernels. The pure-Python +# loops. +# FEATURE ARM PyAutoArray at bae9296e — the lever branch. The numba kernels. +# Plus the bit-identity witness (below). +# +# Each arm is phase 2's LEG D and nothing else: `fixed_light_numba.py --routes b +# --formalism sparse_numba --nnls-warm-start on --n-repeats 16 --instances iid +# --threads 1`. Route b is the S3 source-only system (the lens light converted to +# regular profiles at its solved intensities and subtracted) on the numba sparse +# operator, and the memo is ON — the library default for +# `aa.Settings(nnls_warm_start_memo=...)` is true and production leaves it unset, +# so this is what production pays. Phase 2's Leg D +# (`..._fixed_light_numba_sparse_b_warm_t1.json`, job 343311) is therefore the +# directly comparable prior row: whole call 404.597 ms with +# `inversion.regularization_matrix` at 111.501 ms exclusive. A Leg-D-shaped arm +# whose rows report `seed_source: "dense"` is a silently cold run and a FAIL, not +# a number — check it in both arms' JSONs before quoting anything. +# +# WHY A PRIVATE MERGE-BASE CONTROL RATHER THAN THE SHARED INSTALL. +# /mnt/ral/jnightin/PyAuto/PyAutoArray happens to sit at 5e2bc0f4 today, which IS +# the merge base — but "happens to sit at" is not a control arm. HPCPullPyAuto +# moves the shared install whenever anyone refreshes it, and it is read-only to +# this job by policy in any case. Both arms therefore run from private checkouts +# under /mnt/ral/jnightin/PyAuto_wt/fixed-light-numba-levers/, prepended to +# PYTHONPATH after activate.sh, and each arm PRINTS `autoarray.__file__` and its +# checkout's `rev-parse HEAD` inside the job so the SLURM log carries the +# provenance rather than this comment carrying it. The shared install's own +# revisions are echoed too, for the other four libraries, which are the same on +# both arms. +# +# Each arm runs in its OWN SUBSHELL so the PYTHONPATH prepend cannot leak into +# the next arm. An arm that inherited the other's prepend would import whichever +# checkout came first on the path and report it under the wrong label; the +# `autoarray.__file__` echo is the check that this worked. +# +# LOG-LIKELIHOOD IS NOT COMPARABLE ACROSS THE TWO ARMS. The arms are separate +# processes and nothing in this job compares their evidences: the cell has no +# cross-process comparison and there is no calibrated pin for any numba +# fixed-light configuration (`pinned_expected` is null and says so in as many +# words). A log-evidence is only ever read per-instance WITHIN one process, +# against that process's own gates (P1/P2/P3). The correctness claim for this +# lever is therefore NOT "the two arms agree on log-evidence" — it is the +# witness's W1/W2/W3, inside one process, on one system, against the retained +# reference bodies. Across the arms, compare milliseconds and nothing else. +# +# THE WITNESS (feature arm only). `fixed_light_numba_levers_witness.py` rebuilds +# the same HST Delaunay N=1500 source-only AdaptSplit system and asserts: +# W1 the reference chain reproduces `inversion.regularization_matrix` under +# `np.array_equal` (bit-identity, not a tolerance); +# W2 the interpolator's cached stencil tables are byte-identical after the +# library inversion (the kernels must not eat their input); +# W3 the fit's `figure_of_merit` is unchanged when both numpy entry points are +# monkeypatched to the references, to <= 1e-9 relative (expect exactly 0). +# It runs on the FEATURE arm because that is the arm whose matrix is in question; +# on the control arm the references ARE the library. It takes no timings, and it +# exits non-zero on a FAIL, which `activate.sh`'s in-job `set -e` turns into a +# failed job rather than a COMPLETED one with a bad witness buried in the log. +# +# SINGLE-THREAD SCOPE, unchanged from phase 2. Production for this path is +# cpu_fast_modeling.py: one single-threaded numba likelihood per process under a +# multiprocessing pool, every core carrying its own worker. Both arms run at +# --threads 1 with NUMBA_NUM_THREADS=1 and the whole BLAS family pinned to 1. +# These are per-likelihood costs a pool worker pays, NOT a threaded-likelihood +# scaling study (that is hpc/batch_cpu/submit_parallel_scaling_*). +# --cpus-per-task=4 is headroom for the one process and its imports, not a thread +# budget. The cell's own contention gate (1-minute loadavg vs os.cpu_count()) is +# what decides whether the numbers are quotable — check +# `contention.load_average_*` in BOTH JSONs, and prefer a host at load ~0. +# +# This cell imports NO JAX of its own, but jax lands in sys.modules via the first +# FitImaging regardless (recorded as jax_after_rows). There is no JAX_*/XLA_* +# configuration here on purpose. +# +# parse_known_args IGNORES unknown flags, so a checkout WITHOUT this cell's flags +# would run and silently produce a different table — check +# `configuration.routes_selected`, `n_repeats`, `nnls_warm_start_env` and +# `formalisms_selected` in each JSON before quoting anything. +# +# PER-ARM NUMBA CACHE. The two arms load their kernels from DIFFERENT source +# trees, and numba's on-disk cache keys include the source path, so one cache +# would already be safe. They get one directory each anyway: it makes the arms +# independent by construction, so neither arm's first-call compile can be served +# out of the other's cache. (The cell warms to a steady state and the compile +# lands in call 1 either way, but "either way" is not a thing a record should +# rely on.) + +# THE PARTITION THIS DECLARES, AND WHY IT IS NOT `ral`. +# +# The #SBATCH block below asks for `gpu` with FOUR CPUs and NO --gres: the gpu +# partition's two 124-core nodes used CPUs-only, leaving both A100s free for the +# GPU cells (including this lever's own A100 row, +# hpc/batch_gpu/submit_breakdown_imaging_fixed_light_numba_levers_delaunay_a100_hst_fp64). +# This is the same choice phase 2's job 343311 made, for the same reasons: +# +# `ral` is the CPU partition and it runs saturated: 21 nodes at 252/252 CPUs +# allocated and four shared nodes at 234/236, so even a 2-CPU request was +# scheduled three days out and a 4-CPU one no sooner. +# `imp` is idle and unusable: euclid-imp-compute-* do NOT mount /mnt/ral, so +# the repo, the venv, activate.sh and the private checkouts are all absent and +# the job dies in 0 s with no output files at all. +# `gpu` works: both nodes mount /mnt/ral and sat at load 0.00-0.01. +# +# IF `ral` EVER FREES UP, prefer it — it is the partition meant for this work: +# +# sbatch --partition=ral --cpus-per-task=2 +# +# Check `sinfo -p ral,gpu -N -o "%N %t %C %O"` first and submit to whichever is +# genuinely idle; the numbers only mean something on a quiet host. +# +# The -o/-e paths below are relative, so sbatch from INSIDE hpc/batch_cpu/. + +#SBATCH -J fl_numba_lever1 +#SBATCH --partition=gpu +#SBATCH --ntasks=1 +#SBATCH --cpus-per-task=4 +#SBATCH --mem=32gb +#SBATCH --time=4:00:00 +#SBATCH -o output/output.%A.out +#SBATCH -e error/error.%A.err +#SBATCH --mail-type=END,FAIL +#SBATCH --mail-user=james.w.nightingale@durham.ac.uk + +# Derive the repo root from where this was submitted (hpc/batch_cpu/../..) rather +# than hardcoding /mnt/ral/jnightin/autolens_profiling: the canonical RAL +# checkout sits on main with a dirty tree, so this runs from a worktree of the +# feature branch. +export AP_ROOT="$(cd "${SLURM_SUBMIT_DIR:-$(dirname "$0")}/../.." && pwd)" +echo "AP_ROOT=$AP_ROOT" +source $AP_ROOT/activate.sh + +# The two private PyAutoArray checkouts. Neither is the shared install and +# neither is written to by this job. +export PYAUTOARRAY_CONTROL=/mnt/ral/jnightin/PyAuto_wt/fixed-light-numba-levers/PyAutoArray_control +export PYAUTOARRAY_FEATURE=/mnt/ral/jnightin/PyAuto_wt/fixed-light-numba-levers/PyAutoArray_feature + +# One thread everywhere. NUMBA_NUM_THREADS must be in the environment BEFORE +# numba is imported; the cell also sets it and records the resolved block. +export OMP_NUM_THREADS=1 +export MKL_NUM_THREADS=1 +export OPENBLAS_NUM_THREADS=1 +export NUMBA_NUM_THREADS=1 +export MPLCONFIGDIR=/tmp/matplotlib_${SLURM_JOB_ID:-local} +mkdir -p "$MPLCONFIGDIR" +# output/ is gitignored and ${SLURM_JOB_ID} keeps concurrent jobs on the same +# shared node from fighting over one cache directory. +export NUMBA_CACHE_CONTROL=$AP_ROOT/output/numba_cache_${SLURM_JOB_ID:-local}_control +export NUMBA_CACHE_FEATURE=$AP_ROOT/output/numba_cache_${SLURM_JOB_ID:-local}_feature +mkdir -p "$NUMBA_CACHE_CONTROL" "$NUMBA_CACHE_FEATURE" + +echo "==========================================" +date +hostname +lscpu | grep 'Model name' || true +echo "cpus-per-task: ${SLURM_CPUS_PER_TASK:-unset}" +echo "loadavg: $(cat /proc/loadavg)" +echo "Cell: likelihood_breakdown/imaging/fixed_light_numba (route b, memo ON) x 2 arms" +echo "Witness: likelihood_breakdown/imaging/fixed_light_numba_levers_witness (feature arm)" +echo "Instrument: hst" +echo "Precision: fp64" +echo "Inversion path: numba sparse operator (InversionImagingSparseNumba), use_jax=False" +echo "Source mesh: Hilbert/Delaunay mesh, 1500 vertices" +echo "Regularization: AdaptSplit(inner=0.1, outer=10.0, signal_scale=0.1)" +echo "Threads: 1 (numba + BLAS family), production pool-worker scope" +echo "Thread env: OMP=$OMP_NUM_THREADS MKL=$MKL_NUM_THREADS OPENBLAS=$OPENBLAS_NUM_THREADS NUMBA=$NUMBA_NUM_THREADS" + +echo "=== source revisions (shared install, untouched — PyAutoArray is overridden per arm) ===" +for r in PyAutoNerves PyAutoFit PyAutoArray PyAutoGalaxy PyAutoLens; do + printf '%-14s %s\n' "$r" "$(git -C /mnt/ral/jnightin/PyAuto/$r rev-parse HEAD 2>&1)" +done +echo "PyAutoArray control: $(git -C $PYAUTOARRAY_CONTROL rev-parse HEAD 2>&1)" +echo "PyAutoArray feature: $(git -C $PYAUTOARRAY_FEATURE rev-parse HEAD 2>&1)" +echo "AP_ROOT rev: $(git -C $AP_ROOT rev-parse HEAD 2>&1)" +echo "AP_ROOT branch: $(git -C $AP_ROOT rev-parse --abbrev-ref HEAD 2>&1)" + +cd $AP_ROOT + +echo "==========================================" +echo "CONTROL ARM: PyAutoArray 5e2bc0f4 (merge base) — pure-Python split-reg loops" +echo " route b, sparse_numba, memo ON, threads 1, n-repeats 16, instances iid" +date +echo "loadavg: $(cat /proc/loadavg)" +( + export PYTHONPATH=$PYAUTOARRAY_CONTROL:$PYTHONPATH + export NUMBA_CACHE_DIR=$NUMBA_CACHE_CONTROL + echo "--- control arm import provenance ---" + echo " checkout HEAD: $(git -C $PYAUTOARRAY_CONTROL rev-parse HEAD)" + python3 -c "import autoarray; print(' autoarray.__file__ =', autoarray.__file__); print(' autoarray.__version__ =', autoarray.__version__)" + python3 -u scripts/imaging/likelihood_breakdown/fixed_light_numba.py \ + --mesh delaunay \ + --dataset hst \ + --formalism sparse_numba \ + --routes b \ + --threads 1 \ + --n-repeats 16 \ + --instances iid \ + --nnls-warm-start on \ + --config-name hpc_ral_cpu_fp64_fixed_light_numba_lever1_control_b_warm_t1 +) + +echo "==========================================" +echo "FEATURE ARM: PyAutoArray bae9296e (lever 1) — numba split-reg kernels" +echo " route b, sparse_numba, memo ON, threads 1, n-repeats 16, instances iid" +date +echo "loadavg: $(cat /proc/loadavg)" +( + export PYTHONPATH=$PYAUTOARRAY_FEATURE:$PYTHONPATH + export NUMBA_CACHE_DIR=$NUMBA_CACHE_FEATURE + echo "--- feature arm import provenance ---" + echo " checkout HEAD: $(git -C $PYAUTOARRAY_FEATURE rev-parse HEAD)" + python3 -c "import autoarray; print(' autoarray.__file__ =', autoarray.__file__); print(' autoarray.__version__ =', autoarray.__version__)" + python3 -u scripts/imaging/likelihood_breakdown/fixed_light_numba.py \ + --mesh delaunay \ + --dataset hst \ + --formalism sparse_numba \ + --routes b \ + --threads 1 \ + --n-repeats 16 \ + --instances iid \ + --nnls-warm-start on \ + --config-name hpc_ral_cpu_fp64_fixed_light_numba_lever1_b_warm_t1 + + echo "--- feature arm witness: lever 1 bit-identity (W1/W2/W3) ---" + date + python3 -u scripts/imaging/likelihood_breakdown/fixed_light_numba_levers_witness.py \ + --mesh delaunay \ + --dataset hst \ + --threads 1 \ + --config-name hpc_ral_cpu_fp64_lever1 +) + +echo "==========================================" +echo "loadavg: $(cat /proc/loadavg)" +echo "Finished." +date diff --git a/hpc/batch_gpu/submit_breakdown_imaging_fixed_light_numba_levers_delaunay_a100_hst_fp64 b/hpc/batch_gpu/submit_breakdown_imaging_fixed_light_numba_levers_delaunay_a100_hst_fp64 new file mode 100755 index 000000000..46c7e3518 --- /dev/null +++ b/hpc/batch_gpu/submit_breakdown_imaging_fixed_light_numba_levers_delaunay_a100_hst_fp64 @@ -0,0 +1,177 @@ +#!/bin/bash -l +# +# A100 likelihood-breakdown profile: imaging/delaunay x hst x fp64 — the +# numba-levers A/B (autolens_profiling#267, lever 1). +# +# WHAT THIS ROW IS FOR. Lever 1 replaced the two pure-Python loops in +# PyAutoArray's split-regularization assembly — `reg_split_np_from` and +# `pixel_splitted_regularization_matrix_np_from` — with numba kernels. Both +# functions are reached through a dispatch on `xp` +# (`regularization_util.reg_split_from` / `pixel_splitted_regularization_matrix_from`, +# `if xp == np: ...` then the JAX body), and ONLY the numpy branch changed. +# **So the expectation for this job is identity**, and that is the point: an A100 +# row that moved would mean lever 1 leaked out of the numpy branch. +# +# Two findings come out of this job, and neither is a speedup: +# +# (i) WHICH PATH THE GPU CELL ACTUALLY RUNS. Confirmed by reading the cell: +# `delaunay.py`'s step-11 prefix builds the mapper and calls +# `pixelization_obj.regularization.regularization_matrix_from(linear_obj=m, xp=jnp)` +# (the `upto == 11` branch of `_setup_prefix_fn`), so with +# `--regularization adapt_split` it is `AdaptSplit.regularization_matrix_from` +# -> `reg_split_from(..., xp=jnp)` -> `pixel_splitted_regularization_matrix_from(..., xp=jnp)`, +# i.e. the JAX branch, inside `jax.jit`. That branch is PyAutoArray#536's +# compacted scatter: a head scatter over the first +# `SPLIT_REG_COMPACT_WIDTH = 12` stencil columns plus an exact supplement +# for rows wider than that, budgeted by +# `SPLIT_REG_WIDE_ROW_BUDGET = 256` (both defaults in +# `regularization_util.py`, both left UNSET here, as production leaves +# them). This job's log is the record that the compacted path is what ran, +# on both arms, at the library defaults. +# (ii) THE MEASURED H ROW, control vs feature. The comparable prior row is +# `results/breakdown/imaging/delaunay_hpc_a100_fp64.json`: +# `steps["Regularization matrix (H)"]` 0.000234 s and +# `regularization_matrix_prefix_s` 0.00738 s. H is reported as a +# DIFFERENCE of two jitted prefixes (step 11's prefix minus step 6's), so +# it is small and noisy by construction; the absolute prefix is the +# sturdier number and both are quoted from both arms. +# +# THE TWO ARMS, run back-to-back in ONE job so both share a node, a GPU and a +# driver: +# +# CONTROL ARM PyAutoArray 5e2bc0f4 — the merge base of the lever branch with +# main, i.e. the library WITHOUT the numba kernels. +# FEATURE ARM PyAutoArray bae9296e — the lever branch. +# +# Both from PRIVATE checkouts under +# /mnt/ral/jnightin/PyAuto_wt/fixed-light-numba-levers/, prepended to PYTHONPATH +# after activate.sh, each in its OWN SUBSHELL so the prepend cannot leak into the +# next arm, and each printing `autoarray.__file__` plus its checkout's +# `rev-parse HEAD` inside the job. The shared install +# /mnt/ral/jnightin/PyAuto/PyAutoArray is NOT used as the control even though it +# happens to sit at 5e2bc0f4 today: HPCPullPyAuto moves it whenever anyone +# refreshes it, and it is read-only to this job by policy. Its revisions are +# echoed below for the other four libraries, which are the same on both arms. +# +# `--regularization adapt_split --split-setup --vmap-batch 16` and every +# JAX/XLA/env setting below are copied verbatim from +# `submit_breakdown_imaging_delaunay_a100_hst_fp64_adapt_split`, the job +# `delaunay_hpc_a100_fp64.json`'s row set came from, so the only difference +# between these arms and that record is the PyAutoArray revision. +# +# --regularization adapt_split al.reg.AdaptSplit(0.1, 10.0, signal_scale=0.1) +# --split-setup four-way split of the inversion-setup block +# (+ the split-point Sibson cut of params->H) +# --vmap-batch 16 batched re-timing at the Nautilus reference +# n_batch +# +# LOG-LIKELIHOOD IS NOT COMPARABLE ACROSS THE TWO ARMS: they are separate +# processes and nothing here compares their evidences. Each arm's own pinned +# drift (`pinned_drift`, the AdaptSplit log-evidence pin) is the per-arm +# correctness statement, and the numpy-branch bit-identity claim lever 1 actually +# makes is witnessed on the CPU job +# (hpc/batch_cpu/submit_breakdown_imaging_fixed_light_numba_levers_delaunay_ral_hst_fp64, +# W1/W2/W3). Across the arms, compare milliseconds and nothing else. +# +# TRAPS. `parse_known_args` IGNORES unknown flags, so a checkout without these +# flags would run and silently produce a different table — check +# `configuration` / `regularization` / `vmap` in each JSON before quoting. +# SLURM `COMPLETED` can hide a Python crash (a job whose cell died still runs the +# trailing `echo`/`date`), which is what `activate.sh`'s in-job `set -e` guard is +# for — but read the `.out` AND the `.err` anyway, and confirm both result JSONs +# exist. The -o/-e paths below are relative, so sbatch from INSIDE hpc/batch_gpu/. + +#SBATCH -J bd_del_lever1 +#SBATCH --partition=gpu +#SBATCH --gres=gpu:1 +#SBATCH --ntasks=1 +#SBATCH --cpus-per-task=4 +#SBATCH --mem=64gb +#SBATCH --time=12:00:00 +#SBATCH -o output/output.%A.out +#SBATCH -e error/error.%A.err + +export AP_ROOT="$(cd "${SLURM_SUBMIT_DIR:-$(dirname "$0")}/../.." && pwd)" +echo "AP_ROOT=$AP_ROOT" +source $AP_ROOT/activate.sh + +# The two private PyAutoArray checkouts. Neither is the shared install and +# neither is written to by this job. +export PYAUTOARRAY_CONTROL=/mnt/ral/jnightin/PyAuto_wt/fixed-light-numba-levers/PyAutoArray_control +export PYAUTOARRAY_FEATURE=/mnt/ral/jnightin/PyAuto_wt/fixed-light-numba-levers/PyAutoArray_feature + +export JAX_PLATFORM_NAME=cuda +export JAX_PLATFORMS=cuda,cpu +export XLA_PYTHON_CLIENT_PREALLOCATE=false +export JAX_ENABLE_X64=True +export XLA_FLAGS="--xla_disable_hlo_passes=constant_folding" +export NUMBA_CACHE_DIR=/tmp/numba_cache +export MPLCONFIGDIR=/tmp/matplotlib + +# PYAUTO_SIBSON_QUERY_CHUNK is deliberately left UNSET on both arms (library +# default 4096, what production uses); the script records the effective chunk +# under "sibson" in the result JSON. SPLIT_REG_COMPACT_WIDTH (12) and +# SPLIT_REG_WIDE_ROW_BUDGET (256) are likewise left at their library defaults — +# they are function keyword defaults in regularization_util.py, not environment +# variables, and finding (i) above is about confirming that path ran, not +# retuning it. + +nvidia-smi + +echo "==========================================" +date +hostname +echo "loadavg: $(cat /proc/loadavg)" +echo "Cell: likelihood_breakdown/imaging/delaunay x 2 arms (control / feature)" +echo "Instrument: hst" +echo "Precision: fp64" +echo "Regularization: adapt_split — al.reg.AdaptSplit(inner_coefficient=0.1, outer_coefficient=10.0, signal_scale=0.1)" +echo "A/B: PyAutoArray 5e2bc0f4 (merge base) vs bae9296e (lever 1 numba split-reg kernels)" +echo "Expectation: IDENTITY — lever 1 changed only the xp==np branch; this cell runs xp=jnp" +echo "Sibson chunk: PYAUTO_SIBSON_QUERY_CHUNK=${PYAUTO_SIBSON_QUERY_CHUNK:-unset (library default)}" + +echo "=== source revisions (shared install, untouched — PyAutoArray is overridden per arm) ===" +for r in PyAutoNerves PyAutoFit PyAutoArray PyAutoGalaxy PyAutoLens; do + printf '%-14s %s\n' "$r" "$(git -C /mnt/ral/jnightin/PyAuto/$r rev-parse HEAD 2>&1)" +done +echo "PyAutoArray control: $(git -C $PYAUTOARRAY_CONTROL rev-parse HEAD 2>&1)" +echo "PyAutoArray feature: $(git -C $PYAUTOARRAY_FEATURE rev-parse HEAD 2>&1)" +echo "AP_ROOT rev: $(git -C $AP_ROOT rev-parse HEAD 2>&1)" +echo "AP_ROOT branch: $(git -C $AP_ROOT rev-parse --abbrev-ref HEAD 2>&1)" + +cd $AP_ROOT + +echo "==========================================" +echo "CONTROL ARM: PyAutoArray 5e2bc0f4 (merge base)" +date +( + export PYTHONPATH=$PYAUTOARRAY_CONTROL:$PYTHONPATH + echo "--- control arm import provenance ---" + echo " checkout HEAD: $(git -C $PYAUTOARRAY_CONTROL rev-parse HEAD)" + python3 -c "import autoarray, autolens; print(' autoarray.__file__ =', autoarray.__file__); print(' autoarray.__version__ =', autoarray.__version__); print(' autolens.__file__ =', autolens.__file__)" + python3 -u scripts/imaging/likelihood_breakdown/delaunay.py \ + --regularization adapt_split \ + --config-name hpc_a100_fp64_lever1_control \ + --split-setup \ + --vmap-batch 16 +) + +echo "==========================================" +echo "FEATURE ARM: PyAutoArray bae9296e (lever 1)" +date +( + export PYTHONPATH=$PYAUTOARRAY_FEATURE:$PYTHONPATH + echo "--- feature arm import provenance ---" + echo " checkout HEAD: $(git -C $PYAUTOARRAY_FEATURE rev-parse HEAD)" + python3 -c "import autoarray, autolens; print(' autoarray.__file__ =', autoarray.__file__); print(' autoarray.__version__ =', autoarray.__version__); print(' autolens.__file__ =', autolens.__file__)" + python3 -u scripts/imaging/likelihood_breakdown/delaunay.py \ + --regularization adapt_split \ + --config-name hpc_a100_fp64_lever1 \ + --split-setup \ + --vmap-batch 16 +) + +echo "==========================================" +echo "loadavg: $(cat /proc/loadavg)" +echo "Finished." +date diff --git a/results/breakdown/imaging/delaunay_hpc_a100_fp64_lever1.json b/results/breakdown/imaging/delaunay_hpc_a100_fp64_lever1.json new file mode 100644 index 000000000..3697d113d --- /dev/null +++ b/results/breakdown/imaging/delaunay_hpc_a100_fp64_lever1.json @@ -0,0 +1,292 @@ +{ + "autolens_version": "2026.8.17.1", + "device": { + "backend": "gpu", + "device": "cuda:0", + "hostname": "euclid-ral-gpu-1", + "xla_flags": "--xla_disable_hlo_passes=constant_folding --xla_gpu_autotune_level=0 --xla_gpu_enable_triton_gemm=false", + "omp_num_threads": null, + "cpu_count": 124, + "jax_compilation_cache_dir": "/home/jnightin/.cache/pyauto_jax", + "autotune_cache_entries_at_start": 0, + "cache_fresh": true, + "nvidia_smi": "NVIDIA A100 80GB PCIe, 41495 MiB, 81920 MiB" + }, + "instrument": "hst", + "configuration": { + "pixel_scale_arcsec": 0.05, + "mask_radius_arcsec": 3.5, + "image_pixels_masked": 15361, + "over_sampled_pixels": 62752, + "delaunay_vertices": 1500, + "source_pixels_requested": null, + "edge_zeroed_pixels": 0, + "inversion_path": "dense", + "total_params": 1560, + "thread_env": { + "n_threads": null, + "vars": [ + "OPENBLAS_NUM_THREADS", + "MKL_NUM_THREADS", + "OMP_NUM_THREADS", + "VECLIB_MAXIMUM_THREADS", + "NUMEXPR_NUM_THREADS" + ], + "set_to": null, + "preexisting": {}, + "overridden": {}, + "note": "Not pinned (legacy variant): recorded as found." + }, + "memo": "library_default (inert on the JAX path)", + "over_sample_size_lp_rule": { + "sub_size_list": [ + 4, + 2, + 2 + ], + "radial_list": [ + 0.3, + 0.6 + ], + "centre": [ + 0.0, + 0.0 + ], + "note": "Outer sub-size 1 retired repo-wide on 2026-09-08 (autolens_profiling#235): it leaves the outermost annulus un-over-sampled and causes gradient issues." + } + }, + "regularization": { + "scheme": "adapt_split", + "inner_coefficient": 0.1, + "outer_coefficient": 10.0, + "signal_scale": 0.1 + }, + "steps": { + "Ray-trace data grid": 0.00016900701448321342, + "Ray-trace mesh grid": 0.00019444068893790246, + "Lens light images (pre-PSF)": 0.0001144536305218935, + "Blurred image (PSF convolution)": 0.0008288030978292227, + "Profile-subtracted image": 0.0001250624656677246, + "Inversion setup (steps 5-8 combined)": 0.020726340496912597, + "Data vector (D)": 0.00032450617291033266, + "Curvature matrix (F)": 0.0048147886991500854, + "Regularization matrix (H)": 0.00023651919327676366, + "Regularized reconstruction": 0.037309164321050046, + "Mapped recon + log evidence": 0.0022042868193238975 + }, + "total_step_by_step": 0.06704737260006369, + "regularization_matrix_prefix_s": 0.007329776789993048, + "interpolator_prefix_s": 0.007093257596716284, + "jit_phases": { + "ray_trace_data_jit": { + "lower_s": 0.08402059087529778, + "compile_s": 0.34478978998959064, + "first_call_s": 0.0015262328088283539, + "steady_per_call_s": 0.00016900701448321342 + }, + "ray_trace_mesh_jit": { + "lower_s": 0.07762124622240663, + "compile_s": 0.4328926228918135, + "first_call_s": 0.0011144261807203293, + "steady_per_call_s": 0.00019444068893790246 + }, + "lens_image_jit": { + "lower_s": 0.06400963896885514, + "compile_s": 0.036909440997987986, + "first_call_s": 0.0006024539470672607, + "steady_per_call_s": 0.0001144536305218935 + }, + "blurred_image_jit": { + "lower_s": 0.059575822204351425, + "compile_s": 0.20675774104893208, + "first_call_s": 0.0035917269997298717, + "steady_per_call_s": 0.0008288030978292227 + }, + "profile_subtract_jit": { + "lower_s": 0.004614714998751879, + "compile_s": 0.026700633112341166, + "first_call_s": 0.0005999929271638393, + "steady_per_call_s": 0.0001250624656677246 + }, + "inversion_setup_jit": { + "lower_s": 3.049173553008586, + "compile_s": 10.68769536120817, + "first_call_s": 0.13612036081030965, + "steady_per_call_s": 0.020726340496912597 + }, + "setup_prefix_5": { + "lower_s": 0.1658519278280437, + "compile_s": 0.9138642428442836, + "first_call_s": 0.004631645977497101, + "steady_per_call_s": 0.0010389016009867192 + }, + "setup_prefix_6": { + "lower_s": 0.23427595384418964, + "compile_s": 1.8170326338149607, + "first_call_s": 0.011729080695658922, + "steady_per_call_s": 0.007093257596716284 + }, + "setup_prefix_7": { + "lower_s": 0.24288607202470303, + "compile_s": 1.9496000166982412, + "first_call_s": 0.011699580121785402, + "steady_per_call_s": 0.007289390405640006 + }, + "setup_prefix_8": { + "lower_s": 0.25114908441901207, + "compile_s": 1.9777258322574198, + "first_call_s": 0.020659084897488356, + "steady_per_call_s": 0.01579543319530785 + }, + "data_vector_jit": { + "lower_s": 0.006116747390478849, + "compile_s": 0.06154243787750602, + "first_call_s": 0.0009231879375874996, + "steady_per_call_s": 0.00032450617291033266 + }, + "curvature_matrix_jit": { + "lower_s": 0.010713763069361448, + "compile_s": 0.05450473306700587, + "first_call_s": 0.005323855672031641, + "steady_per_call_s": 0.0048147886991500854 + }, + "regularization_matrix_jit": { + "lower_s": 0.4907937743701041, + "compile_s": 3.2612749892286956, + "first_call_s": 0.012830947991460562, + "steady_per_call_s": 0.007329776789993048 + }, + "setup_prefix_5_vmap16": { + "first_call_s": 1.2859896891750395, + "batch_per_call_s": 0.0010260248091071844, + "steady_per_call_s": 6.412655056919903e-05 + }, + "setup_prefix_6_vmap16": { + "first_call_s": 2.6362731219269335, + "batch_per_call_s": 0.0817845304030925, + "steady_per_call_s": 0.005111533150193281 + }, + "setup_prefix_7_vmap16": { + "first_call_s": 2.7572509427554905, + "batch_per_call_s": 0.08360229888930917, + "steady_per_call_s": 0.005225143680581823 + }, + "setup_prefix_8_vmap16": { + "first_call_s": 3.050433416850865, + "batch_per_call_s": 0.21696947021409868, + "steady_per_call_s": 0.013560591888381168 + }, + "setup_prefix_11_vmap16": { + "first_call_s": 3.881215966306627, + "batch_per_call_s": 0.08274070201441645, + "steady_per_call_s": 0.005171293875901028 + }, + "inversion_setup_vmap16": { + "first_call_s": 17.030757784843445, + "batch_per_call_s": 0.2224764971062541, + "steady_per_call_s": 0.013904781069140882 + }, + "reconstruction_jit": { + "lower_s": 0.028195125982165337, + "compile_s": 0.45178185729309916, + "first_call_s": 0.03869487019255757, + "steady_per_call_s": 0.037309164321050046 + }, + "cholesky_curvature_reg_jit": { + "lower_s": 0.009365108329802752, + "compile_s": 0.07309082197025418, + "first_call_s": 0.0016789501532912254, + "steady_per_call_s": 0.0011551761999726295 + }, + "cholesky_solve_jit": { + "lower_s": 0.010504284873604774, + "compile_s": 0.06545166205614805, + "first_call_s": 0.0019604270346462727, + "steady_per_call_s": 0.001496648183092475 + }, + "nnls_pdip_jit": { + "lower_s": 0.02291371813043952, + "compile_s": 0.4325692756101489, + "first_call_s": 0.03852708172053099, + "steady_per_call_s": 0.037258329894393684 + }, + "nnls_pdip_one_iteration_jit": { + "lower_s": 0.02327603381127119, + "compile_s": 0.43229943001642823, + "first_call_s": 0.004748273175209761, + "steady_per_call_s": 0.0031347598414868116 + }, + "nnls_pdip_vmap16": { + "first_call_s": 0.8841444370336831, + "batch_per_call_s": 0.34871410140767695, + "steady_per_call_s": 0.02179463133797981 + }, + "log_evidence_jit": { + "lower_s": 0.017086816020309925, + "compile_s": 0.2027455298230052, + "first_call_s": 0.003256000578403473, + "steady_per_call_s": 0.0022042868193238975 + }, + "log_det_curvature_reg_jit": { + "lower_s": 0.013694896828383207, + "compile_s": 0.08910879073664546, + "first_call_s": 0.001777338795363903, + "steady_per_call_s": 0.0011280254926532506 + }, + "log_det_regularization_jit": { + "lower_s": 0.0003807968460023403, + "compile_s": 1.2638978660106659e-05, + "first_call_s": 0.0012353449128568172, + "steady_per_call_s": 0.0011197667103260756 + } + }, + "steps_reconstruction_sub_rows": { + "Cholesky (F+\u03bbH)": 0.0011551761999726295, + "Cholesky solve (unconstrained)": 0.001496648183092475, + "NNLS PDIP (cell-driven, max_iter 50)": 0.037258329894393684, + "NNLS PDIP one iteration": 0.0031347598414868116, + "NNLS PDIP @vmap 16 (identical lanes)": 0.02179463133797981, + "Log det Cholesky (F+\u03bbH reduced)": 0.0011280254926532506, + "Log det Cholesky (H reduced)": 0.0011197667103260756 + }, + "nnls": { + "iterations": 22, + "converged": true, + "ms_per_iteration": 1.6935604497451673, + "one_iteration_ms": 3.1347598414868116, + "max_iter": 50, + "solver_tol": "jaxnnls default", + "jacobi_preconditioning": true, + "reconstruction_max_abs_diff_vs_library": 7.592702022662934e-10, + "reconstruction_tolerance": 1e-08, + "drift": null + }, + "log_evidence_terms": { + "chi_squared": 19821.95111065407, + "regularization_term": 928.9375270505461, + "log_det_curvature_reg": 8360.401762997288, + "log_det_regularization": 7756.614958909804, + "noise_normalization": -79635.26723742482, + "log_evidence": 29140.295897816362 + }, + "steps_reconstruction_vmap_note": "The @vmap 16 NNLS row batches 16 copies of the same (Q_pc, q_pc); identical lanes converge on the same PDIP iteration, so the lax.while_loop never runs on for a straggler. It is the best case for amortization, not a representative one \u2014 a real batch of distinct parameter draws runs until its slowest lane converges.", + "setup_split": { + "Border relocation": 0.0010389016009867192, + "Triangulation + interpolation": 0.006054355995729566, + "Mapping matrix": 0.0001961328089237213, + "Blurred mapping matrix (PSF)": 0.008506042789667845 + }, + "vmap_batch": 16, + "steps_vmap_per_call": { + "Inversion setup (steps 5-8 combined)": 0.013904781069140882, + "Regularization matrix (H)": 5.9760725707747216e-05 + }, + "setup_split_vmap": { + "Border relocation": 6.412655056919903e-05, + "Triangulation + interpolation": 0.005047406599624082, + "Mapping matrix": 0.00011361053038854221, + "Blurred mapping matrix (PSF)": 0.008335448207799344 + }, + "regularization_matrix_prefix_vmap_per_call_s": 0.005171293875901028, + "interpolator_prefix_vmap_per_call_s": 0.005111533150193281 +} \ No newline at end of file diff --git a/results/breakdown/imaging/delaunay_hpc_a100_fp64_lever1.png b/results/breakdown/imaging/delaunay_hpc_a100_fp64_lever1.png new file mode 100644 index 000000000..ed35ef035 Binary files /dev/null and b/results/breakdown/imaging/delaunay_hpc_a100_fp64_lever1.png differ diff --git a/results/breakdown/imaging/delaunay_hpc_a100_fp64_lever1_control.json b/results/breakdown/imaging/delaunay_hpc_a100_fp64_lever1_control.json new file mode 100644 index 000000000..430721a1d --- /dev/null +++ b/results/breakdown/imaging/delaunay_hpc_a100_fp64_lever1_control.json @@ -0,0 +1,292 @@ +{ + "autolens_version": "2026.8.17.1", + "device": { + "backend": "gpu", + "device": "cuda:0", + "hostname": "euclid-ral-gpu-1", + "xla_flags": "--xla_disable_hlo_passes=constant_folding --xla_gpu_autotune_level=0 --xla_gpu_enable_triton_gemm=false", + "omp_num_threads": null, + "cpu_count": 124, + "jax_compilation_cache_dir": "/home/jnightin/.cache/pyauto_jax", + "autotune_cache_entries_at_start": 0, + "cache_fresh": true, + "nvidia_smi": "NVIDIA A100 80GB PCIe, 41495 MiB, 81920 MiB" + }, + "instrument": "hst", + "configuration": { + "pixel_scale_arcsec": 0.05, + "mask_radius_arcsec": 3.5, + "image_pixels_masked": 15361, + "over_sampled_pixels": 62752, + "delaunay_vertices": 1500, + "source_pixels_requested": null, + "edge_zeroed_pixels": 0, + "inversion_path": "dense", + "total_params": 1560, + "thread_env": { + "n_threads": null, + "vars": [ + "OPENBLAS_NUM_THREADS", + "MKL_NUM_THREADS", + "OMP_NUM_THREADS", + "VECLIB_MAXIMUM_THREADS", + "NUMEXPR_NUM_THREADS" + ], + "set_to": null, + "preexisting": {}, + "overridden": {}, + "note": "Not pinned (legacy variant): recorded as found." + }, + "memo": "library_default (inert on the JAX path)", + "over_sample_size_lp_rule": { + "sub_size_list": [ + 4, + 2, + 2 + ], + "radial_list": [ + 0.3, + 0.6 + ], + "centre": [ + 0.0, + 0.0 + ], + "note": "Outer sub-size 1 retired repo-wide on 2026-09-08 (autolens_profiling#235): it leaves the outermost annulus un-over-sampled and causes gradient issues." + } + }, + "regularization": { + "scheme": "adapt_split", + "inner_coefficient": 0.1, + "outer_coefficient": 10.0, + "signal_scale": 0.1 + }, + "steps": { + "Ray-trace data grid": 0.00016934699378907682, + "Ray-trace mesh grid": 0.00016315709799528122, + "Lens light images (pre-PSF)": 0.00011987751349806786, + "Blurred image (PSF convolution)": 0.0008315801154822111, + "Profile-subtracted image": 0.00012890337966382505, + "Inversion setup (steps 5-8 combined)": 0.02078137588687241, + "Data vector (D)": 0.00033538597635924817, + "Curvature matrix (F)": 0.004814203782007098, + "Regularization matrix (H)": 0.00021638926118612307, + "Regularized reconstruction": 0.0372886975761503, + "Mapped recon + log evidence": 0.002222441602498293 + }, + "total_step_by_step": 0.06707135918550193, + "regularization_matrix_prefix_s": 0.007331827795132995, + "interpolator_prefix_s": 0.007115438533946872, + "jit_phases": { + "ray_trace_data_jit": { + "lower_s": 0.08429981814697385, + "compile_s": 0.3529686131514609, + "first_call_s": 0.0015430417843163013, + "steady_per_call_s": 0.00016934699378907682 + }, + "ray_trace_mesh_jit": { + "lower_s": 0.07763279741629958, + "compile_s": 0.4152077422477305, + "first_call_s": 0.0011462359689176083, + "steady_per_call_s": 0.00016315709799528122 + }, + "lens_image_jit": { + "lower_s": 0.06383245019242167, + "compile_s": 0.0394399119541049, + "first_call_s": 0.000621723011136055, + "steady_per_call_s": 0.00011987751349806786 + }, + "blurred_image_jit": { + "lower_s": 0.0598516589961946, + "compile_s": 0.2119954191148281, + "first_call_s": 0.0036597661674022675, + "steady_per_call_s": 0.0008315801154822111 + }, + "profile_subtract_jit": { + "lower_s": 0.004602745175361633, + "compile_s": 0.026582204271107912, + "first_call_s": 0.000551754143089056, + "steady_per_call_s": 0.00012890337966382505 + }, + "inversion_setup_jit": { + "lower_s": 3.021751527208835, + "compile_s": 10.615665158256888, + "first_call_s": 0.4645752152428031, + "steady_per_call_s": 0.02078137588687241 + }, + "setup_prefix_5": { + "lower_s": 0.3272400479763746, + "compile_s": 0.8826301041990519, + "first_call_s": 0.004689533729106188, + "steady_per_call_s": 0.0011586602311581373 + }, + "setup_prefix_6": { + "lower_s": 0.23702536104246974, + "compile_s": 1.8401543898507953, + "first_call_s": 0.012725758366286755, + "steady_per_call_s": 0.007115438533946872 + }, + "setup_prefix_7": { + "lower_s": 0.24566828925162554, + "compile_s": 1.8877481217496097, + "first_call_s": 0.01167893223464489, + "steady_per_call_s": 0.00725938961841166 + }, + "setup_prefix_8": { + "lower_s": 0.25494405813515186, + "compile_s": 1.9988571419380605, + "first_call_s": 0.020678714849054813, + "steady_per_call_s": 0.015834783716127277 + }, + "data_vector_jit": { + "lower_s": 0.00623267563059926, + "compile_s": 0.06192258419468999, + "first_call_s": 0.0008940286934375763, + "steady_per_call_s": 0.00033538597635924817 + }, + "curvature_matrix_jit": { + "lower_s": 0.011319935321807861, + "compile_s": 0.05685453535988927, + "first_call_s": 0.005324196070432663, + "steady_per_call_s": 0.004814203782007098 + }, + "regularization_matrix_jit": { + "lower_s": 0.3195114200934768, + "compile_s": 3.0433736010454595, + "first_call_s": 0.01321183331310749, + "steady_per_call_s": 0.007331827795132995 + }, + "setup_prefix_5_vmap16": { + "first_call_s": 1.371332572773099, + "batch_per_call_s": 0.001025569811463356, + "steady_per_call_s": 6.409811321645975e-05 + }, + "setup_prefix_6_vmap16": { + "first_call_s": 2.765783301088959, + "batch_per_call_s": 0.08216467192396522, + "steady_per_call_s": 0.005135291995247826 + }, + "setup_prefix_7_vmap16": { + "first_call_s": 2.66021759621799, + "batch_per_call_s": 0.08417384307831526, + "steady_per_call_s": 0.0052608651923947035 + }, + "setup_prefix_8_vmap16": { + "first_call_s": 3.051568733062595, + "batch_per_call_s": 0.21718953237868846, + "steady_per_call_s": 0.013574345773668029 + }, + "setup_prefix_11_vmap16": { + "first_call_s": 3.970909111201763, + "batch_per_call_s": 0.0831049389205873, + "steady_per_call_s": 0.0051940586825367065 + }, + "inversion_setup_vmap16": { + "first_call_s": 17.24961724318564, + "batch_per_call_s": 0.22212901059538126, + "steady_per_call_s": 0.013883063162211329 + }, + "reconstruction_jit": { + "lower_s": 0.028514021076261997, + "compile_s": 0.46305563393980265, + "first_call_s": 0.038662140257656574, + "steady_per_call_s": 0.0372886975761503 + }, + "cholesky_curvature_reg_jit": { + "lower_s": 0.009691854007542133, + "compile_s": 0.08811015170067549, + "first_call_s": 0.001703969668596983, + "steady_per_call_s": 0.0011649670079350472 + }, + "cholesky_solve_jit": { + "lower_s": 0.01064528338611126, + "compile_s": 0.07163292774930596, + "first_call_s": 0.0020613158121705055, + "steady_per_call_s": 0.0015122809913009406 + }, + "nnls_pdip_jit": { + "lower_s": 0.02326801372691989, + "compile_s": 0.4626593077555299, + "first_call_s": 0.03871151991188526, + "steady_per_call_s": 0.037271011900156734 + }, + "nnls_pdip_one_iteration_jit": { + "lower_s": 0.02430408075451851, + "compile_s": 0.43662937777116895, + "first_call_s": 0.004598124884068966, + "steady_per_call_s": 0.003169087367132306 + }, + "nnls_pdip_vmap16": { + "first_call_s": 1.0800176169723272, + "batch_per_call_s": 0.34831849513575436, + "steady_per_call_s": 0.021769905945984647 + }, + "log_evidence_jit": { + "lower_s": 0.0178202991373837, + "compile_s": 0.21254594158381224, + "first_call_s": 0.0032823411747813225, + "steady_per_call_s": 0.002222441602498293 + }, + "log_det_curvature_reg_jit": { + "lower_s": 0.012704798020422459, + "compile_s": 0.07859686622396111, + "first_call_s": 0.0017417497001588345, + "steady_per_call_s": 0.001111854799091816 + }, + "log_det_regularization_jit": { + "lower_s": 0.00026628701016306877, + "compile_s": 8.600298315286636e-06, + "first_call_s": 0.0012191259302198887, + "steady_per_call_s": 0.0011194596998393535 + } + }, + "steps_reconstruction_sub_rows": { + "Cholesky (F+\u03bbH)": 0.0011649670079350472, + "Cholesky solve (unconstrained)": 0.0015122809913009406, + "NNLS PDIP (cell-driven, max_iter 50)": 0.037271011900156734, + "NNLS PDIP one iteration": 0.003169087367132306, + "NNLS PDIP @vmap 16 (identical lanes)": 0.021769905945984647, + "Log det Cholesky (F+\u03bbH reduced)": 0.001111854799091816, + "Log det Cholesky (H reduced)": 0.0011194596998393535 + }, + "nnls": { + "iterations": 22, + "converged": true, + "ms_per_iteration": 1.694136904552579, + "one_iteration_ms": 3.169087367132306, + "max_iter": 50, + "solver_tol": "jaxnnls default", + "jacobi_preconditioning": true, + "reconstruction_max_abs_diff_vs_library": 7.592702022662934e-10, + "reconstruction_tolerance": 1e-08, + "drift": null + }, + "log_evidence_terms": { + "chi_squared": 19821.95111065407, + "regularization_term": 928.9375270505461, + "log_det_curvature_reg": 8360.401762997288, + "log_det_regularization": 7756.614958909804, + "noise_normalization": -79635.26723742482, + "log_evidence": 29140.295897816362 + }, + "steps_reconstruction_vmap_note": "The @vmap 16 NNLS row batches 16 copies of the same (Q_pc, q_pc); identical lanes converge on the same PDIP iteration, so the lax.while_loop never runs on for a straggler. It is the best case for amortization, not a representative one \u2014 a real batch of distinct parameter draws runs until its slowest lane converges.", + "setup_split": { + "Border relocation": 0.0011586602311581373, + "Triangulation + interpolation": 0.0059567783027887344, + "Mapping matrix": 0.00014395108446478826, + "Blurred mapping matrix (PSF)": 0.008575394097715617 + }, + "vmap_batch": 16, + "steps_vmap_per_call": { + "Inversion setup (steps 5-8 combined)": 0.013883063162211329, + "Regularization matrix (H)": 5.876668728888035e-05 + }, + "setup_split_vmap": { + "Border relocation": 6.409811321645975e-05, + "Triangulation + interpolation": 0.005071193882031366, + "Mapping matrix": 0.0001255731971468773, + "Blurred mapping matrix (PSF)": 0.008313480581273326 + }, + "regularization_matrix_prefix_vmap_per_call_s": 0.0051940586825367065, + "interpolator_prefix_vmap_per_call_s": 0.005135291995247826 +} \ No newline at end of file diff --git a/results/breakdown/imaging/delaunay_hpc_a100_fp64_lever1_control.png b/results/breakdown/imaging/delaunay_hpc_a100_fp64_lever1_control.png new file mode 100644 index 000000000..a54db13e9 Binary files /dev/null and b/results/breakdown/imaging/delaunay_hpc_a100_fp64_lever1_control.png differ diff --git a/results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_lever1_b_warm_t1.json b/results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_lever1_b_warm_t1.json new file mode 100644 index 000000000..9dd9bc8b4 --- /dev/null +++ b/results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_lever1_b_warm_t1.json @@ -0,0 +1,774 @@ +{ + "autolens_version": "2026.8.17.1", + "timing_status": "measured", + "timing_status_reason": "Load average stayed at or below the core count (2.25 on 124 cores) across the timed rows.", + "contention": { + "load_average_at_start": [ + 2.25, + 0.87, + 0.32 + ], + "load_average_at_end": [ + 2.21, + 0.9, + 0.34 + ], + "cpu_count": 124, + "load_average_peak_1min": 2.25, + "contention_warning": false, + "contention_note": "load_average_at_* are /proc/loadavg's 1/5/15-minute figures, read either side of the timed rows. contention_warning is the 1-minute figure exceeding the core count: the rows were competing for the cores they were timed on, which widens the per-call scatter and can inject multi-call transients. It does not affect any gate under `gates` \u2014 those are exact comparisons of numbers, not of times." + }, + "device": { + "use_jax": false, + "backend": "numba_cpu", + "inversion_paths": [ + "InversionImagingSparseNumba" + ], + "hostname": "euclid-ral-gpu-1", + "omp_num_threads": "1", + "numba_num_threads": "1", + "cpu_count": 124, + "note": "Cell-local. _profile_cli.device_info_dict() is deliberately NOT called: it imports jax unconditionally (_profile_cli.py:392), and a JAX runtime in this process changes the thread pools the numba rows are measured through." + }, + "machine": { + "cpu_model": "AMD EPYC 7702 64-Core Processor", + "cpu_count_os": 124, + "nproc": 1, + "nproc_all": 124, + "nproc_note": "GNU nproc honours OMP_NUM_THREADS, so `nproc` can print 1 on a multi-core host; `nproc_all` is the core count.", + "ram_total": "928298232 kB", + "kernel": "5.14.0-687.39.1.el9_8.x86_64", + "platform": "Linux-5.14.0-687.39.1.el9_8.x86_64-x86_64-with-glibc2.34", + "python": "3.12.4", + "jax_thread_env": { + "NPROC": null + }, + "blas_thread_env": { + "OMP_NUM_THREADS": "1", + "OPENBLAS_NUM_THREADS": "1", + "MKL_NUM_THREADS": "1", + "VECLIB_MAXIMUM_THREADS": "1", + "NUMEXPR_NUM_THREADS": "1" + }, + "thread_env_note": "NPROC sizes XLA's CPU intra-op pool (the JAX rows); the BLAS knobs pin OpenBLAS/MKL/OpenMP (the numpy/scipy rows) and do not touch JAX. Two disjoint families; both are recorded on every CPU timing.", + "gpu": null + }, + "instrument": "hst", + "configuration": { + "mesh": "delaunay", + "dataset": "hst", + "pixel_scale_arcsec": 0.05, + "mask_radius_arcsec": 3.5, + "image_pixels_masked": 15361, + "over_sampled_pixels": 62752, + "source_pixels": 1500, + "mesh_shape": null, + "routes_selected": [ + "b" + ], + "formalisms_selected": [ + "sparse_numba" + ], + "row_order": "grouped", + "n_threads": 1, + "n_repeats": 16, + "instances": "iid", + "iid_seed": 263, + "decompose": true, + "pins_mode": "fp64", + "use_jax": false, + "thread_env": { + "n_threads": 1, + "vars": [ + "OPENBLAS_NUM_THREADS", + "MKL_NUM_THREADS", + "OMP_NUM_THREADS", + "VECLIB_MAXIMUM_THREADS", + "NUMEXPR_NUM_THREADS" + ], + "set_to": "1", + "preexisting": { + "OPENBLAS_NUM_THREADS": "1", + "MKL_NUM_THREADS": "1", + "OMP_NUM_THREADS": "1" + }, + "overridden": {}, + "note": "Set by _production_config.pin_thread_env before numpy import; mirrors the production SLURM submit scripts." + }, + "numba_thread_env": { + "NUMBA_NUM_THREADS": "1", + "preexisting": "1", + "overridden": null, + "note": "Set cell-locally before numpy/numba import. Deliberately NOT added to _production_config.THREAD_ENV_VARS: that tuple is recorded verbatim in every existing numba cell's configuration.thread_env and widening it would change those blocks and the pins that describe them." + }, + "nnls_warm_start_mode": "on", + "nnls_warm_start_env": "1", + "nnls_warm_start_env_preexisting": null, + "memo_cleared_between_rows": true, + "memo_cleared_within_block": false, + "memo_note": "The between-row clears are unconditional; only the WITHIN-BLOCK clears are gated by --nnls-warm-start. With the memo on, a block's calls seed each other (the sampler's regime); with it off every call is a cold dense-sign solve.", + "over_sample_size_lp_rule": { + "sub_size_list": [ + 4, + 2, + 2 + ], + "radial_list": [ + 0.3, + 0.6 + ], + "centre": [ + 0.0, + 0.0 + ] + } + }, + "regularization": { + "scheme": "adapt_split", + "inner_coefficient": 0.1, + "outer_coefficient": 10.0, + "signal_scale": 0.1 + }, + "all_route_keys": [ + "a", + "b", + "c", + "d_np" + ], + "default_route_keys": [ + "a", + "b", + "c" + ], + "all_formalism_keys": [ + "dense", + "sparse_numba" + ], + "systems": { + "s0": { + "n_params": 1560, + "n_mapper": 1500, + "n_funcs": 60, + "edge_zeroed_pixels": 0, + "log_evidence_eager": 19705.717585911676 + }, + "s3": { + "n_params": 1500, + "n_mapper": 1500, + "n_funcs": 0, + "edge_zeroed_pixels": 0, + "subtracted_light_flux": 4945.524141998385, + "log_evidence_eager_dense": 19705.71758591185, + "log_evidence_eager_sparse_numba": 19705.71758591176 + } + }, + "gates": { + "P1_rebaked_operator_equals_original": { + "status": "PASS", + "fields": { + "psf_precision_operator_sparse": true, + "indexes": true, + "lengths": true + }, + "asserted_under_pins_none": true, + "basis": "apply_sparse_operator_cpu builds the operator from the noise map, PSF and mask alone (dataset.py:682-706); subtracting the fixed lens light changes only the data, so the re-baked operator must be identical element for element.", + "summary": "3/3 arrays identical" + }, + "S3_mapper_block_equals_S0": { + "status": "PASS", + "log_dets": { + "log_det_curvature_reg_matrix_term": { + "s0": 8326.70017133483, + "s3": 8326.70017133483, + "rel_diff": 0.0, + "status": "PASS" + }, + "log_det_regularization_matrix_term": { + "s0": 7670.876894312947, + "s3": 7670.876894312947, + "rel_diff": 0.0, + "status": "PASS" + } + }, + "n_edge_zeroed_s0": 0, + "n_edge_zeroed_s3": 0, + "rtol": 1e-06, + "summary": "log-dets rel 0.000e+00, edge-zeroed 0 vs 0" + }, + "P2_dense_equals_sparse_numba_system": { + "status": "PASS", + "data_vector_max_rel_diff": 1.2974807795913263e-15, + "curvature_matrix_mapper_block_max_rel_diff": 3.7275058948429935e-15, + "rtol": 1e-09, + "n_mapper": 1500, + "asserted_under_pins_none": true, + "summary": "D 1.297e-15, F(mapper) 3.728e-15 (rtol 1e-09)" + }, + "P3_dense_equals_sparse_numba_evidence": { + "status": "PASS", + "figure_of_merit_dense": 19705.71758591185, + "figure_of_merit_sparse_numba": 19705.71758591176, + "d_log_evidence_nats": -9.094947017729282e-11, + "rel_diff": 4.6153848384752585e-15, + "rtol": 1e-06, + "n_passive_set_differences": 0, + "n_passive_dense": 1485, + "n_passive_sparse_numba": 1485, + "solver_stats_dense": { + "seed_source": "dense", + "warm_start_fallback": false, + "outer_iterations": 0, + "inner_iterations": 1, + "n_passive": 1485, + "warm_start_errors": 5 + }, + "solver_stats_sparse_numba": { + "seed_source": "dense", + "warm_start_fallback": false, + "outer_iterations": 0, + "inner_iterations": 1, + "n_passive": 1485, + "warm_start_errors": 5 + }, + "summary": "\u0394 -9.094947e-11 nats (rel 4.615e-15), 0 passive-set differences" + } + }, + "gate_thresholds": { + "P2_rtol": 1e-09, + "P3_rtol": 1e-06, + "P4_rtol": 1e-09, + "mapper_logdet_rtol": 1e-06, + "max_instrumentation_overhead_ratio": 1.03, + "min_blocks_for_overhead_assert": 3, + "max_unattributed_fraction": 0.05, + "warmup_window": 3, + "warmup_tolerance": 0.1, + "warmup_max_calls": 12 + }, + "route_c": { + "solve_ids_to_keep_is_none": true, + "edge_zeroing_disabled": true, + "edge_zeroing_note": "Inversion.solve_ids_to_keep returns None the moment use_positive_only_solver is False (abstract.py:540-546), so turning positivity off silently turns edge zeroing off with it. Route c solves the FULL system; routes a and b solve the edge-zeroed one.", + "log_evidence_eager": 19783.98705569277, + "d_log_evidence_vs_route_b": 78.26946978092019, + "n_negative_entries": 10, + "negative_flux_fraction": 9.879318261208077e-05, + "note": "Never quote route c's milliseconds without these numbers. The unconstrained solution sits at a HIGHER evidence than the constrained optimum because it is a different, infeasible minimiser." + }, + "rows": { + "b_sparse_numba": { + "route": "b", + "formalism": "sparse_numba", + "label": "S3 fnnls source-only (the reference) [sparse_numba]", + "inversion_class": "InversionImagingSparseNumba", + "n_repeats": 16, + "warmup": { + "sequence_s": [ + 0.3575598979368806, + 0.2915676631964743, + 0.3038667971268296, + 0.2987135280855, + 0.295441806782037, + 0.3025209433399141 + ], + "n_calls": 6, + "steady": true, + "window": 3, + "tolerance": 0.1, + "max_calls": 12, + "first_call_incl_numba_compile_s": 0.3575598979368806, + "note": "Warm-up ran to a steady state, not to a fixed count: calls repeat until the median of the last `window` agrees with the median of the previous `window` to `tolerance`, or `max_calls` is hit. Every call is recorded. `steady: false` means the row's timings were taken on a host that never settled and should be read with the sequence in hand." + }, + "warmup_incl_numba_compile_s": 0.3575598979368806, + "row_order": "grouped", + "memo_cleared_between_rows": true, + "memo_cleared_within_block": false, + "nnls_warm_start_mode": "on", + "nnls_warm_start_env": "1", + "operated_mapping_matrix_memo_entries_before": 0, + "decomposed": true, + "call_ms": 299.7090723074507, + "call_ms_median": 297.26180946454406, + "call_ms_min": 285.08096002042294, + "call_ms_max": 350.7997989654541, + "call_ms_sequence": [ + 306.7406117916107, + 291.2986259907484, + 302.4728028103709, + 304.32424088940024, + 304.8389758914709, + 296.5677338652313, + 285.8552113175392, + 291.9794279150665, + 297.6717110723257, + 285.08096002042294, + 287.3134333640337, + 300.03022216260433, + 297.33107425272465, + 350.7997989654541, + 297.19254467636347, + 295.8477819338441 + ], + "clean_relative_spread": 0.21927544081019604, + "n_clean_calls": 16, + "log_likelihood": 18665.014334145228, + "log_likelihood_sequence": [ + 19497.35174868952, + 19651.457884697327, + 19328.369614256386, + 19488.202055828602, + 18847.16626547022, + 19319.244429423128, + 19014.188491645276, + 19652.641982502628, + 18982.846275923246, + 19314.213619474776, + 19705.71758591176, + 18820.528845843237, + 18656.216134096525, + 19403.96980059209, + 18665.014334145228, + 19343.4137410371, + 18791.303045235916, + 19497.35174868952, + 19651.457884697153, + 19328.369614256895, + 19488.202055828788, + 18847.166265470227, + 19319.244429423157, + 19014.188491645313, + 19652.641982502777, + 18982.84627592324, + 19314.213619474453, + 19705.71758591176, + 18820.528845843237, + 18656.216134096525, + 19403.96980059209, + 18665.014334145228 + ], + "cpu_over_wall": 1.0003671095137376, + "cpu_over_wall_note": "time.process_time() sums every thread of the process, so this is the effective thread count of the timed calls. At --threads 1 it should sit just above 1.0; anything higher means a pool this cell did not pin.", + "call_ms_instrumented": 304.34655499993823, + "call_ms_instrumented_sequence": [ + 357.6852078549564, + 291.45106533542275, + 293.6760480515659, + 305.93888321891427, + 313.04826820269227, + 350.6654198281467, + 298.0505460873246, + 295.8418717607856, + 302.39767394959927, + 287.61145984753966, + 294.9852733872831, + 288.91214495524764, + 297.79146891087294, + 306.16761930286884, + 287.35152212902904, + 297.9704071767628 + ], + "n_instrumented_calls": 16, + "abba": { + "n_blocks": 8, + "block_ratios": [ + 1.0854409412959212, + 0.988163896802298, + 1.1036020670593165, + 1.02778957425749, + 1.0124520453776442, + 0.9941325029194071, + 0.9318474295397937, + 0.9869850380183525 + ], + "ratio_mean": 1.016301686908778, + "ratio_median": 1.0032922741485257, + "ratio_min": 0.9318474295397937, + "ratio_max": 1.1036020670593165, + "design": "A B B A per block; ratio = mean(B) / mean(A)", + "why": "A B B A straddles the two instrumented calls with one clean call either side, so a drift linear in call index cancels exactly in the ratio. A sequential 'all clean then all instrumented' design charges the whole drift over the row to the instrumentation: measured on this configuration it returned 0.71, 0.98, 1.10, 1.11, 1.24 and 1.37 across six rows of one leg \u2014 including ratios below 1, which no real instrumentation can produce." + }, + "instrumentation_overhead_ratio": 1.016301686908778, + "instrumentation_overhead_status": "PASS", + "instrumentation_overhead_assertable": true, + "instrumentation_overhead_threshold": 1.03, + "min_blocks_for_overhead_assert": 3, + "decomposition_rescale_factor": 0.9847624932291792, + "attributed_ms": 303.34537985618226, + "unattributed_ms": 1.0011751437559724, + "unattributed_fraction": 0.003289589211076089, + "steps": { + "fit.blurred_image": { + "excl_s": 0.0026329341001277273, + "excl_s_unscaled": 0.0026736742292996496, + "incl_s": 0.0026329341001277273, + "n_calls": 1.0, + "group": "image" + }, + "fit.profile_subtracted_image": { + "excl_s": 6.954164236620262e-05, + "excl_s_unscaled": 7.061767973937094e-05, + "incl_s": 0.00270247574249393, + "n_calls": 1.0, + "group": "image" + }, + "fit.tracer_to_inversion": { + "excl_s": 1.705950646558789e-05, + "excl_s_unscaled": 1.7323473002761602e-05, + "incl_s": 0.0027195352489595174, + "n_calls": 1.0, + "group": "mesh" + }, + "to_inversion.traced_grid_2d_list_of_inversion": { + "excl_s": 0.0008743922363357156, + "excl_s_unscaled": 0.0008879219531081617, + "incl_s": 0.0008743922363357156, + "n_calls": 1.0, + "group": "mesh" + }, + "to_inversion.image_plane_mesh_grid_pg_list": { + "excl_s": 4.20138531946433e-05, + "excl_s_unscaled": 4.2663945350795984e-05, + "incl_s": 4.20138531946433e-05, + "n_calls": 1.0, + "group": "mesh" + }, + "to_inversion.traced_mesh_grid_pg_list": { + "excl_s": 0.0003973438007125559, + "excl_s_unscaled": 0.00040349201299250126, + "incl_s": 0.0004393576539071992, + "n_calls": 1.0, + "group": "mesh" + }, + "delaunay.mesh_geometry": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "mesh" + }, + "delaunay.triangulation": { + "excl_s": 0.018661657454100183, + "excl_s_unscaled": 0.018950414523715153, + "incl_s": 0.018661657454100183, + "n_calls": 1.0, + "group": "mesh" + }, + "to_inversion.lp_linear_func_list_galaxy_dict": { + "excl_s": 0.006048669089066008, + "excl_s_unscaled": 0.006142261845525354, + "incl_s": 0.006048669089066008, + "n_calls": 1.0, + "group": "mapper" + }, + "to_inversion.mapper_galaxy_dict": { + "excl_s": 0.0012574530316803439, + "excl_s_unscaled": 0.0012769099557772279, + "incl_s": 0.0025712029219232585, + "n_calls": 1.0, + "group": "mapper" + }, + "mapper.unique_mappings": { + "excl_s": 0.002210049504386637, + "excl_s_unscaled": 0.0022442462213803083, + "incl_s": 0.023397623214652517, + "n_calls": 1.0, + "group": "mapper" + }, + "mapper.mapping_matrix": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "mapper" + }, + "mapper.sparse_triplets_data": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "mapper" + }, + "mapper.sparse_triplets_curvature": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "mapper" + }, + "delaunay.mappings_sizes_weights": { + "excl_s": 0.002525916256165699, + "excl_s_unscaled": 0.002565000468166545, + "incl_s": 0.021187573710265882, + "n_calls": 1.0, + "group": "mapper_weights" + }, + "delaunay.mappings_sizes_weights_split": { + "excl_s": 0.0012189239917362942, + "excl_s_unscaled": 0.0012377847451716661, + "incl_s": 0.0012189239917362942, + "n_calls": 1.0, + "group": "mapper_weights" + }, + "inversion.to_inversion": { + "excl_s": 2.8162214914754815e-05, + "excl_s_unscaled": 2.8597976779565215e-05, + "incl_s": 0.00864803422590402, + "n_calls": 1.0, + "group": "DF" + }, + "fit.inversion": { + "excl_s": 7.017251422467837e-05, + "excl_s_unscaled": 7.125831325538456e-05, + "incl_s": 0.011437741989088217, + "n_calls": 1.0, + "group": "DF" + }, + "inversion.operated_mapping_matrix": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "DF" + }, + "inversion.linear_func_operated_mapping_matrix_dict": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "DF" + }, + "sparse_numba.linear_func_operated_mapping_matrix_dict": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "DF" + }, + "sparse_numba.psf_weighted_data": { + "excl_s": 0.008211003850601762, + "excl_s_unscaled": 0.008338055020431057, + "incl_s": 0.008211003850601762, + "n_calls": 1.0, + "group": "DF" + }, + "sparse_numba.data_vector": { + "excl_s": 6.558327397670321e-05, + "excl_s_unscaled": 6.659806240350008e-05, + "incl_s": 0.031674210339230985, + "n_calls": 1.0, + "group": "DF" + }, + "sparse_numba.curvature_matrix": { + "excl_s": 0.08715333020221701, + "excl_s_unscaled": 0.08850187817006372, + "incl_s": 0.08715333020221701, + "n_calls": 1.0, + "group": "DF" + }, + "dense.data_vector": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "DF" + }, + "dense.curvature_matrix": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "DF" + }, + "inversion.regularization_matrix": { + "excl_s": 0.005923704213250357, + "excl_s_unscaled": 0.006015363353071734, + "incl_s": 0.007142628204986651, + "n_calls": 1.0, + "group": "F_plus_H" + }, + "inversion.regularization_matrix_reduced": { + "excl_s": 2.312375217405981e-06, + "excl_s_unscaled": 2.3481552489101887e-06, + "incl_s": 2.312375217405981e-06, + "n_calls": 1.0, + "group": "F_plus_H" + }, + "inversion.curvature_reg_matrix": { + "excl_s": 0.0041082762052205915, + "excl_s_unscaled": 0.0041718447173479944, + "incl_s": 0.09840423461242426, + "n_calls": 2.0, + "group": "F_plus_H" + }, + "inversion.curvature_reg_matrix_reduced": { + "excl_s": 1.4507129388156654e-05, + "excl_s_unscaled": 1.4731602277606726e-05, + "incl_s": 0.0019676349005610027, + "n_calls": 1.0, + "group": "F_plus_H" + }, + "inversion.zeroed_ids_to_keep": { + "excl_s": 4.491293465477403e-05, + "excl_s_unscaled": 4.560788511298597e-05, + "incl_s": 4.491293465477403e-05, + "n_calls": 1.0, + "group": "F_plus_H" + }, + "inversion.reconstruction": { + "excl_s": 0.007043397753596039, + "excl_s_unscaled": 0.007152382226195186, + "incl_s": 0.20528671632166318, + "n_calls": 1.0, + "group": "solve" + }, + "solver.reconstruction_positive_only_from": { + "excl_s": 0.007470803349266413, + "excl_s_unscaled": 0.007586401188746095, + "incl_s": 0.07007308845292998, + "n_calls": 1.0, + "group": "solve" + }, + "solver.reconstruction_positive_negative_from": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "solve" + }, + "solver.fnnls_cholesky": { + "excl_s": 0.06260228510366357, + "excl_s_unscaled": 0.06357094785198569, + "incl_s": 0.06260228510366357, + "n_calls": 1.0, + "group": "solve" + }, + "solver.nnls_factor_reuse": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "solve" + }, + "inversion.reconstruction_reduced": { + "excl_s": 5.05058607324703e-06, + "excl_s_unscaled": 5.128735210746527e-06, + "incl_s": 5.05058607324703e-06, + "n_calls": 1.0, + "group": "solve" + }, + "inversion.regularization_term": { + "excl_s": 0.0007168488706338159, + "excl_s_unscaled": 0.0007279408746398985, + "incl_s": 0.0007242118319244689, + "n_calls": 1.0, + "group": "evidence" + }, + "inversion.log_det_curvature_reg_matrix_term": { + "excl_s": 0.0399825718586175, + "excl_s_unscaled": 0.04060123342787847, + "incl_s": 0.041950206759178495, + "n_calls": 1.0, + "group": "evidence" + }, + "inversion.log_det_regularization_matrix_term": { + "excl_s": 0.03719965376353001, + "excl_s_unscaled": 0.03777525445912033, + "incl_s": 0.03719965376353001, + "n_calls": 1.0, + "group": "evidence" + }, + "inversion.mapped_reconstructed_operated_data": { + "excl_s": 0.0017249035710899022, + "excl_s_unscaled": 0.0017515934887342155, + "incl_s": 0.20701161989275307, + "n_calls": 1.0, + "group": "evidence" + }, + "fit.model_data": { + "excl_s": 6.0780743324822136e-05, + "excl_s_unscaled": 6.172122084535658e-05, + "incl_s": 0.2070724006360779, + "n_calls": 1.0, + "group": "evidence" + }, + "fit.residual_map": { + "excl_s": 5.376385588893447e-05, + "excl_s_unscaled": 5.459575913846493e-05, + "incl_s": 0.20712616449196683, + "n_calls": 1.0, + "group": "evidence" + }, + "fit.chi_squared_map": { + "excl_s": 4.505907383369316e-05, + "excl_s_unscaled": 4.5756285544484854e-05, + "incl_s": 0.20717122356580053, + "n_calls": 1.0, + "group": "evidence" + }, + "fit.chi_squared": { + "excl_s": 2.032759006899843e-05, + "excl_s_unscaled": 2.0642124582082033e-05, + "incl_s": 0.20719155115586954, + "n_calls": 1.0, + "group": "evidence" + }, + "fit.noise_normalization": { + "excl_s": 0.0001411509004699192, + "excl_s_unscaled": 0.00014333496801555157, + "incl_s": 0.0001411509004699192, + "n_calls": 1.0, + "group": "evidence" + }, + "fit.log_evidence": { + "excl_s": 6.701987455393821e-05, + "excl_s_unscaled": 6.805689190514386e-05, + "incl_s": 0.28727379428552635, + "n_calls": 1.0, + "group": "evidence" + }, + "fit.figure_of_merit": { + "excl_s": 1.161630211189114e-05, + "excl_s_unscaled": 1.179604441858828e-05, + "incl_s": 0.2987231525767265, + "n_calls": 1.0, + "group": "evidence" + }, + "unattributed (call - sum of exclusive times)": { + "excl_s": 0.0009859197307242132, + "excl_s_unscaled": 0.0010011751437559724, + "incl_s": null, + "n_calls": null, + "group": "unattributed" + } + }, + "n_sites_instrumented": 48, + "n_sites_reached": 37, + "cached_site_call_count_violations": {}, + "solver_stats": { + "solver.fnnls_cholesky": { + "seed_source": "memo", + "warm_start_fallback": false, + "outer_iterations": 2, + "inner_iterations": 1, + "n_passive": 1484, + "warm_start_errors": 5 + } + }, + "operated_mapping_matrix_memo_entries_after": 0 + } + }, + "decomposition_method": "likelihood_breakdown.call_accounting wraps ~40 named library descriptors and three module-level solver functions and the PRODUCTION AnalysisImaging.log_likelihood_function is then run untouched. Each row is inclusive time, exclusive (self) time and the number of times the library reached the site; exclusive times are additive by construction, so 'unattributed' is a measured remainder and not an estimate. It is always an explicit row. Rows are rescaled by decomposition_rescale_factor (clean / instrumented) so they sum to the quoted, uninstrumented call. The clean and instrumented calls are COUNTERBALANCED (A B B A per block), so the overhead ratio is free of any drift linear in call index, and the warm-up runs to a steady state with its whole per-call sequence recorded under rows[*].warmup.", + "group_labels": { + "image": "Image + blurring", + "mesh": "Mesh (ray trace, placement, triangulation)", + "mapper": "Mapper + mapping matrix", + "mapper_weights": "Mapper weights (Delaunay)", + "DF": "D and F assembly", + "F_plus_H": "F + lambda H", + "solve": "Positivity solve", + "evidence": "Log determinants + evidence" + }, + "no_pin_note": "NO PIN WAS EVER CALIBRATED HERE. No numba fixed-light configuration has a pinned log likelihood, log evidence or log determinant anywhere in this repo, so every numerical quantity in this JSON is RECORDED, not asserted, and pinned_expected is null. The only hard verdicts this leg carries are the structural gates under `gates` (P1, P2, P3, the S3-equals-S0 mapper block, the per-row dispatch, the cached-access counts, the instrumentation overhead and the coverage), none of which is a calibrated number.", + "pinned_expected": null, + "pinned_drift": [] +} \ No newline at end of file diff --git a/results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_lever1_b_warm_t1.png b/results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_lever1_b_warm_t1.png new file mode 100644 index 000000000..ee99a7bcc Binary files /dev/null and b/results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_lever1_b_warm_t1.png differ diff --git a/results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_lever1_control_b_warm_t1.json b/results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_lever1_control_b_warm_t1.json new file mode 100644 index 000000000..758482e1d --- /dev/null +++ b/results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_lever1_control_b_warm_t1.json @@ -0,0 +1,774 @@ +{ + "autolens_version": "2026.8.17.1", + "timing_status": "measured", + "timing_status_reason": "Load average stayed at or below the core count (2.13 on 124 cores) across the timed rows.", + "contention": { + "load_average_at_start": [ + 1.9, + 0.51, + 0.18 + ], + "load_average_at_end": [ + 2.13, + 0.63, + 0.22 + ], + "cpu_count": 124, + "load_average_peak_1min": 2.13, + "contention_warning": false, + "contention_note": "load_average_at_* are /proc/loadavg's 1/5/15-minute figures, read either side of the timed rows. contention_warning is the 1-minute figure exceeding the core count: the rows were competing for the cores they were timed on, which widens the per-call scatter and can inject multi-call transients. It does not affect any gate under `gates` \u2014 those are exact comparisons of numbers, not of times." + }, + "device": { + "use_jax": false, + "backend": "numba_cpu", + "inversion_paths": [ + "InversionImagingSparseNumba" + ], + "hostname": "euclid-ral-gpu-1", + "omp_num_threads": "1", + "numba_num_threads": "1", + "cpu_count": 124, + "note": "Cell-local. _profile_cli.device_info_dict() is deliberately NOT called: it imports jax unconditionally (_profile_cli.py:392), and a JAX runtime in this process changes the thread pools the numba rows are measured through." + }, + "machine": { + "cpu_model": "AMD EPYC 7702 64-Core Processor", + "cpu_count_os": 124, + "nproc": 1, + "nproc_all": 124, + "nproc_note": "GNU nproc honours OMP_NUM_THREADS, so `nproc` can print 1 on a multi-core host; `nproc_all` is the core count.", + "ram_total": "928298232 kB", + "kernel": "5.14.0-687.39.1.el9_8.x86_64", + "platform": "Linux-5.14.0-687.39.1.el9_8.x86_64-x86_64-with-glibc2.34", + "python": "3.12.4", + "jax_thread_env": { + "NPROC": null + }, + "blas_thread_env": { + "OMP_NUM_THREADS": "1", + "OPENBLAS_NUM_THREADS": "1", + "MKL_NUM_THREADS": "1", + "VECLIB_MAXIMUM_THREADS": "1", + "NUMEXPR_NUM_THREADS": "1" + }, + "thread_env_note": "NPROC sizes XLA's CPU intra-op pool (the JAX rows); the BLAS knobs pin OpenBLAS/MKL/OpenMP (the numpy/scipy rows) and do not touch JAX. Two disjoint families; both are recorded on every CPU timing.", + "gpu": null + }, + "instrument": "hst", + "configuration": { + "mesh": "delaunay", + "dataset": "hst", + "pixel_scale_arcsec": 0.05, + "mask_radius_arcsec": 3.5, + "image_pixels_masked": 15361, + "over_sampled_pixels": 62752, + "source_pixels": 1500, + "mesh_shape": null, + "routes_selected": [ + "b" + ], + "formalisms_selected": [ + "sparse_numba" + ], + "row_order": "grouped", + "n_threads": 1, + "n_repeats": 16, + "instances": "iid", + "iid_seed": 263, + "decompose": true, + "pins_mode": "fp64", + "use_jax": false, + "thread_env": { + "n_threads": 1, + "vars": [ + "OPENBLAS_NUM_THREADS", + "MKL_NUM_THREADS", + "OMP_NUM_THREADS", + "VECLIB_MAXIMUM_THREADS", + "NUMEXPR_NUM_THREADS" + ], + "set_to": "1", + "preexisting": { + "OPENBLAS_NUM_THREADS": "1", + "MKL_NUM_THREADS": "1", + "OMP_NUM_THREADS": "1" + }, + "overridden": {}, + "note": "Set by _production_config.pin_thread_env before numpy import; mirrors the production SLURM submit scripts." + }, + "numba_thread_env": { + "NUMBA_NUM_THREADS": "1", + "preexisting": "1", + "overridden": null, + "note": "Set cell-locally before numpy/numba import. Deliberately NOT added to _production_config.THREAD_ENV_VARS: that tuple is recorded verbatim in every existing numba cell's configuration.thread_env and widening it would change those blocks and the pins that describe them." + }, + "nnls_warm_start_mode": "on", + "nnls_warm_start_env": "1", + "nnls_warm_start_env_preexisting": null, + "memo_cleared_between_rows": true, + "memo_cleared_within_block": false, + "memo_note": "The between-row clears are unconditional; only the WITHIN-BLOCK clears are gated by --nnls-warm-start. With the memo on, a block's calls seed each other (the sampler's regime); with it off every call is a cold dense-sign solve.", + "over_sample_size_lp_rule": { + "sub_size_list": [ + 4, + 2, + 2 + ], + "radial_list": [ + 0.3, + 0.6 + ], + "centre": [ + 0.0, + 0.0 + ] + } + }, + "regularization": { + "scheme": "adapt_split", + "inner_coefficient": 0.1, + "outer_coefficient": 10.0, + "signal_scale": 0.1 + }, + "all_route_keys": [ + "a", + "b", + "c", + "d_np" + ], + "default_route_keys": [ + "a", + "b", + "c" + ], + "all_formalism_keys": [ + "dense", + "sparse_numba" + ], + "systems": { + "s0": { + "n_params": 1560, + "n_mapper": 1500, + "n_funcs": 60, + "edge_zeroed_pixels": 0, + "log_evidence_eager": 19705.717585911676 + }, + "s3": { + "n_params": 1500, + "n_mapper": 1500, + "n_funcs": 0, + "edge_zeroed_pixels": 0, + "subtracted_light_flux": 4945.524141998385, + "log_evidence_eager_dense": 19705.71758591185, + "log_evidence_eager_sparse_numba": 19705.71758591176 + } + }, + "gates": { + "P1_rebaked_operator_equals_original": { + "status": "PASS", + "fields": { + "psf_precision_operator_sparse": true, + "indexes": true, + "lengths": true + }, + "asserted_under_pins_none": true, + "basis": "apply_sparse_operator_cpu builds the operator from the noise map, PSF and mask alone (dataset.py:682-706); subtracting the fixed lens light changes only the data, so the re-baked operator must be identical element for element.", + "summary": "3/3 arrays identical" + }, + "S3_mapper_block_equals_S0": { + "status": "PASS", + "log_dets": { + "log_det_curvature_reg_matrix_term": { + "s0": 8326.70017133483, + "s3": 8326.70017133483, + "rel_diff": 0.0, + "status": "PASS" + }, + "log_det_regularization_matrix_term": { + "s0": 7670.876894312947, + "s3": 7670.876894312947, + "rel_diff": 0.0, + "status": "PASS" + } + }, + "n_edge_zeroed_s0": 0, + "n_edge_zeroed_s3": 0, + "rtol": 1e-06, + "summary": "log-dets rel 0.000e+00, edge-zeroed 0 vs 0" + }, + "P2_dense_equals_sparse_numba_system": { + "status": "PASS", + "data_vector_max_rel_diff": 1.2974807795913263e-15, + "curvature_matrix_mapper_block_max_rel_diff": 3.7275058948429935e-15, + "rtol": 1e-09, + "n_mapper": 1500, + "asserted_under_pins_none": true, + "summary": "D 1.297e-15, F(mapper) 3.728e-15 (rtol 1e-09)" + }, + "P3_dense_equals_sparse_numba_evidence": { + "status": "PASS", + "figure_of_merit_dense": 19705.71758591185, + "figure_of_merit_sparse_numba": 19705.71758591176, + "d_log_evidence_nats": -9.094947017729282e-11, + "rel_diff": 4.6153848384752585e-15, + "rtol": 1e-06, + "n_passive_set_differences": 0, + "n_passive_dense": 1485, + "n_passive_sparse_numba": 1485, + "solver_stats_dense": { + "seed_source": "dense", + "warm_start_fallback": false, + "outer_iterations": 0, + "inner_iterations": 1, + "n_passive": 1485, + "warm_start_errors": 5 + }, + "solver_stats_sparse_numba": { + "seed_source": "dense", + "warm_start_fallback": false, + "outer_iterations": 0, + "inner_iterations": 1, + "n_passive": 1485, + "warm_start_errors": 5 + }, + "summary": "\u0394 -9.094947e-11 nats (rel 4.615e-15), 0 passive-set differences" + } + }, + "gate_thresholds": { + "P2_rtol": 1e-09, + "P3_rtol": 1e-06, + "P4_rtol": 1e-09, + "mapper_logdet_rtol": 1e-06, + "max_instrumentation_overhead_ratio": 1.03, + "min_blocks_for_overhead_assert": 3, + "max_unattributed_fraction": 0.05, + "warmup_window": 3, + "warmup_tolerance": 0.1, + "warmup_max_calls": 12 + }, + "route_c": { + "solve_ids_to_keep_is_none": true, + "edge_zeroing_disabled": true, + "edge_zeroing_note": "Inversion.solve_ids_to_keep returns None the moment use_positive_only_solver is False (abstract.py:540-546), so turning positivity off silently turns edge zeroing off with it. Route c solves the FULL system; routes a and b solve the edge-zeroed one.", + "log_evidence_eager": 19783.98705569277, + "d_log_evidence_vs_route_b": 78.26946978092019, + "n_negative_entries": 10, + "negative_flux_fraction": 9.879318261208077e-05, + "note": "Never quote route c's milliseconds without these numbers. The unconstrained solution sits at a HIGHER evidence than the constrained optimum because it is a different, infeasible minimiser." + }, + "rows": { + "b_sparse_numba": { + "route": "b", + "formalism": "sparse_numba", + "label": "S3 fnnls source-only (the reference) [sparse_numba]", + "inversion_class": "InversionImagingSparseNumba", + "n_repeats": 16, + "warmup": { + "sequence_s": [ + 0.4699607817456126, + 0.4026111620478332, + 0.41600668290629983, + 0.4144584918394685, + 0.40638109715655446, + 0.4141521751880646 + ], + "n_calls": 6, + "steady": true, + "window": 3, + "tolerance": 0.1, + "max_calls": 12, + "first_call_incl_numba_compile_s": 0.4699607817456126, + "note": "Warm-up ran to a steady state, not to a fixed count: calls repeat until the median of the last `window` agrees with the median of the previous `window` to `tolerance`, or `max_calls` is hit. Every call is recorded. `steady: false` means the row's timings were taken on a host that never settled and should be read with the sequence in hand." + }, + "warmup_incl_numba_compile_s": 0.4699607817456126, + "row_order": "grouped", + "memo_cleared_between_rows": true, + "memo_cleared_within_block": false, + "nnls_warm_start_mode": "on", + "nnls_warm_start_env": "1", + "operated_mapping_matrix_memo_entries_before": 0, + "decomposed": true, + "call_ms": 413.30131035647355, + "call_ms_median": 411.13529610447586, + "call_ms_min": 398.487351834774, + "call_ms_max": 466.9346669688821, + "call_ms_sequence": [ + 420.38724198937416, + 404.7317272052169, + 416.5037269704044, + 417.08598006516695, + 418.51091384887695, + 408.73077884316444, + 398.487351834774, + 401.25000942498446, + 416.90377332270145, + 399.10108409821987, + 400.3357901237905, + 414.53862003982067, + 410.86204443126917, + 466.9346669688821, + 407.04870875924826, + 411.40854777768254 + ], + "clean_relative_spread": 0.16561117378280765, + "n_clean_calls": 16, + "log_likelihood": 18665.014334145228, + "log_likelihood_sequence": [ + 19497.35174868952, + 19651.457884697327, + 19328.369614256386, + 19488.202055828602, + 18847.16626547022, + 19319.244429423128, + 19014.188491645276, + 19652.641982502628, + 18982.846275923246, + 19314.213619474776, + 19705.71758591176, + 18820.528845843237, + 18656.216134096525, + 19403.96980059209, + 18665.014334145228, + 19343.4137410371, + 18791.303045235916, + 19497.35174868952, + 19651.457884697153, + 19328.369614256895, + 19488.202055828788, + 18847.166265470227, + 19319.244429423157, + 19014.188491645313, + 19652.641982502777, + 18982.84627592324, + 19314.213619474453, + 19705.71758591176, + 18820.528845843237, + 18656.216134096525, + 19403.96980059209, + 18665.014334145228 + ], + "cpu_over_wall": 1.0002884709918158, + "cpu_over_wall_note": "time.process_time() sums every thread of the process, so this is the effective thread count of the timed calls. At --threads 1 it should sit just above 1.0; anything higher means a pool this cell did not pin.", + "call_ms_instrumented": 419.15473822155036, + "call_ms_instrumented_sequence": [ + 477.75171836838126, + 418.7545217573643, + 417.1074707992375, + 418.7444900162518, + 426.5008680522442, + 468.20601308718324, + 409.83388666063547, + 406.74729319289327, + 415.14673409983516, + 403.50953210145235, + 405.614516697824, + 404.4453501701355, + 409.09045515581965, + 419.44248182699084, + 396.2945966050029, + 409.2858829535544 + ], + "n_instrumented_calls": 16, + "abba": { + "n_blocks": 8, + "block_ratios": [ + 1.0865175491006303, + 1.00271386961814, + 1.081554386152659, + 1.021061687761139, + 1.0032492561242174, + 0.9940916744524042, + 0.9438779232394693, + 0.9842670134872309 + ], + "ratio_mean": 1.0146666699919864, + "ratio_median": 1.0029815628711787, + "ratio_min": 0.9438779232394693, + "ratio_max": 1.0865175491006303, + "design": "A B B A per block; ratio = mean(B) / mean(A)", + "why": "A B B A straddles the two instrumented calls with one clean call either side, so a drift linear in call index cancels exactly in the ratio. A sequential 'all clean then all instrumented' design charges the whole drift over the row to the instrumentation: measured on this configuration it returned 0.71, 0.98, 1.10, 1.11, 1.24 and 1.37 across six rows of one leg \u2014 including ratios below 1, which no real instrumentation can produce." + }, + "instrumentation_overhead_ratio": 1.0146666699919864, + "instrumentation_overhead_status": "PASS", + "instrumentation_overhead_assertable": true, + "instrumentation_overhead_threshold": 1.03, + "min_blocks_for_overhead_assert": 3, + "decomposition_rescale_factor": 0.986035162360534, + "attributed_ms": 417.8638940793462, + "unattributed_ms": 1.2908441422041506, + "unattributed_fraction": 0.0030796362882145353, + "steps": { + "fit.blurred_image": { + "excl_s": 0.002641620797688788, + "excl_s_unscaled": 0.002679033059393987, + "incl_s": 0.002641620797688788, + "n_calls": 1.0, + "group": "image" + }, + "fit.profile_subtracted_image": { + "excl_s": 7.001210022865087e-05, + "excl_s_unscaled": 7.100365473888814e-05, + "incl_s": 0.002711632897917439, + "n_calls": 1.0, + "group": "image" + }, + "fit.tracer_to_inversion": { + "excl_s": 1.3977011367602198e-05, + "excl_s_unscaled": 1.4174962416291237e-05, + "incl_s": 0.0027256099092850413, + "n_calls": 1.0, + "group": "mesh" + }, + "to_inversion.traced_grid_2d_list_of_inversion": { + "excl_s": 0.0008907600988414261, + "excl_s_unscaled": 0.0009033755923155695, + "incl_s": 0.0008907600988414261, + "n_calls": 1.0, + "group": "mesh" + }, + "to_inversion.image_plane_mesh_grid_pg_list": { + "excl_s": 4.1006805632296504e-05, + "excl_s_unscaled": 4.1587569285184145e-05, + "incl_s": 4.1006805632296504e-05, + "n_calls": 1.0, + "group": "mesh" + }, + "to_inversion.traced_mesh_grid_pg_list": { + "excl_s": 0.0003829357262473929, + "excl_s_unscaled": 0.00038835909799672663, + "incl_s": 0.0004239425318796894, + "n_calls": 1.0, + "group": "mesh" + }, + "delaunay.mesh_geometry": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "mesh" + }, + "delaunay.triangulation": { + "excl_s": 0.01881631858813972, + "excl_s_unscaled": 0.01908280688803643, + "incl_s": 0.01881631858813972, + "n_calls": 1.0, + "group": "mesh" + }, + "to_inversion.lp_linear_func_list_galaxy_dict": { + "excl_s": 0.0072646386401312175, + "excl_s_unscaled": 0.007367524929577485, + "incl_s": 0.0072646386401312175, + "n_calls": 1.0, + "group": "mapper" + }, + "to_inversion.mapper_galaxy_dict": { + "excl_s": 0.001269442325130099, + "excl_s_unscaled": 0.0012874209496658295, + "incl_s": 0.0025841449558512146, + "n_calls": 1.0, + "group": "mapper" + }, + "mapper.unique_mappings": { + "excl_s": 0.0022631928877605966, + "excl_s_unscaled": 0.0022952456201892346, + "incl_s": 0.02363609332500171, + "n_calls": 1.0, + "group": "mapper" + }, + "mapper.mapping_matrix": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "mapper" + }, + "mapper.sparse_triplets_data": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "mapper" + }, + "mapper.sparse_triplets_curvature": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "mapper" + }, + "delaunay.mappings_sizes_weights": { + "excl_s": 0.0025565818491013947, + "excl_s_unscaled": 0.002592789736809209, + "incl_s": 0.02137290043724111, + "n_calls": 1.0, + "group": "mapper_weights" + }, + "delaunay.mappings_sizes_weights_split": { + "excl_s": 0.0012247503141550396, + "excl_s_unscaled": 0.0012420959828887135, + "incl_s": 0.0012247503141550396, + "n_calls": 1.0, + "group": "mapper_weights" + }, + "inversion.to_inversion": { + "excl_s": 2.853405458783899e-05, + "excl_s_unscaled": 2.8938171453773975e-05, + "incl_s": 0.009877317650570271, + "n_calls": 1.0, + "group": "DF" + }, + "fit.inversion": { + "excl_s": 7.42628165395524e-05, + "excl_s_unscaled": 7.531457231380045e-05, + "incl_s": 0.012677190376394865, + "n_calls": 1.0, + "group": "DF" + }, + "inversion.operated_mapping_matrix": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "DF" + }, + "inversion.linear_func_operated_mapping_matrix_dict": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "DF" + }, + "sparse_numba.linear_func_operated_mapping_matrix_dict": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "DF" + }, + "sparse_numba.psf_weighted_data": { + "excl_s": 0.008399457156361317, + "excl_s_unscaled": 0.008518415444996208, + "incl_s": 0.008399457156361317, + "n_calls": 1.0, + "group": "DF" + }, + "sparse_numba.data_vector": { + "excl_s": 6.532670439707567e-05, + "excl_s_unscaled": 6.625190144404769e-05, + "incl_s": 0.0321008771857601, + "n_calls": 1.0, + "group": "DF" + }, + "sparse_numba.curvature_matrix": { + "excl_s": 0.08961524924332953, + "excl_s_unscaled": 0.09088443563086912, + "incl_s": 0.08961524924332953, + "n_calls": 1.0, + "group": "DF" + }, + "dense.data_vector": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "DF" + }, + "dense.curvature_matrix": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "DF" + }, + "inversion.regularization_matrix": { + "excl_s": 0.11059897984589565, + "excl_s_unscaled": 0.11216535075800493, + "incl_s": 0.11182373016005068, + "n_calls": 1.0, + "group": "F_plus_H" + }, + "inversion.regularization_matrix_reduced": { + "excl_s": 2.2992357032002762e-06, + "excl_s_unscaled": 2.3317988961935043e-06, + "incl_s": 2.2992357032002762e-06, + "n_calls": 1.0, + "group": "F_plus_H" + }, + "inversion.curvature_reg_matrix": { + "excl_s": 0.004260747659322256, + "excl_s_unscaled": 0.004321090993471444, + "incl_s": 0.20569972706270248, + "n_calls": 2.0, + "group": "F_plus_H" + }, + "inversion.curvature_reg_matrix_reduced": { + "excl_s": 1.9987394863336917e-05, + "excl_s_unscaled": 2.0270468667149544e-05, + "incl_s": 0.0021388568959468095, + "n_calls": 1.0, + "group": "F_plus_H" + }, + "inversion.zeroed_ids_to_keep": { + "excl_s": 4.853545378246849e-05, + "excl_s_unscaled": 4.9222842790186405e-05, + "incl_s": 4.853545378246849e-05, + "n_calls": 1.0, + "group": "F_plus_H" + }, + "inversion.reconstruction": { + "excl_s": 0.007322313613228707, + "excl_s_unscaled": 0.007426016731187701, + "incl_s": 0.3158508335573054, + "n_calls": 1.0, + "group": "solve" + }, + "solver.reconstruction_positive_only_from": { + "excl_s": 0.007747939362419124, + "excl_s_unscaled": 0.007857670454541221, + "incl_s": 0.07279824974291514, + "n_calls": 1.0, + "group": "solve" + }, + "solver.reconstruction_positive_negative_from": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "solve" + }, + "solver.fnnls_cholesky": { + "excl_s": 0.06505031038049602, + "excl_s_unscaled": 0.06597159296507016, + "incl_s": 0.06505031038049602, + "n_calls": 1.0, + "group": "solve" + }, + "solver.nnls_factor_reuse": { + "excl_s": 0.0, + "excl_s_unscaled": 0.0, + "incl_s": 0.0, + "n_calls": 0.0, + "group": "solve" + }, + "inversion.reconstruction_reduced": { + "excl_s": 5.242584553658792e-06, + "excl_s_unscaled": 5.316833266988397e-06, + "incl_s": 5.242584553658792e-06, + "n_calls": 1.0, + "group": "solve" + }, + "inversion.regularization_term": { + "excl_s": 0.0007615590080760761, + "excl_s_unscaled": 0.0007723446760792285, + "incl_s": 0.0007691008283329352, + "n_calls": 1.0, + "group": "evidence" + }, + "inversion.log_det_curvature_reg_matrix_term": { + "excl_s": 0.0405951732806892, + "excl_s_unscaled": 0.04117010714253411, + "incl_s": 0.04273403017663601, + "n_calls": 1.0, + "group": "evidence" + }, + "inversion.log_det_regularization_matrix_term": { + "excl_s": 0.03780858991912886, + "excl_s_unscaled": 0.03834405847010203, + "incl_s": 0.03780858991912886, + "n_calls": 1.0, + "group": "evidence" + }, + "inversion.mapped_reconstructed_operated_data": { + "excl_s": 0.0017805665256797477, + "excl_s_unscaled": 0.0018057840061374009, + "incl_s": 0.3176314000829852, + "n_calls": 1.0, + "group": "evidence" + }, + "fit.model_data": { + "excl_s": 6.416316830638351e-05, + "excl_s_unscaled": 6.507188663817942e-05, + "incl_s": 0.31769556325129156, + "n_calls": 1.0, + "group": "evidence" + }, + "fit.residual_map": { + "excl_s": 5.409393931741571e-05, + "excl_s_unscaled": 5.4860051022842526e-05, + "incl_s": 0.317749657190609, + "n_calls": 1.0, + "group": "evidence" + }, + "fit.chi_squared_map": { + "excl_s": 4.200458553949284e-05, + "excl_s_unscaled": 4.259948036633432e-05, + "incl_s": 0.3177916617761485, + "n_calls": 1.0, + "group": "evidence" + }, + "fit.chi_squared": { + "excl_s": 2.0489025418653205e-05, + "excl_s_unscaled": 2.077920362353325e-05, + "incl_s": 0.3178121508015671, + "n_calls": 1.0, + "group": "evidence" + }, + "fit.noise_normalization": { + "excl_s": 0.00015102420092402287, + "excl_s_unscaled": 0.00015316309873014688, + "incl_s": 0.00015102420092402287, + "n_calls": 1.0, + "group": "evidence" + }, + "fit.log_evidence": { + "excl_s": 6.63532104018619e-05, + "excl_s_unscaled": 6.729294545948505e-05, + "incl_s": 0.3993412491369908, + "n_calls": 1.0, + "group": "evidence" + }, + "fit.figure_of_merit": { + "excl_s": 1.0053129747461366e-05, + "excl_s_unscaled": 1.0195508366450667e-05, + "incl_s": 0.4120284926431331, + "n_calls": 1.0, + "group": "evidence" + }, + "unattributed (call - sum of exclusive times)": { + "excl_s": 0.001272817713340414, + "excl_s_unscaled": 0.0012908441422041506, + "incl_s": null, + "n_calls": null, + "group": "unattributed" + } + }, + "n_sites_instrumented": 48, + "n_sites_reached": 37, + "cached_site_call_count_violations": {}, + "solver_stats": { + "solver.fnnls_cholesky": { + "seed_source": "memo", + "warm_start_fallback": false, + "outer_iterations": 2, + "inner_iterations": 1, + "n_passive": 1484, + "warm_start_errors": 5 + } + }, + "operated_mapping_matrix_memo_entries_after": 0 + } + }, + "decomposition_method": "likelihood_breakdown.call_accounting wraps ~40 named library descriptors and three module-level solver functions and the PRODUCTION AnalysisImaging.log_likelihood_function is then run untouched. Each row is inclusive time, exclusive (self) time and the number of times the library reached the site; exclusive times are additive by construction, so 'unattributed' is a measured remainder and not an estimate. It is always an explicit row. Rows are rescaled by decomposition_rescale_factor (clean / instrumented) so they sum to the quoted, uninstrumented call. The clean and instrumented calls are COUNTERBALANCED (A B B A per block), so the overhead ratio is free of any drift linear in call index, and the warm-up runs to a steady state with its whole per-call sequence recorded under rows[*].warmup.", + "group_labels": { + "image": "Image + blurring", + "mesh": "Mesh (ray trace, placement, triangulation)", + "mapper": "Mapper + mapping matrix", + "mapper_weights": "Mapper weights (Delaunay)", + "DF": "D and F assembly", + "F_plus_H": "F + lambda H", + "solve": "Positivity solve", + "evidence": "Log determinants + evidence" + }, + "no_pin_note": "NO PIN WAS EVER CALIBRATED HERE. No numba fixed-light configuration has a pinned log likelihood, log evidence or log determinant anywhere in this repo, so every numerical quantity in this JSON is RECORDED, not asserted, and pinned_expected is null. The only hard verdicts this leg carries are the structural gates under `gates` (P1, P2, P3, the S3-equals-S0 mapper block, the per-row dispatch, the cached-access counts, the instrumentation overhead and the coverage), none of which is a calibrated number.", + "pinned_expected": null, + "pinned_drift": [] +} \ No newline at end of file diff --git a/results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_lever1_control_b_warm_t1.png b/results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_lever1_control_b_warm_t1.png new file mode 100644 index 000000000..3c72a3278 Binary files /dev/null and b/results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_lever1_control_b_warm_t1.png differ diff --git a/results/breakdown/imaging/fixed_light_numba_levers_witness_hpc_ral_cpu_fp64_lever1.json b/results/breakdown/imaging/fixed_light_numba_levers_witness_hpc_ral_cpu_fp64_lever1.json new file mode 100644 index 000000000..a856e7e51 --- /dev/null +++ b/results/breakdown/imaging/fixed_light_numba_levers_witness_hpc_ral_cpu_fp64_lever1.json @@ -0,0 +1,133 @@ +{ + "cell": "fixed_light_numba_levers_witness", + "issue": "autolens_profiling#267 (lever 1: numba split-regularization assembly)", + "verdict": "PASS", + "results": { + "W1_regularization_matrix_bit_identical": { + "status": "PASS", + "array_equal": true, + "max_abs_diff": 0.0, + "shape": [ + 1500, + 1500 + ], + "n_zero_size_stencil_rows": 0, + "reference_wall_s": 0.1068422794342041, + "library_wall_s": 0.006465435028076172, + "summary": "array_equal=True, max|diff|=0.000e+00, zero-size rows=0, reference 106.8 ms vs library 6.5 ms" + }, + "W2_interpolator_tables_unmutated": { + "status": "PASS", + "mappings_unchanged": true, + "sizes_unchanged": true, + "weights_unchanged": true, + "summary": "mappings=True, sizes=True, weights=True" + }, + "W3_log_evidence_identical": { + "status": "PASS", + "figure_of_merit_kernel": 19705.71758591176, + "figure_of_merit_reference": 19705.71758591176, + "d_log_evidence_nats": 0.0, + "relative_difference": 0.0, + "rtol": 1e-09, + "monkeypatch_calls": { + "reg_split": 1, + "pixel_splitted": 1 + }, + "monkeypatch_fired": true, + "summary": "kernel 19705.717585911760 vs reference 19705.717585911760 (rel 0.000e+00 <= 1e-09), patch calls {'reg_split': 1, 'pixel_splitted': 1}" + } + }, + "configuration": { + "config_name": "hpc_ral_cpu_fp64_lever1", + "mesh": "delaunay", + "dataset": "hst", + "source_pixels": 1500, + "mesh_vertices_placed": 1500, + "regularization": { + "scheme": "adapt_split", + "inner_coefficient": 0.1, + "outer_coefficient": 10.0, + "signal_scale": 0.1 + }, + "threads": 1, + "thread_env": { + "n_threads": 1, + "vars": [ + "OPENBLAS_NUM_THREADS", + "MKL_NUM_THREADS", + "OMP_NUM_THREADS", + "VECLIB_MAXIMUM_THREADS", + "NUMEXPR_NUM_THREADS" + ], + "set_to": "1", + "preexisting": { + "OPENBLAS_NUM_THREADS": "1", + "MKL_NUM_THREADS": "1", + "OMP_NUM_THREADS": "1" + }, + "overridden": {}, + "note": "Set by _production_config.pin_thread_env before numpy import; mirrors the production SLURM submit scripts." + }, + "numba_thread_env": { + "NUMBA_NUM_THREADS": "1", + "preexisting": "1" + }, + "nnls_warm_start_env": "0", + "use_jax": false, + "instance_seed": 263, + "w3_rtol": 1e-09 + }, + "system": { + "n_params": 1500, + "n_mapper": 1500, + "n_funcs": 0, + "edge_zeroed_pixels": 0, + "subtracted_light_flux": 4945.524141998385, + "mapper_params": 1500, + "h_shape_full": [ + 1500, + 1500 + ], + "h_sliced_to_mapper_block": false, + "stencil_mappings_shape": [ + 6000, + 4 + ], + "stencil_sizes_max": 3, + "n_zero_size_stencil_rows": 0 + }, + "provenance": { + "autoarray_file": "/mnt/ral/jnightin/PyAuto_wt/fixed-light-numba-levers/PyAutoArray_feature/autoarray/__init__.py", + "autoarray_version": "2026.8.17.1", + "autolens_version": "2026.8.17.1", + "hostname": "euclid-ral-gpu-1", + "slurm_job_id": "343345", + "jax_in_sys_modules": true, + "wall_s": 12.747674465179443 + }, + "machine": { + "cpu_model": "AMD EPYC 7702 64-Core Processor", + "cpu_count_os": 124, + "nproc": 1, + "nproc_all": 124, + "nproc_note": "GNU nproc honours OMP_NUM_THREADS, so `nproc` can print 1 on a multi-core host; `nproc_all` is the core count.", + "ram_total": "928298232 kB", + "kernel": "5.14.0-687.39.1.el9_8.x86_64", + "platform": "Linux-5.14.0-687.39.1.el9_8.x86_64-x86_64-with-glibc2.34", + "python": "3.12.4", + "jax_thread_env": { + "NPROC": null + }, + "blas_thread_env": { + "OMP_NUM_THREADS": "1", + "OPENBLAS_NUM_THREADS": "1", + "MKL_NUM_THREADS": "1", + "VECLIB_MAXIMUM_THREADS": "1", + "NUMEXPR_NUM_THREADS": "1" + }, + "thread_env_note": "NPROC sizes XLA's CPU intra-op pool (the JAX rows); the BLAS knobs pin OpenBLAS/MKL/OpenMP (the numpy/scipy rows) and do not touch JAX. Two disjoint families; both are recorded on every CPU timing.", + "gpu": null + }, + "notes": "W1 asserts np.array_equal between the retained pure-Python reference chain (_reg_split_reference -> _pixel_splitted_regularization_matrix_reference) and the library's own inversion.regularization_matrix on the HST Delaunay N=1500 source-only (S3) AdaptSplit system fixed_light_numba.py route b builds. W2 asserts the interpolator's cached stencil tables are byte-identical after the library inversion. W3 asserts the fit's figure_of_merit is unchanged when both numpy entry points are monkeypatched to the references. No timing is taken here and no pin is asserted; the A/B milliseconds are the two arms of hpc/batch_cpu/submit_breakdown_imaging_fixed_light_numba_levers_delaunay_ral_hst_fp64." +} \ No newline at end of file diff --git a/results/notes/fixed_lens_light_levers_2026_09.md b/results/notes/fixed_lens_light_levers_2026_09.md new file mode 100644 index 000000000..88ff3799d --- /dev/null +++ b/results/notes/fixed_lens_light_levers_2026_09.md @@ -0,0 +1,439 @@ +# Fixed lens light on the numba CPU path — the three levers (2026-09-16) + +autolens_profiling issue [#267](https://github.com/PyAutoLabs/autolens_profiling/issues/267), +epic `fixed-lens-light-numba-cpu` phase 3, branch `feature/fixed-light-numba-levers`. +Phase 2 ([`fixed_lens_light_numba_2026_09.md`](./fixed_lens_light_numba_2026_09.md)) closed the +solver and left a memo-invariant, non-solver residue in the production numba CPU likelihood call: +`inversion.regularization_matrix` at 111.5 ms, the two log-dets at 40.2 + 37.5 ms, and +`sparse_numba.curvature_matrix` at 87.4 ms of a 404.6 ms call. Phase 3 attacks that residue in three +levers, each paired with an A100 row: **lever 1** numba-jit the split-regularization assembly, +**lever 2** log det H from sparsity, **lever 3** one shared Cholesky of `F + λH`. +**Lever 1 is measured; levers 2 and 3 are pending** and will be appended here as their own sections. + +**Lever 1's result: 1.379× on the production numba CPU route (413.301 → 299.709 ms), and identity +on the A100.** `inversion.regularization_matrix` falls 110.599 → 5.924 ms — 26.8 % of the call to +2.0 % — with the regularization matrix bit-identical, the interpolators' cached stencil tables +unmutated, and the fit's `figure_of_merit` unchanged at relative difference exactly 0.0. The A100 +arm is identity to 0.036 % on the whole call because lever 1 changed only the `xp==np` branch, which +the GPU cell never reaches; its one finding is negative and structural — **the `#536` compaction +constants `SPLIT_REG_COMPACT_WIDTH` and `SPLIT_REG_WIDE_ROW_BUDGET` are inert at this +configuration**, because `InterpolatorDelaunay`'s stencil table is K = 4 wide. + +## Scope — read this before quoting a number + +- **Route b, memo ON, is what production pays.** Both arms are phase 2's Leg D cell and nothing + else: `fixed_light_numba.py --mesh delaunay --dataset hst --formalism sparse_numba --routes b + --threads 1 --n-repeats 16 --instances iid --nnls-warm-start on`. Route **b** is the source-only + **S3** system (1500 params) the `fixed-lens-light` campaign established; the cross-evaluation NNLS + memo is **on**, which is the library default and therefore production. `configuration.routes_selected` + is `["b"]` and `nnls_warm_start_mode` is `"on"` in both JSONs — check them before quoting, because + `parse_profile_cli` uses `parse_known_args` and silently ignores a mistyped flag. +- **S3 source-only only.** Route **a** (the joint S0 system the library solves today) was not + re-measured in this phase, so **no "a → lever 1" ratio exists** and none is quoted. Route **c** + (positivity off) **is not present in either arm** — it is a diagnostic, it silently turns edge + zeroing off as well, and phase 2's prohibition on quoting its milliseconds carries here unchanged. +- **`log_likelihood` is never compared across legs.** `--instances iid` rotates a call index, so the + last-timed instance depends on the route count and the leg. Both arms here printed the *same* + `log_likelihood` **18665.014334145228** and the same 32-entry `log_likelihood_sequence`, which is + what a deterministic iid stream from `iid_seed: 263` on the same route set must do. **Record it as + an observation of stream determinism, never as a cross-leg comparison and never as the equivalence + evidence** — the equivalence evidence is the witness's W1/W3 and the gates. +- **1.379× is a lower bound.** The scheduler placed both jobs on `euclid-ral-gpu-1`, so the feature + arm's timed rows started at 1-minute loadavg **2.25** against the control arm's **1.90** (both on + 124 cores; `contention.load_average_at_start`). The asymmetry is small and it works *against* the + feature arm. Both arms stamp `timing_status: "measured"` and `contention_warning: false`. +- **The A100 numbers are `delaunay.py` prefix differences, not standalone timings.** The cell times + nested jitted prefixes of one inversion setup; `steps["Regularization matrix (H)"]` is the + **difference of two jitted prefixes** — `regularization_matrix_prefix_s` minus + `interpolator_prefix_s` (0.0073318 − 0.0071154 = 0.0002164 s in the control arm, exactly the H + step). A 20 µs "H difference" between the two arms is 0.3 % of a 7.1 ms prefix and is prefix + scatter, not an H change. Judge the A100 arms on the prefixes and on `total_step_by_step`. +- **The compaction constants are unobservable in this row.** `InterpolatorDelaunay` gives a stencil + table of width **K = 4**, so `kc = min(K, SPLIT_REG_COMPACT_WIDTH=12) = 4`, the head scatter + already covers every column and the `if K > kc` supplement is a **static Python branch XLA never + traces**. Neither constant can be measured, tuned or validated on this cell — see + "Lever 1 — the A100 row and the compaction finding". +- **No pin exists here.** `pinned_expected` is `null` and `pinned_drift` is empty in both arms; the + `no_pin_note` block says the same. Every millisecond is RECORDED. The hard verdicts are the + structural gates (`gates`), the witness's W1–W3, and the A100 cell's own eager regression assertion. +- **Single-threaded only**, as in phase 2: production runs one single-threaded numba likelihood per + pool worker. `n_threads: 1`, `NUMBA_NUM_THREADS: "1"` and the whole BLAS family pinned to `"1"` in + both arms; `cpu_over_wall` 1.0003 / 1.0004, so no pool went unpinned. +- **The control is a private merge-base checkout, not the shared install.** The shared + `/mnt/ral/jnightin/PyAuto` venv also carries PyAutoArray `5e2bc0f4`, but it was **not** used as the + control: each arm prepends its own PyAutoArray checkout to `PYTHONPATH` inside its own subshell and + prints `autoarray.__file__`, so the A/B is symmetric in how the library is reached. +- **The process is not JAX-free**, as in phase 2: `jax_in_sys_modules` is `true` in the witness JSON. + Recorded, not fixed (PyAutoArray bug, still unfiled). + +## Provenance + +Two SLURM jobs, one node, 2026-09-16. + +| | CPU A/B + witness | A100 A/B | +|---|---|---| +| Job | **343345**, `COMPLETED 0:0` | **343346**, `COMPLETED 0:0` | +| Elapsed / MaxRSS | 00:02:16 / 2 079 124 K of 32 GB | 00:03:29 / 3 692 788 K of 64 GB | +| Node | **euclid-ral-gpu-1** | **euclid-ral-gpu-1** | +| Partition | `gpu` CPUs-only, `--cpus-per-task=4 --mem=32gb`, **no `--gres`** | `gpu`, `--gres=gpu:1 --cpus-per-task=4 --mem=64gb` | +| Device | AMD EPYC 7702 64-Core, `os.cpu_count()` 124, kernel 5.14.0-687.39.1.el9_8 | NVIDIA A100 80GB PCIe (`nvidia_smi`), `cuda:0` | +| Job loadavg, entry → exit | `0.00 0.00 0.00` → `2.16 0.96 0.37` | `0.00 0.00 0.00` → `1.96 1.18 0.49` | +| Cell | `scripts/imaging/likelihood_breakdown/fixed_light_numba.py` | `scripts/imaging/likelihood_breakdown/delaunay.py` | +| Python / autolens | 3.12.4 / 2026.8.17.1 | 2026.8.17.1 | +| `AP_ROOT` | `/mnt/ral/jnightin/autolens_profiling_wt/fixed-light-numba-levers` @ `7c7968c4`, branch `feature/fixed-light-numba-levers` | same worktree | + +Per-arm checkouts and config names: + +| Arm | PyAutoArray checkout | rev | config name | +|---|---|---|---| +| CPU control | `/mnt/ral/jnightin/PyAuto_wt/fixed-light-numba-levers/PyAutoArray_control` | `5e2bc0f42940adfe04ff30fa42a7ce13a86ecbe0` (merge base) | `hpc_ral_cpu_fp64_fixed_light_numba_lever1_control_b_warm_t1` | +| CPU feature | `.../PyAutoArray_feature` | `bae9296ed528da6812613edc2ebc6ea367361ebb` (lever 1) | `hpc_ral_cpu_fp64_fixed_light_numba_lever1_b_warm_t1` | +| CPU witness | `.../PyAutoArray_feature` | `bae9296e` | `hpc_ral_cpu_fp64_lever1` | +| A100 control | `.../PyAutoArray_control` | `5e2bc0f4` | `hpc_a100_fp64_lever1_control` | +| A100 feature | `.../PyAutoArray_feature` | `bae9296e` | `hpc_a100_fp64_lever1` | + +The rest of the stack is the shared RAL install, untouched and identical for all four arms: + +| Repo | rev | +|---|---| +| PyAutoNerves | `fac8b17b962adc272e0aaae81e951d58b13bcce3` | +| PyAutoFit | `27d41e7c8d235a8aedbc1afa88cadf0863d68fe8` | +| PyAutoArray (shared install, **not** the control) | `5e2bc0f42940adfe04ff30fa42a7ce13a86ecbe0` | +| PyAutoGalaxy | `840ffde063fae1c7bfb41986f7c62b6ca96df3b7` | +| PyAutoLens | `ccf9295f32ec3ad897d4c809c76f33987ce2b0ed` | + +System under test, identical in both CPU arms: HST, `pixel_scale` 0.05″, mask 3.5″, **15 361** masked +image pixels, 62 752 over-sampled pixels, Hilbert/Delaunay mesh at **1500** source pixels, +`AdaptSplit(inner=0.1, outer=10.0, signal_scale=0.1)`, fp64, `InversionImagingSparseNumba`, +`use_jax=False`, `n_edge_zeroed` 0, `--instances iid` from `iid_seed` 263. +The A100 cell runs the same dataset and mesh on the **dense** JAX path (`inversion_path: "dense"`, +`total_params` 1560, `vmap_batch` 16, XLA flags +`--xla_disable_hlo_passes=constant_folding --xla_gpu_autotune_level=0 --xla_gpu_enable_triton_gemm=false`). + +## Gate roll-up + +Cell gates, both CPU arms (`gates` in each JSON; thresholds in `gate_thresholds`): + +| Gate | control | feature | value (identical in both arms) | +|---|---|---|---| +| `P1_rebaked_operator_equals_original` | **PASS** | **PASS** | 3/3 arrays identical | +| `S3_mapper_block_equals_S0` | **PASS** | **PASS** | log-dets 8326.70017133483 / 7670.876894312947, rel diff **0.0**, edge-zeroed 0 vs 0 | +| `P2_dense_equals_sparse_numba_system` | **PASS** | **PASS** | D 1.297e-15, F(mapper) 3.728e-15 (rtol 1e-09) | +| `P3_dense_equals_sparse_numba_evidence` | **PASS** | **PASS** | Δ −9.094947e-11 nats (rel 4.615e-15), **0** passive-set differences, 1485 passive both sides | +| `instrumentation_overhead_ratio` (≤ 1.03) | 1.0147 **PASS** | 1.0163 **PASS** | 8 ABBA blocks each | +| `unattributed_fraction` (≤ 0.05) | 0.00308 | 0.00329 | explicit measured remainder | +| `cached_site_call_count_violations` | `{}` | `{}` | — | +| `timing_status` / `contention_warning` | measured / false | measured / false | peak 1-min loadavg 2.13 / 2.25 on 124 cores | + +Every `gates` field is **byte-identical between the two arms**, including +`P3.figure_of_merit_sparse_numba` = 19705.71758591176 and the S3 = S0 log-dets. That is the first +equivalence statement: the two library revisions produce the same numbers on the same system. + +Solver state, both arms: `seed_source` `"memo"`, `warm_start_fallback` `false`, `n_passive` **1484**, +`outer_iterations` 2, `inner_iterations` 1, `memo_cleared_within_block: false` — the rows are +genuinely warm, and the solver saw the same problem in both arms. + +Witness (`fixed_light_numba_levers_witness.py`, **verdict PASS**, run inside the feature arm's +subshell, wall 12.75 s, `slurm_job_id` 343345, `nnls_warm_start_env: "0"` — the witness takes no +timing, so the memo setting is irrelevant to it): + +| Gate | status | evidence | +|---|---|---| +| **W1** H bit-identical | **PASS** | `np.array_equal` retained pure-Python reference chain vs the library's `inversion.regularization_matrix`: `array_equal` **true**, `max_abs_diff` **0.0**, shape (1500, 1500), `n_zero_size_stencil_rows` **0**. Same matrix: reference 106.8 ms, library **6.5 ms** | +| **W2** interpolator tables unmutated | **PASS** | `mappings_unchanged` / `sizes_unchanged` / `weights_unchanged` all **true** after the library inversion | +| **W3** evidence unchanged | **PASS** | `figure_of_merit` kernel **19705.71758591176** vs reference **19705.71758591176**, `d_log_evidence_nats` **0.0**, `relative_difference` **0.0** (rtol 1e-09); `monkeypatch_calls` `{reg_split: 1, pixel_splitted: 1}`, `monkeypatch_fired` true | + +Witness system block: `InversionImagingSparseNumba`, `InterpolatorDelaunay`, `AdaptSplit`, `n_params` +1500, `n_funcs` 0, `edge_zeroed_pixels` 0, stencil tables **mappings (6000, 4) int64, sizes (6000,) +int32, weights (6000, 4) float64**, `stencil_sizes_max` **3**, H shape (1500, 1500) not sliced, +subtracted light flux 4945.524141998385. + +A100 assertions, both arms (`output/output.343346.out`): "cell-driven NNLS reproduces the library +reconstruction to 1e-8" **PASSED**, "inversion-matrix log_evidence matches FitImaging.log_evidence" +**PASSED**, "Eager regression assertion PASSED: log_evidence matches 29140.295882". Every one of the +six `log_evidence_terms` is bit-identical across the two arms, and `nnls.iterations` is 22 with +`reconstruction_max_abs_diff_vs_library` **7.592702022662934e-10** in both — the same digits. + +## Lever 1 — headline + +### Host 1: `euclid-ral-gpu-1`, numba CPU + +`use_jax: false`, `backend: "numba_cpu"`, `InversionImagingSparseNumba`, `n_threads` 1, +`NUMBA_NUM_THREADS` `"1"`, `OMP`/`OPENBLAS`/`MKL`/`VECLIB`/`NUMEXPR` all `"1"`, +`cpu_over_wall` 1.0003 (control) / 1.0004 (feature). Clean (uninstrumented) calls, n-repeats 16. + +| arm | PyAutoArray | mean ms | median ms | min | max | clean spread | ABBA | `inversion.regularization_matrix` ms | H as % of call | +|---|---|---:|---:|---:|---:|---:|---:|---:|---:| +| control | `5e2bc0f4` | **413.301** | 411.135 | 398.487 | 466.934 | 16.56 % | 1.0147 | **110.599** | 26.76 % | +| feature | `bae9296e` | **299.709** | 297.262 | 285.081 | 350.800 | 21.93 % | 1.0163 | **5.924** | 1.98 % | + +| | value | +|---|---:| +| speedup on means | **1.379×** | +| speedup on medians | **1.383×** | +| whole-call saving | **113.592 ms** (means), 113.873 ms (medians) | +| H saving | **104.675 ms** (110.599 → 5.924, **18.7×** on that site) | + +Anchors on phase 2's Leg D (job 343311, the same cell on the same node type, pre-lever): +mean 407.864 → control 413.301 (**+1.33 %**), median 404.597 → 411.135 (**+1.62 %**), +H 111.501 → 110.599 (**−0.81 %**). The control reproduces phase 2. + +Both arms ran 16 clean and 16 instrumented calls in 8 counterbalanced ABBA blocks; the decomposition +closes exactly — the 48 instrumented sites (37 of them reached) plus the explicit +`unattributed (call − sum of exclusive times)` row, 49 rows in all, sum to the clean call to the last +printed digit: **413.301** and **299.709**. `unattributed` is 1.273 ms (0.31 %) and 0.986 ms +(0.33 %) of the two calls, on a 5 % gate. + +### Host 2: `euclid-ral-gpu-1`, A100 80GB PCIe, JAX/XLA + +`backend: "gpu"`, `device: "cuda:0"`, fp64, `--split-setup --vmap-batch 16`, dense inversion path, +`jax_compilation_cache_dir` `/home/jnightin/.cache/pyauto_jax` with `cache_fresh: true` and +`autotune_cache_entries_at_start` 0 in both arms. + +| arm | PyAutoArray | `total_step_by_step` s | `regularization_matrix_prefix_s` | `interpolator_prefix_s` | H step (prefix difference) s | H @ vmap/16 s | `regularization_matrix_jit.compile_s` | +|---|---|---:|---:|---:|---:|---:|---:| +| control | `5e2bc0f4` | **0.067071** | 0.0073318 | 0.0071154 | 0.00021639 | 5.877e-05 | 3.043 | +| feature | `bae9296e` | **0.067047** | 0.0073298 | 0.0070933 | 0.00023652 | 5.976e-05 | 3.261 | +| difference | — | **−0.036 %** | **−0.028 %** | −0.312 % | +20 µs (see Scope) | +1.7 % | +0.218 s | + +**Identity, as expected.** The whole call moves 0.036 % and the H prefix 0.028 %. The H *step* moves ++20 µs only because the interpolator prefix it is subtracted from moved −0.312 %; both prefixes are +~7.1–7.3 ms, so the step is a small difference of two large jitted numbers. + +## Lever 1 — decomposition + +Exclusive (self) time per instrumented site, rescaled by `decomposition_rescale_factor` +(0.98604 control / 0.98476 feature) so the rows sum to the clean call. `n_sites_instrumented` 48 and +`n_sites_reached` 37 in both arms. Top rows by control time: + +| site | group | control ms | feature ms | Δ ms | Δ % | +|---|---|---:|---:|---:|---:| +| `inversion.regularization_matrix` | F + λH | **110.599** | **5.924** | **−104.675** | **−94.6** | +| `sparse_numba.curvature_matrix` | D and F assembly | 89.615 | 87.153 | −2.462 | −2.7 (scatter) | +| `solver.fnnls_cholesky` | Positivity solve | 65.050 | 62.602 | −2.448 | −3.8 (scatter) | +| `inversion.log_det_curvature_reg_matrix_term` | Log dets + evidence | 40.595 | 39.983 | −0.613 | −1.5 | +| `inversion.log_det_regularization_matrix_term` | Log dets + evidence | 37.809 | 37.200 | −0.609 | −1.6 | +| `delaunay.triangulation` | Mesh | 18.816 | 18.662 | −0.155 | −0.8 | +| `sparse_numba.psf_weighted_data` | D and F assembly | 8.399 | 8.211 | −0.188 | −2.2 | +| `solver.reconstruction_positive_only_from` | Positivity solve | 7.748 | 7.471 | −0.277 | −3.6 | +| `inversion.reconstruction` | Positivity solve | 7.322 | 7.043 | −0.279 | −3.8 | +| `to_inversion.lp_linear_func_list_galaxy_dict` | Mapper | 7.265 | 6.049 | −1.216 | −16.7 | +| `inversion.curvature_reg_matrix` | F + λH | 4.261 | 4.108 | −0.152 | −3.6 | +| `unattributed (call − sum of exclusive times)` | — | 1.273 | 0.986 | −0.287 | −22.5 | + +**Only one row moved.** `sparse_numba.curvature_matrix` (−2.462 ms) and `solver.fnnls_cholesky` +(−2.448 ms) are the only other sites that moved more than 2 ms, and both are **−2.7 % and −3.8 % of +their own rows against clean spreads of 16.6 % and 21.9 % — that is scatter, not an effect.** Lever 1 +cannot touch either site: it changed two functions in +`autoarray/inversion/regularization/regularization_util.py` and nothing else. +`to_inversion.lp_linear_func_list_galaxy_dict` is the largest relative mover after H (−16.7 %) but +only −1.216 ms of a 7 ms row, and is likewise scatter. The whole-call saving (113.592 ms) exceeds +the H saving (104.675 ms) by **8.917 ms**, which is — by the additive construction of the +decomposition — precisely the sum of every non-H row's delta. **That 8.917 ms is scatter, not a +secondary effect**, so the honest reading of the headline is "H fell 104.675 ms and the call fell +113.592 ms on a host whose rows scatter 17–22 %", not "104.675 ms plus 8.9 ms of side benefits". + +Groups, before and after (percentages of each arm's own clean call): + +| group | control ms | control % | feature ms | feature % | +|---|---:|---:|---:|---:| +| **F + λH** | **114.931** | **27.81** | **10.094** | **3.37** | +| D and F assembly | 98.183 | 23.76 | 95.528 | 31.87 | +| Log determinants + evidence | 81.354 | 19.68 | 80.024 | 26.70 | +| Positivity solve | 80.126 | 19.39 | 77.122 | 25.73 | +| Mesh (ray trace, placement, triangulation) | 20.145 | 4.87 | 19.992 | 6.67 | +| Mapper + mapping matrix | 10.797 | 2.61 | 9.516 | 3.18 | +| Mapper weights (Delaunay) | 3.781 | 0.91 | 3.745 | 1.25 | +| Image + blurring | 2.712 | 0.66 | 2.702 | 0.90 | +| unattributed | 1.273 | 0.31 | 0.986 | 0.33 | + +The `F + λH` group was the largest in the call and is now the second smallest of the four big ones. +**After lever 1 the call's shape is: assembly 32 %, log-dets 27 %, solve 26 %, mesh 7 %.** + +## Lever 1 — the A100 row and the compaction finding + +Lever 1 was expected to be invisible on the GPU and it is. The mechanism, verified against the code +rather than assumed: + +1. `delaunay.py`'s `_setup_prefix_fn` (`scripts/imaging/likelihood_breakdown/delaunay.py:927`) has an + `upto == 11` branch (line 992) which calls + `pixelization_obj.regularization.regularization_matrix_from(linear_obj=m, xp=jnp)` **inside + `jax.jit`** — `jit_profile(_setup_prefix_fn(11), "regularization_matrix_jit", …)` at line 1338. +2. With `xp=jnp`, `AdaptSplit` dispatches to the **JAX** branches of `reg_split_from` and + `pixel_splitted_regularization_matrix_from` — `#536`'s compacted scatter. The numpy branch lever 1 + rewrote (`reg_split_np_from` / `pixel_splitted_regularization_matrix_np_from`) is **never reached** + on this cell. + +**The finding: the two compaction constants are inert at this configuration.** +`InterpolatorDelaunay` (`delaunay.py:747`, `_INTERPOLATOR_CLS = al.InterpolatorDelaunay`) produces a +stencil table of width **K = 4** — three barycentric columns plus one reserved pad column for the +centre-pixel insertion — which the witness JSON records as `stencil_mappings_shape` **(6000, 4)** with +`stencil_sizes_max` **3**. In `pixel_splitted_regularization_matrix_from` +(`regularization_util.py:462`): + +- `kc = min(K, int(compact_width))` = `min(4, 12)` = **4** (line 568), so the compact head scatter + `reg_mat.at[rows, cols].add(outer_scaled)` already covers **every** column of the table; +- `if K > kc:` (line 583) is a **static Python branch on a shape**, so with K = 4 it is not taken and + XLA never traces it: **no `jax.lax.top_k`, no `(W, K, K)` wide-row supplement, no `head_block` + mask, `overflow = None`, and no `jnp.where(overflow, jnp.nan, reg_mat)` poison guard is emitted at + all.** + +Therefore **`SPLIT_REG_COMPACT_WIDTH = 12` and `SPLIT_REG_WIDE_ROW_BUDGET = 256` do nothing at HST +Delaunay N=1500 with `InterpolatorDelaunay`.** They bite only when K > 12 — the natural-neighbour +Sibson path, where the constants' own docstring records K = 33 (`SIBSON_MAX_NEIGHBORS` 32 + 1 spare +column) and an occupied width of min 1 / median 5 / p99 9 / max 11. **Any retune of either constant +must be measured on a `DelaunayNN` cell; a measurement on this Delaunay row cannot see them.** +It follows that the A100 identity result here is *not* evidence that the compaction is correctly +tuned — it is evidence that the compaction is not exercised. + +For context (not a control): the pre-existing `delaunay_hpc_a100_fp64.json` row reads +`total_step_by_step` 0.067474 s, `regularization_matrix_prefix_s` 0.0073808, H step 0.00023435 s and +H @ vmap/16 **0.00034227 s**. It ran on **`euclid-ral-gpu-2`** with a different JAX cache directory +and a different PyAutoArray revision, so its 5.8× larger vmap H row is **not attributable to lever 1** +and is not part of this A/B. + +## Lever 1 — verdict + +1. **Lever 1 ships and is worth 1.379× on the production numba CPU route.** 413.301 → 299.709 ms + mean (1.383× on medians), a saving of **113.592 ms** on a 404–413 ms call, single-threaded, HST + Delaunay N=1500, sparse numba operator, route b, memo ON. Take it as a **lower bound**: the + feature arm was the arm with the busier host. +2. **What shipped** (PyAutoArray `bae9296e`, merge base `5e2bc0f4`, branch + `feature/fixed-light-numba-levers`): the two pure-Python loops behind `reg_split_np_from` and + `pixel_splitted_regularization_matrix_np_from` in + `autoarray/inversion/regularization/regularization_util.py` are now `@numba_util.jit()` kernels + (`_reg_split_kernel`, `_pixel_splitted_regularization_matrix_kernel`) behind thin numpy wrappers, + reproducing the reference accumulation order bit for bit. The Python bodies are **retained** as + `_reg_split_reference` and `_pixel_splitted_regularization_matrix_reference` and pinned against the + kernels with `np.array_equal` in + `test_autoarray/inversion/regularizations/test_regularization_util_numba.py` (7 test functions, 8 + collected cases with the `NARROW_SIZES`/`WIDE_SIZES` parametrize). The **JAX branch is untouched** + — PyAutoArray#536 owns it. PyAutoArray suites: regularizations 118, interpolator 58, inversion 212 + passed. +3. **Three deliberate behaviour changes, all recorded in the commit message and all covered by a + test:** + - `reg_split_np_from` **copies `mappings` and `sizes` on entry** (`np.array(...)`) instead of + mutating the interpolators' `cached_property` stencil tables in place. Witness **W2** is the + measurement of that on the production system: all three tables byte-identical after the + inversion. Test: `test__reg_split__does_not_mutate_its_inputs`. + - a **`size == 0` row inserts its centre pixel at column 0**, not at a stale `j + 1` — the old + code leaked the loop variable from the previous row. Not exercised here + (`n_zero_size_stencil_rows` is **0** on this system, from both the witness and W1), so this is a + latent-correctness change, not a source of the speedup. Test: + `test__reg_split__empty_row__inserts_at_column_zero`. + - a **full stencil with no self pixel raises `exc.InversionException`** instead of writing past the + table width; numba does no bounds checking, so the kernel returns the first overflowing row index + and the wrapper raises. Test: `test__reg_split__full_row_without_self_pixel__raises`. +4. **The equivalence is bit-level, not tolerance-level, and it was witnessed on the production + system.** W1: `np.array_equal` **true**, `max_abs_diff` **0.0** on the (1500, 1500) matrix. W3: + `figure_of_merit` **19705.71758591176** on both paths, relative difference **0.0** against a 1e-09 + gate, with the monkeypatch confirmed fired (`{reg_split: 1, pixel_splitted: 1}`). Every `gates` + field in the two A/B arms is identical. No number changed. +5. **On the A100 it is identity, and the negative finding is the useful one.** 0.036 % on the whole + call, 0.028 % on the H prefix, `log_evidence_terms` bit-identical. The `#536` compaction constants + are **unmeasurable** at K = 4 (see above), so nothing about them is validated or invalidated by + this job. +6. **Where the H site now sits.** `inversion.regularization_matrix` was the **single largest site in + the S3 call** in phase 2 (111.5 ms, 27 %); it is now **5.924 ms, 2.0 %**, and the witness measures + the same matrix at 6.5 ms against the reference's 106.8 ms. The local laptop sanity check before + the cluster run read 106.3 ms → 1.23 ms at P=1500, K=4 in isolation; the in-call site is larger + than that because it includes the `AdaptSplit` weight construction and the split-point walk, not + only the two kernels. **The lever the phase-2 note named as the biggest untouched one is closed.** + +## Next + +Lever 1 removed the largest site and did not touch the others. The residue of the 299.709 ms feature +call, from its own decomposition: + +| site | feature ms | % of the 299.709 ms call | lever | +|---|---:|---:|---| +| `sparse_numba.curvature_matrix` | 87.153 | 29.08 | — (phase 2 concluded; not a phase-3 lever) | +| `solver.fnnls_cholesky` | 62.602 | 20.89 | — (phase 2 closed the solver) | +| `inversion.log_det_curvature_reg_matrix_term` | 39.983 | 13.34 | **lever 3** | +| `inversion.log_det_regularization_matrix_term` | 37.200 | 12.41 | **lever 2** | +| `delaunay.triangulation` | 18.662 | 6.23 | — | +| `inversion.regularization_matrix` | 5.924 | 1.98 | lever 1, done | + +1. **Lever 2 — log det H from sparsity.** `inversion.log_det_regularization_matrix_term`, 37.468 ms in + phase 2's Leg D and 37.200 ms in the lever 1 feature arm (memo-invariant, as the two agree to + 0.7 %). H is a split-regularization matrix: sparse and, for Delaunay, structurally banded once the + pixels are ordered. Options to measure: `scipy.sparse.linalg.splu` on the CSR form; a **banded + Cholesky after an RCM (reverse Cuthill-McKee) permutation**, whose log det is permutation-invariant; + or caching the factor across evaluations keyed on the mesh **and** the adapt weights, since + `AdaptSplit`'s weights move with the model while the mesh connectivity does not — the cache key is + the whole question, and a wrong key is a silent wrong evidence. +2. **Lever 3 — one shared Cholesky of `F + λH`.** `inversion.log_det_curvature_reg_matrix_term`, + 40.172 ms in Leg D and 39.983 ms here. The solver already factorises `F + λH` + (`solver.fnnls_cholesky`, 62.602 ms) and the log-det term then factorises it again. Lever 3 folds in + the `curvature_reg_matrix` rebuild draft, **on the numpy/numba path only** — the JAX side is the GPU + session's HLO census to answer, not this lever's. Together levers 2 and 3 address **77.183 ms, + 25.8 %** of the feature call. +3. **Both levers need the same A/B rig this one used**, and it worked: two private PyAutoArray + checkouts prepended to `PYTHONPATH` in separate subshells, both arms in one SLURM job on one node, + a bit-identity witness inside the feature arm, and an A100 row to prove the JAX branch did not move. + Re-use `hpc/batch_cpu/submit_breakdown_imaging_fixed_light_numba_levers_delaunay_ral_hst_fp64` and + `hpc/batch_gpu/submit_breakdown_imaging_fixed_light_numba_levers_delaunay_a100_hst_fp64`. +4. **If either compaction constant is ever retuned**, the cell must be `DelaunayNN`. This Delaunay row + cannot observe them (K = 4 ⇒ `kc` = 4 ⇒ the wide-row branch is never traced), so a Delaunay + measurement is not evidence about them in either direction. +5. **Still unfiled, carried from phase 2**: the PyAutoArray bug that + `abstract_ndarray.__getitem__` imports `jax.numpy`, so a numba-only process cannot stay JAX-free + after the first `FitImaging` (`jax_in_sys_modules: true` in this phase's witness JSON too). +6. **Out of scope throughout, as in phase 2**: route a, route c, rectangular meshes, Euclid, the + source-pixel sweep, and the sparse-operator/profile-subtracted-image bug. + +## Artifacts + +Result artifacts added by this commit (**9 files**): + +``` +results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_lever1_control_b_warm_t1.{json,png} # CPU control, 5e2bc0f4 +results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_lever1_b_warm_t1.{json,png} # CPU feature, bae9296e +results/breakdown/imaging/fixed_light_numba_levers_witness_hpc_ral_cpu_fp64_lever1.json # W1/W2/W3, feature arm +results/breakdown/imaging/delaunay_hpc_a100_fp64_lever1_control.{json,png} # A100 control, 5e2bc0f4 +results/breakdown/imaging/delaunay_hpc_a100_fp64_lever1.{json,png} # A100 feature, bae9296e +``` + +Read alongside (already versioned, **not** part of this A/B): + +``` +results/breakdown/imaging/delaunay_hpc_a100_fp64.json # prior A100 row, context only (ran on gpu-2) +results/breakdown/imaging/fixed_light_numba_delaunay_hpc_ral_cpu_fp64_fixed_light_numba_sparse_b_warm_t1.json # phase 2 Leg D, the anchor +``` + +Two laptop witness JSONs written while developing the witness script +(`fixed_light_numba_levers_witness_local_laptop_lever1{,_postlint}.json`) were **deliberately not +versioned**: they are laptop test artifacts, not cluster rows, and the laptop's clean spreads make it +useless as a timing host for this cell (phase 2, Scope). + +Cells and submit scripts: + +``` +scripts/imaging/likelihood_breakdown/fixed_light_numba.py # the CPU cell (phase 2's Leg D) +scripts/imaging/likelihood_breakdown/fixed_light_numba_levers_witness.py # the W1/W2/W3 witness +scripts/imaging/likelihood_breakdown/delaunay.py # the A100 cell +scripts/misc/likelihood_breakdown/call_accounting.py # the decomposition instrument +hpc/batch_cpu/submit_breakdown_imaging_fixed_light_numba_levers_delaunay_ral_hst_fp64 # job 343345, both CPU arms + witness +hpc/batch_gpu/submit_breakdown_imaging_fixed_light_numba_levers_delaunay_a100_hst_fp64 # job 343346, both A100 arms +``` + +Library change: **PyAutoArray `bae9296ed528da6812613edc2ebc6ea367361ebb`** on +`feature/fixed-light-numba-levers`, merge base +`5e2bc0f42940adfe04ff30fa42a7ce13a86ecbe0` — `autoarray/inversion/regularization/regularization_util.py` +(+181/−17) and `test_autoarray/inversion/regularizations/test_regularization_util_numba.py` (+295). + +Job logs (SLURM, **not versioned** — `output/` is gitignored): `output/output.343345.out`, +`output/output.343346.out` and `error/error.34334{5,6}.err`, on +`/mnt/ral/jnightin/autolens_profiling_wt/fixed-light-numba-levers` and mirrored into this worktree's +untracked `output/`. + +JSON keys specific to these arms: `rows["b_sparse_numba"]` with `call_ms` / `call_ms_median` / +`call_ms_sequence` / `clean_relative_spread` / `abba` / `instrumentation_overhead_ratio`, +`steps[*]` (`excl_s` already rescaled, plus `excl_s_unscaled`, `incl_s`, `n_calls`, `group`) including +the explicit `unattributed (call − sum of exclusive times)` row, `decomposition_rescale_factor`, +`solver_stats["solver.fnnls_cholesky"]`, `gates`, `contention`; and on the A100 side `steps`, +`steps_vmap_per_call`, `setup_split`, `regularization_matrix_prefix_s`, `interpolator_prefix_s`, +`jit_phases[*].compile_s`, `log_evidence_terms`, `nnls`, `total_step_by_step`. + + diff --git a/scripts/imaging/likelihood_breakdown/fixed_light_numba_levers_witness.py b/scripts/imaging/likelihood_breakdown/fixed_light_numba_levers_witness.py new file mode 100644 index 000000000..2925b7ef4 --- /dev/null +++ b/scripts/imaging/likelihood_breakdown/fixed_light_numba_levers_witness.py @@ -0,0 +1,692 @@ +""" +Numba CPU Witness: split-regularization lever 1 is bit-identical +================================================================ + +Witness for **lever 1** of the numba CPU levers task (autolens_profiling#267). + +Lever 1 replaced the two pure-Python loops in PyAutoArray's split-regularization +assembly — ``regularization_util.reg_split_np_from`` (the split-point stencil +completion) and ``regularization_util.pixel_splitted_regularization_matrix_np_from`` +(the dense ``(P, P)`` scatter) — with numba kernels, and **retained the original +loop bodies verbatim** as ``_reg_split_reference`` and +``_pixel_splitted_regularization_matrix_reference``. The library's unit tests +assert the kernels against those references on synthetic tables. This cell +asserts the same thing on the **production system the CPU timing legs measure**: +the HST Delaunay N=1500 source-only (S3) ``AdaptSplit`` system that +``fixed_light_numba.py`` route ``b`` builds. + +A speedup row without this witness beside it is a number for a *possibly +different* matrix. Three things are checked, in the order a reader should want +them: + +``W1`` **the matrix itself**. The interpolator's +``_mappings_sizes_weights_split`` tables are run through +``_reg_split_reference`` (on copies — it mutates mappings and sizes in place) +and then through ``_pixel_splitted_regularization_matrix_reference``, and the +result is asserted ``np.array_equal`` with the library's own +``inversion.regularization_matrix`` (the kernel path). ``array_equal``, not +``allclose``: the claim is bit-identity, and the max absolute difference is +printed and recorded either way. + + One caveat is recorded rather than assumed away. ``_reg_split_reference`` + carries a ``size == 0`` index leak that ``_reg_split_kernel`` deliberately + fixes (``j`` keeps its value from the previous row when a row's stencil is + empty, so the flag-zero branch writes at a stale ``j + 1``). The two are + therefore bit-identical only on tables with no empty rows. The count of + zero-size rows is asserted to be 0 and recorded as + ``n_zero_size_stencil_rows``; a non-zero count would make W1's verdict a + statement about the leak, not about the lever. + +``W2`` **the caller's tables are not consumed**. ``reg_split_np_from`` copies +mappings and sizes on entry (``np.array(...)``) and rebinds weights +(``-1.0 * w``), so the interpolator's ``cached_property`` stencil tables must be +byte-for-byte unchanged after a full library inversion. They are snapshotted +before the library builds ``H`` and compared after. An in-place kernel that ate +its input would still produce the right ``H`` on the first evaluation and the +wrong one on every evaluation after it — which a single-call witness on ``H`` +alone cannot see. + +``W3`` **the likelihood**. The fit's ``figure_of_merit`` (the log evidence) is +computed twice on **fresh fit objects**: once with the library as it ships, once +with both module-level entry points monkeypatched to the ``_reference`` bodies +(each given copies). Bit-identity of ``H`` should make the relative difference +exactly ``0.0``; the gate passes at ``<= 1e-9``. The monkeypatch is at module +scope on ``regularization_util``, which is where ``reg_split_from`` and +``pixel_splitted_regularization_matrix_from`` look their numpy branches up, so +the library's own dispatch is what routes into the references. + +What this cell is NOT +-------------------- + +It takes **no timings** and asserts no pin. The A/B milliseconds are +``hpc/batch_cpu/submit_breakdown_imaging_fixed_light_numba_levers_delaunay_ral_hst_fp64``'s +two arms of ``fixed_light_numba.py``; this cell is the correctness leg that runs +beside the feature arm and says the two arms computed the same matrix. + +It imports **no JAX** of its own and sets no ``JAX_*``/``XLA_*`` variable. Lever +1 did not touch the JAX branch of either function (``reg_split_from`` and +``pixel_splitted_regularization_matrix_from`` both dispatch on ``if xp == np``, +and only that branch changed), so there is nothing for a JAX witness to say +here. Note that ``jax`` still lands in ``sys.modules`` via the first +``FitImaging`` regardless. + +Construction +------------ + +The dataset, mask, over-sampling, Hilbert mesh, MGE lens light, mass/shear +priors, instance stream and ``AdaptSplit(0.1, 10.0, signal_scale=0.1)`` +regularization are the same block ``fixed_light_numba.py`` runs, and the S3 +system is built through the same +``likelihood_breakdown.fixed_light_system.fixed_light_system_from`` with +``sparse_operator="rebake_cpu"``, i.e. route ``b``'s +``InversionImagingSparseNumba`` on the subtracted dataset. The construction is +**replicated rather than imported**: ``fixed_light_numba.py`` is a top-to-bottom +script with no ``__main__`` guard, so importing it would run all four of its +legs. Every shared helper it uses is imported from the same module, so the two +cells cannot drift in the mesh, the model or the regularization — only in this +prologue, which is why the instance seed, the mask radius, the over-sample bins +and the mesh vertex count are literals here exactly as they are there. + +The dispatch is a hard ``isinstance`` assert, and ``fit._xp is np`` is asserted +too: a witness that silently ran the dense formalism, or the JAX branch, would +be asserting bit-identity of something the timing legs do not run. + +Output +------ +``results/breakdown/imaging/fixed_light_numba_levers_witness_.json`` +""" + +import sys as _sys +from pathlib import Path as _Path + + +def _profiling_root() -> _Path: + for _p in _Path(__file__).resolve().parents: + if (_p / "ruff.toml").exists(): + return _p + raise RuntimeError("autolens_profiling root (ruff.toml) not found") + + +_misc_dir = str(_profiling_root() / "scripts" / "misc") +if _misc_dir not in _sys.path: + _sys.path.insert(0, _misc_dir) + +_sys.path.insert(0, str(_profiling_root())) + +# --------------------------------------------------------------------------- +# HEADER ORDER IS LOAD-BEARING — the same constraint fixed_light_numba.py has +# --------------------------------------------------------------------------- +# OpenBLAS / MKL / OpenMP read their thread-count variables once, when the +# shared library loads, and numba reads NUMBA_NUM_THREADS once, when it +# initialises its threading layer. Both therefore have to be set before +# `import numpy` and before anything imports numba. `_production_config` and +# `_profile_cli` are stdlib-only at import time, which is what makes this +# possible. NUMBA_NUM_THREADS is set cell-locally and deliberately NOT added to +# `_production_config.THREAD_ENV_VARS`, for the reason that cell gives. +import argparse as _argparse # noqa: E402 +import os as _os # noqa: E402 + +from _production_config import pin_thread_env as _pin_thread_env # noqa: E402 +from _profile_cli import parse_profile_cli as _parse_profile_cli # noqa: E402 + +_cli = _parse_profile_cli() + +_cell_parser = _argparse.ArgumentParser(add_help=False, allow_abbrev=False) +_cell_parser.add_argument("--mesh", choices=("delaunay",), default="delaunay") +_cell_parser.add_argument("--dataset", choices=("hst", "euclid"), default="hst") +_cell_parser.add_argument("--threads", type=int, default=1) +_cell_args, _ = _cell_parser.parse_known_args() + +MESH = _cell_args.mesh +DATASET = _cell_args.dataset +N_THREADS = max(1, int(_cell_args.threads)) + +#: W3's gate. Bit-identity of H should give exactly 0.0; the tolerance exists so +#: a last-bit difference in the log-evidence sum is reported as a pass with its +#: value printed rather than as a crash with no number. +W3_RTOL = 1e-9 + +thread_env = _pin_thread_env(N_THREADS) + +_numba_threads_before = _os.environ.get("NUMBA_NUM_THREADS") +_os.environ["NUMBA_NUM_THREADS"] = str(N_THREADS) +numba_thread_env = { + "NUMBA_NUM_THREADS": _os.environ["NUMBA_NUM_THREADS"], + "preexisting": _numba_threads_before, +} + +# The cross-evaluation NNLS warm-start memo is OFF here. This cell takes no +# timing, and every figure_of_merit it compares must be a cold solve of its own +# system: a memo shared between the library fit and the monkeypatched fit would +# let the second one start from the first's passive set, which is exactly the +# channel W3 is trying to look through. +_os.environ["AUTOARRAY_NNLS_WARM_START"] = "0" + +import json # noqa: E402 +import os # noqa: E402 +import socket # noqa: E402 +import sys # noqa: E402 +import time # noqa: E402 +from pathlib import Path # noqa: E402 + +import autofit as af # noqa: E402 +import autolens as al # noqa: E402 +import numpy as np # noqa: E402 + +if os.environ.get("AUTOLENS_PROFILING_SMOKE") == "1": + print(f"[smoke] {__file__}: imports + module setup OK; exiting.") + sys.exit(0) + +import autoarray # noqa: E402 +from autoarray.inversion.inversion.imaging.mapping import ( # noqa: E402 + InversionImagingMapping, +) +from autoarray.inversion.inversion.imaging_numba.sparse import ( # noqa: E402 + InversionImagingSparseNumba, +) +from autoarray.inversion.mappers.abstract import Mapper # noqa: E402 +from autoarray.inversion.regularization import regularization_util # noqa: E402 +from likelihood_breakdown import fixed_light_system # noqa: E402 +from simulators.imaging import INSTRUMENTS # noqa: E402 + +from _adapt_image_util import adapt_image_for_dataset # noqa: E402 +from _profile_cli import ( # noqa: E402 + auto_simulate_if_missing, + delaunay_regularization, + machine_info_dict, +) + +_t_start = time.time() +_workspace_root = _profiling_root() + +print("=" * 70) +print("FIXED-LIGHT NUMBA LEVERS — LEVER 1 BIT-IDENTITY WITNESS (#267)") +print("=" * 70) +print(f" autoarray.__file__: {autoarray.__file__}") +print(f" autolens.__version__: {al.__version__}") +print(f" hostname: {socket.gethostname()}") +print(f" thread env: {thread_env}") +print(f" numba thread env: {numba_thread_env}") + + +# =================================================================== +# PART A — the S3 system route `b` of fixed_light_numba.py builds +# =================================================================== + +instrument = DATASET + +print(f"\n--- Dataset loading & masking [{instrument}, mesh={MESH}] ---") + +pixel_scale = INSTRUMENTS[instrument]["pixel_scale"] +dataset_path = Path("dataset") / "imaging" / instrument + +auto_simulate_if_missing( + dataset_path, + dataset_type="imaging", + instrument=instrument, + workspace_root=_workspace_root, +) + +dataset = al.Imaging.from_fits( + data_path=dataset_path / "data.fits", + psf_path=dataset_path / "psf.fits", + noise_map_path=dataset_path / "noise_map.fits", + pixel_scales=pixel_scale, +) + +mask_radius = 3.5 + +mask = al.Mask2D.circular( + shape_native=dataset.shape_native, + pixel_scales=dataset.pixel_scales, + radius=mask_radius, +) + +dataset = dataset.apply_mask(mask=mask) +dataset = dataset.apply_over_sampling( + over_sample_size_lp=4, + over_sample_size_pixelization=1, +) + +over_sample_size = al.util.over_sample.over_sample_size_via_radial_bins_from( + grid=dataset.grid, + sub_size_list=[4, 2, 2], + radial_list=[0.3, 0.6], + centre_list=[(0.0, 0.0)], +) + +dataset = dataset.apply_over_sampling( + over_sample_size_lp=over_sample_size, + over_sample_size_pixelization=1, +) + +n_mesh_vertices = 1500 if _cli.source_pixels is None else int(_cli.source_pixels) + +print("\n--- Adapt image (lensed source) ---") +adapt_image = adapt_image_for_dataset(dataset_path=dataset_path, dataset=dataset) + +print("\n--- Image mesh construction (Hilbert) ---") +image_mesh = al.image_mesh.Hilbert(pixels=n_mesh_vertices, weight_power=1.0, weight_floor=0.0) +image_plane_mesh_grid = image_mesh.image_plane_mesh_grid_from( + mask=dataset.mask, adapt_data=adapt_image +) +print(f" Mesh vertices placed: {image_plane_mesh_grid.shape[0]}") + +print("\n--- Model construction ---") + +lens_bulge = al.model_util.mge_model_from( + mask_radius=mask_radius, + total_gaussians=60, + centre_prior_is_uniform=True, +) + +mass = af.Model(al.mp.Isothermal) +mass.centre.centre_0 = af.GaussianPrior(mean=0.0, sigma=0.005) +mass.centre.centre_1 = af.GaussianPrior(mean=0.0, sigma=0.005) +mass.einstein_radius = af.GaussianPrior(mean=1.6, sigma=0.05) +_lens_mass_ell = al.convert.ell_comps_from(axis_ratio=0.9, angle=45.0) +mass.ell_comps.ell_comps_0 = af.GaussianPrior(mean=_lens_mass_ell[0], sigma=0.01) +mass.ell_comps.ell_comps_1 = af.GaussianPrior(mean=_lens_mass_ell[1], sigma=0.01) + +shear = af.Model(al.mp.ExternalShear) +shear.gamma_1 = af.GaussianPrior(mean=0.05, sigma=0.005) +shear.gamma_2 = af.GaussianPrior(mean=0.05, sigma=0.005) + +lens = af.Model(al.Galaxy, redshift=0.5, bulge=lens_bulge, mass=mass, shear=shear) + +mesh_obj = al.mesh.Delaunay(pixels=n_mesh_vertices, zeroed_pixels=0) +reg_scheme, regularization, reg_provenance = delaunay_regularization(_cli) + +pixelization = al.Pixelization(mesh=mesh_obj, regularization=regularization) +source = af.Model(al.Galaxy, redshift=1.0, pixelization=pixelization) +model = af.Collection(galaxies=af.Collection(lens=lens, source=source)) + +print(f" Total free parameters: {model.total_free_parameters}") +print(f" Regularization: {reg_scheme} ({reg_provenance})") + +# Instance 0 of `fixed_light_numba.py`'s `--instances iid` stream: the same seed +# and the same central-20 % draw, so this witness stands on the very first +# instance every timed row of the A/B legs starts from. +_IID_SEED = 263 +_rng = np.random.default_rng(_IID_SEED) +instance = model.instance_from_unit_vector( + unit_vector=list(_rng.uniform(0.4, 0.6, size=model.prior_count)) +) + + +def adapt_images_of(one_instance): + """``AdaptImages`` for one instance — the dicts are keyed on its own galaxy.""" + return al.AdaptImages( + galaxy_image_dict={one_instance.galaxies.source: adapt_image}, + galaxy_name_image_dict={"('galaxies', 'source')": adapt_image}, + galaxy_image_plane_mesh_grid_dict={one_instance.galaxies.source: image_plane_mesh_grid}, + galaxy_name_image_plane_mesh_grid_dict={"('galaxies', 'source')": image_plane_mesh_grid}, + ) + + +adapt_images = adapt_images_of(instance) + +_settings = al.Settings(use_border_relocator=True) + +print("\n--- S0: full FitImaging with linear MGE lens light (eager, dense) ---") +fit_s0 = al.FitImaging( + dataset=dataset, + tracer=al.Tracer(galaxies=list(instance.galaxies)), + adapt_images=adapt_images, + settings=_settings, + xp=np, +) +assert isinstance(fit_s0.inversion, InversionImagingMapping), ( + f"S0 dispatched {type(fit_s0.inversion).__name__}, not InversionImagingMapping" +) +print(f" inversion class: {type(fit_s0.inversion).__name__}") + +print("\n--- S3: lens light converted to regular profiles + subtracted (sparse numba) ---") +system_s3 = fixed_light_system.fixed_light_system_from( + fit_s0, + dataset, + adapt_images=adapt_images, + settings=_settings, + name="S3_sparse_numba", + scaling="numpy", + sparse_operator="rebake_cpu", +) +dataset_s3 = system_s3.dataset +source_only_tracer = system_s3.source_only_tracer +print( + f" S3: n={system_s3.n_params} (mapper {system_s3.n_mapper} + funcs {system_s3.n_funcs}), " + f"edge-zeroed {int(system_s3.edge_zero_mask.sum())}" +) +print(f" S3 operator: {type(dataset_s3.sparse_operator).__name__}") +print(f" subtracted light flux: {system_s3.subtracted_light_flux}") + + +def _s3_instance(one_instance): + """``one_instance`` with the lens light stripped, for the S3 fit.""" + import copy + + stripped = copy.deepcopy(one_instance) + galaxies = list( + fixed_light_system._light_stripped_tracer( + al.Tracer(galaxies=list(one_instance.galaxies)) + ).galaxies + ) + stripped.galaxies.lens = galaxies[0] + stripped.galaxies.source = galaxies[1] + return stripped + + +adapt_images_s3 = adapt_images_of(_s3_instance(instance)) + + +def _eager_s3_fit(): + """A fresh route-``b`` fit: the subtracted dataset, the source-only tracer, numpy.""" + return al.FitImaging( + dataset=dataset_s3, + tracer=source_only_tracer, + adapt_images=adapt_images_s3, + settings=_settings, + xp=np, + ) + + +# =================================================================== +# PART B — the three witness checks +# =================================================================== + +results: dict[str, dict] = {} + + +def _record(name, status, detail): + results[name] = {"status": status, **detail} + print(f" [{status:>4}] {name}: {detail.get('summary', '')}") + return results[name] + + +print("\n" + "=" * 70) +print("WITNESS") +print("=" * 70) + +fit = _eager_s3_fit() +inversion = fit.inversion + +assert isinstance(inversion, InversionImagingSparseNumba), ( + f"the S3 witness fit dispatched {type(inversion).__name__}, not " + f"InversionImagingSparseNumba — route b's formalism is not what is being witnessed" +) +assert fit._xp is np, f"fit._xp is {fit._xp!r}, not numpy — this witness is the numpy path" + +mapper = inversion.cls_list_from(cls=Mapper)[0] +interpolator = mapper.interpolator +print(f" inversion class: {type(inversion).__name__}") +print(f" mapper params: {mapper.params}") +print(f" interpolator: {type(interpolator).__name__}") +print(f" regularization: {type(pixelization.regularization).__name__}") + +# The interpolator's stencil tables. `_mappings_sizes_weights_split` is a +# cached_property, so these are the very arrays the library hands +# `reg_split_from` — which is what makes W2 meaningful. +_mappings, _sizes, _weights = interpolator._mappings_sizes_weights_split +_mappings = np.asarray(_mappings) +_sizes = np.asarray(_sizes) +_weights = np.asarray(_weights) + +print( + f" stencil tables: mappings {_mappings.shape} {_mappings.dtype}, " + f"sizes {_sizes.shape} {_sizes.dtype}, weights {_weights.shape} {_weights.dtype}" +) + +# Snapshots for W2, taken BEFORE the library builds H. +_mappings_before = _mappings.copy() +_sizes_before = _sizes.copy() +_weights_before = _weights.copy() + +n_zero_size_rows = int((_sizes == 0).sum()) + +regularization_weights = np.asarray( + pixelization.regularization.regularization_weights_from(linear_obj=mapper, xp=np), + dtype=float, +) + +# --- the library's own H (the kernel path) --------------------------------- +_t0 = time.time() +_h_library_full = np.asarray(inversion.regularization_matrix, dtype=float) +_t_library = time.time() - _t0 + +# S3 is source-only, so the inversion's regularization matrix should already be +# the mapper's own (P, P) block. It is sliced rather than assumed: a leg that +# ever grows a linear-func block would otherwise compare a padded matrix to an +# unpadded one and report a shape error instead of a verdict. +_P = int(mapper.params) +if _h_library_full.shape == (_P, _P): + _h_library = _h_library_full + _sliced = False +else: + _idx = np.asarray(inversion.mapper_indices) + _h_library = _h_library_full[np.ix_(_idx, _idx)] + _sliced = True + +print( + f" library H: shape {_h_library_full.shape}" + f"{' -> mapper block ' + str(_h_library.shape) if _sliced else ''}, " + f"built in {_t_library * 1e3:.1f} ms" +) + +# --- W1: the reference chain reproduces it, bit for bit -------------------- +_t0 = time.time() +( + _ref_mappings, + _ref_sizes, + _ref_weights, +) = regularization_util._reg_split_reference( + np.array(_mappings), + np.array(_sizes), + np.array(_weights), +) +_h_reference = regularization_util._pixel_splitted_regularization_matrix_reference( + regularization_weights, + _ref_mappings, + _ref_sizes, + _ref_weights, +) +_t_reference = time.time() - _t0 + +_equal = bool(np.array_equal(_h_reference, _h_library)) +_max_abs_diff = float(np.max(np.abs(_h_reference - _h_library))) if not _equal else 0.0 + +_record( + "W1_regularization_matrix_bit_identical", + "PASS" if (_equal and n_zero_size_rows == 0) else "FAIL", + { + "array_equal": _equal, + "max_abs_diff": _max_abs_diff, + "shape": list(_h_library.shape), + "n_zero_size_stencil_rows": n_zero_size_rows, + "reference_wall_s": _t_reference, + "library_wall_s": _t_library, + "summary": ( + f"array_equal={_equal}, max|diff|={_max_abs_diff:.3e}, " + f"zero-size rows={n_zero_size_rows}, reference {_t_reference * 1e3:.1f} ms " + f"vs library {_t_library * 1e3:.1f} ms" + ), + }, +) + +# --- W2: the caller's stencil tables survived ----------------------------- +_w2_mappings_ok = bool(np.array_equal(_mappings, _mappings_before)) +_w2_sizes_ok = bool(np.array_equal(_sizes, _sizes_before)) +_w2_weights_ok = bool(np.array_equal(_weights, _weights_before)) +_w2_ok = _w2_mappings_ok and _w2_sizes_ok and _w2_weights_ok + +_record( + "W2_interpolator_tables_unmutated", + "PASS" if _w2_ok else "FAIL", + { + "mappings_unchanged": _w2_mappings_ok, + "sizes_unchanged": _w2_sizes_ok, + "weights_unchanged": _w2_weights_ok, + "summary": (f"mappings={_w2_mappings_ok}, sizes={_w2_sizes_ok}, weights={_w2_weights_ok}"), + }, +) + +# --- W3: the log evidence is the same ------------------------------------- +# Fresh fit objects on both sides. `fit` above already has its cached inversion +# warm, so it is dropped rather than reused: a figure_of_merit read off it would +# be read off an inversion built before the monkeypatch existed. +del fit, inversion, mapper + +_fit_kernel = _eager_s3_fit() +_fom_kernel = float(_fit_kernel.figure_of_merit) +print(f" figure_of_merit (kernel path): {_fom_kernel!r}") + +_kernel_reg_split = regularization_util.reg_split_np_from +_kernel_pixel_split = regularization_util.pixel_splitted_regularization_matrix_np_from + +_patch_calls = {"reg_split": 0, "pixel_splitted": 0} + + +def _reference_reg_split_np_from(splitted_mappings, splitted_sizes, splitted_weights): + """``reg_split_np_from``'s contract, served by the pure-Python reference. + + The reference mutates mappings and sizes in place, so both are copied here — + the same copies ``reg_split_np_from`` itself makes. + """ + _patch_calls["reg_split"] += 1 + return regularization_util._reg_split_reference( + np.array(splitted_mappings), + np.array(splitted_sizes), + np.array(splitted_weights), + ) + + +def _reference_pixel_splitted_np_from( + regularization_weights, splitted_mappings, splitted_sizes, splitted_weights +): + """``pixel_splitted_regularization_matrix_np_from``'s contract, via the reference. + + The weights are passed **unsquared**: the kernel entry point squares them + before the call, the reference squares them itself. + """ + _patch_calls["pixel_splitted"] += 1 + return regularization_util._pixel_splitted_regularization_matrix_reference( + regularization_weights, + splitted_mappings, + splitted_sizes, + splitted_weights, + ) + + +regularization_util.reg_split_np_from = _reference_reg_split_np_from +regularization_util.pixel_splitted_regularization_matrix_np_from = _reference_pixel_splitted_np_from +try: + _fit_reference = _eager_s3_fit() + _fom_reference = float(_fit_reference.figure_of_merit) +finally: + regularization_util.reg_split_np_from = _kernel_reg_split + regularization_util.pixel_splitted_regularization_matrix_np_from = _kernel_pixel_split + +print(f" figure_of_merit (reference path): {_fom_reference!r}") +print(f" monkeypatch call counts: {_patch_calls}") + +_w3_rel = abs(_fom_reference - _fom_kernel) / max(abs(_fom_kernel), 1e-300) +_w3_fired = _patch_calls["reg_split"] > 0 and _patch_calls["pixel_splitted"] > 0 + +_record( + "W3_log_evidence_identical", + "PASS" if (_w3_rel <= W3_RTOL and _w3_fired) else "FAIL", + { + "figure_of_merit_kernel": _fom_kernel, + "figure_of_merit_reference": _fom_reference, + "d_log_evidence_nats": _fom_reference - _fom_kernel, + "relative_difference": _w3_rel, + "rtol": W3_RTOL, + "monkeypatch_calls": dict(_patch_calls), + "monkeypatch_fired": _w3_fired, + "summary": ( + f"kernel {_fom_kernel:.12f} vs reference {_fom_reference:.12f} " + f"(rel {_w3_rel:.3e} <= {W3_RTOL:g}), patch calls {_patch_calls}" + ), + }, +) + +# =================================================================== +# PART C — the record +# =================================================================== + +_all_pass = all(entry["status"] == "PASS" for entry in results.values()) + +_config_name = _cli.config_name or "local" + +witness = { + "cell": "fixed_light_numba_levers_witness", + "issue": "autolens_profiling#267 (lever 1: numba split-regularization assembly)", + "verdict": "PASS" if _all_pass else "FAIL", + "results": results, + "configuration": { + "config_name": _config_name, + "mesh": MESH, + "dataset": DATASET, + "source_pixels": int(n_mesh_vertices), + "mesh_vertices_placed": int(image_plane_mesh_grid.shape[0]), + "regularization": reg_provenance, + "threads": N_THREADS, + "thread_env": thread_env, + "numba_thread_env": numba_thread_env, + "nnls_warm_start_env": os.environ.get("AUTOARRAY_NNLS_WARM_START"), + "use_jax": False, + "instance_seed": _IID_SEED, + "w3_rtol": W3_RTOL, + }, + "system": { + "n_params": int(system_s3.n_params), + "n_mapper": int(system_s3.n_mapper), + "n_funcs": int(system_s3.n_funcs), + "edge_zeroed_pixels": int(system_s3.edge_zero_mask.sum()), + "subtracted_light_flux": float(system_s3.subtracted_light_flux), + "mapper_params": _P, + "h_shape_full": list(_h_library_full.shape), + "h_sliced_to_mapper_block": _sliced, + "stencil_mappings_shape": list(_mappings.shape), + "stencil_sizes_max": int(_sizes.max()), + "n_zero_size_stencil_rows": n_zero_size_rows, + }, + "provenance": { + "autoarray_file": autoarray.__file__, + "autoarray_version": autoarray.__version__, + "autolens_version": al.__version__, + "hostname": socket.gethostname(), + "slurm_job_id": os.environ.get("SLURM_JOB_ID"), + "jax_in_sys_modules": "jax" in sys.modules, + "wall_s": time.time() - _t_start, + }, + "machine": machine_info_dict(), + "notes": ( + "W1 asserts np.array_equal between the retained pure-Python reference chain " + "(_reg_split_reference -> _pixel_splitted_regularization_matrix_reference) and the " + "library's own inversion.regularization_matrix on the HST Delaunay N=1500 source-only " + "(S3) AdaptSplit system fixed_light_numba.py route b builds. W2 asserts the " + "interpolator's cached stencil tables are byte-identical after the library inversion. " + "W3 asserts the fit's figure_of_merit is unchanged when both numpy entry points are " + "monkeypatched to the references. No timing is taken here and no pin is asserted; the " + "A/B milliseconds are the two arms of " + "hpc/batch_cpu/submit_breakdown_imaging_fixed_light_numba_levers_delaunay_ral_hst_fp64." + ), +} + +_out_dir = _workspace_root / "results" / "breakdown" / "imaging" +_out_dir.mkdir(parents=True, exist_ok=True) +_out_path = _out_dir / f"fixed_light_numba_levers_witness_{_config_name}.json" +_out_path.write_text(json.dumps(witness, indent=2, default=str)) + +print("\n" + "=" * 70) +print(f"VERDICT: {witness['verdict']}") +for _name, _entry in results.items(): + print(f" {_entry['status']:>4} {_name}") +print(f" Witness JSON saved to: {_out_path}") +print("=" * 70) + +if not _all_pass: + raise SystemExit( + "lever 1 witness FAILED — see the per-check summaries above and the witness JSON. " + "The A/B timing rows in this leg describe a matrix the reference does not reproduce." + ) diff --git a/scripts/misc/test/test_fixed_light_cell.py b/scripts/misc/test/test_fixed_light_cell.py index 6d64fb11d..a5a9a4cc6 100644 --- a/scripts/misc/test/test_fixed_light_cell.py +++ b/scripts/misc/test/test_fixed_light_cell.py @@ -56,17 +56,27 @@ def _profiling_root() -> _Path: def _submits() -> list[_Path]: # The phase-1 library-path legs (`..._fixed_light_library_*`) are a second # family with their own config name and their own static checks, in - # test_fixed_light_library.py, and the trace legs (`..._fixed_light_trace_*`, - # autolens_profiling#268) are a third, in test_fixed_light_trace_submit.py. - # Excluding them here keeps each file's assertions owned by the submits they - # were written for -- without it this file's `--config-name - # hpc_a100_fp64_fixed_light` assertion would pass on a library or trace leg - # only because `hpc_a100_fp64_fixed_light_library` / - # `hpc_a100_fp64_fixed_light_trace` happens to contain it as a substring. + # test_fixed_light_library.py, the trace legs (`..._fixed_light_trace_*`, + # autolens_profiling#268) are a third, in test_fixed_light_trace_submit.py, + # and the numba-lever legs (`..._fixed_light_numba_levers_*`, + # autolens_profiling#267) are a fourth, in + # test_fixed_light_numba_levers_submits.py. Excluding them here keeps each + # file's assertions owned by the submits they were written for -- without it + # this file's `--config-name hpc_a100_fp64_fixed_light` assertion would pass + # on a library or trace leg only because `hpc_a100_fp64_fixed_light_library` + # / `hpc_a100_fp64_fixed_light_trace` happens to contain it as a substring. + # The lever legs break the shape more strongly still: they are PyAutoArray + # two-arm A/B jobs that run TWO arms in one job (a control and a feature + # checkout, each on its own PYTHONPATH inside its own subshell), so + # `^python3 -u` cannot see the indented arms, and lever 1 runs the + # `delaunay.py` cell rather than `fixed_light.py`, so it takes no `--mesh` + # and writes under its own config names. return sorted( p for p in BATCH_GPU.glob("submit_breakdown_imaging_fixed_light_*") - if "_fixed_light_library_" not in p.name and "_fixed_light_trace_" not in p.name + if "_fixed_light_library_" not in p.name + and "_fixed_light_trace_" not in p.name + and "_fixed_light_numba_levers_" not in p.name ) diff --git a/scripts/misc/test/test_fixed_light_numba_levers_submits.py b/scripts/misc/test/test_fixed_light_numba_levers_submits.py new file mode 100644 index 000000000..0762eb768 --- /dev/null +++ b/scripts/misc/test/test_fixed_light_numba_levers_submits.py @@ -0,0 +1,338 @@ +"""Static checks on the two-arm numba-lever A100 submits (autolens_profiling#267). + +These legs are a different shape from every other ``submit_*fixed_light*`` +script, which is why they have their own file rather than riding on +``test_fixed_light_cell.py``'s single-arm contracts (see the comment beside that +file's ``_submits()``). Each lever submit runs **two arms back-to-back in one +job** — a control PyAutoArray checkout and a feature one — so that both share a +node, a GPU and a driver, and the only difference between the arms is the +library revision. Each arm is a ``( ... )`` subshell that prepends its own +checkout to ``PYTHONPATH``, so the prepend cannot leak into the next arm. + +What that shape breaks, and what is checked here instead: + +- the run lines are **indented inside a subshell**, so ``^python3 -u`` does not + find them; here the anchor allows leading whitespace and the count must be + exactly two, one per arm; +- lever 1 runs ``likelihood_breakdown/delaunay.py``, not ``fixed_light.py`` — it + takes no ``--mesh`` (the cell *is* the mesh) and writes under its own + ``lever1`` config names, because it is a verbatim copy of the + ``..._adapt_split`` submit whose record it is compared against; +- levers 2 and 3 do wipe a fresh compilation cache per arm, but as + ``JAX_CACHE_CONTROL`` / ``JAX_CACHE_FEATURE`` rather than the single-arm + ``JAX_COMPILATION_CACHE_DIR`` string. + +The contracts that matter for an A/B are the ones about *provenance*: two +distinct private checkouts, neither of them the shared install (which +``HPCPullPyAuto`` moves under the job's feet), each arm echoing the checkout's +``rev-parse HEAD`` and the imported ``autoarray.__file__``, and two paired +``--config-name`` values so the control row cannot overwrite the feature row. + +The submit scripts themselves are frozen: the recorded RAL runs depend on their +text, so a failure here is fixed in this file or in a *new* submit, never by +editing one that has run. + +Run:: + + cd autolens_profiling + python -m pytest scripts/misc/test/test_fixed_light_numba_levers_submits.py +""" + +from __future__ import annotations + +import re +import subprocess +from pathlib import Path as _Path + +import pytest + + +def _profiling_root() -> _Path: + for _p in _Path(__file__).resolve().parents: + if (_p / "ruff.toml").exists(): + return _p + raise RuntimeError("autolens_profiling root (ruff.toml) not found") + + +ROOT = _profiling_root() +BATCH_GPU = ROOT / "hpc" / "batch_gpu" + +#: The meshes ``fixed_light.py``'s ``--mesh`` choices accept. +MESHES = ("rectangular", "delaunay", "delaunay_nn") + +#: Every ``fixed_light.py`` leg must write under a config name the harvest picks +#: up; the lever legs append their own suffix to it. +FIXED_LIGHT_PREFIX = "hpc_a100_fp64_fixed_light" + +#: The private per-arm PyAutoArray checkouts live under this directory on RAL. +CHECKOUT_PARENT = "/mnt/ral/jnightin/PyAuto_wt/fixed-light-numba-levers/" + +#: The shared install. It must never reach an arm's PYTHONPATH: HPCPullPyAuto +#: moves it whenever anyone refreshes it, so an arm resolved through it is not a +#: known revision. It may legitimately appear in the `git -C` echo lines that +#: record the other libraries' revisions. +SHARED_INSTALL = "/mnt/ral/jnightin/PyAuto/PyAutoArray" + +#: The prior record lever 1's submit is a verbatim copy of. +ADAPT_SPLIT_RECORD = "submit_breakdown_imaging_delaunay_a100_hst_fp64_adapt_split" + +LEVER_ONE = "submit_breakdown_imaging_fixed_light_numba_levers_delaunay_a100_hst_fp64" + + +def _submits() -> list[_Path]: + return sorted(BATCH_GPU.glob("submit_breakdown_imaging_fixed_light_numba_levers_*")) + + +def _arms(text: str) -> list[str]: + """The ``( ... )`` subshell arms of a submit, each returned as its own text. + + A line that is exactly ``(`` opens an arm and a line that is exactly ``)`` + closes it. Heredoc bodies are stepped over rather than parsed, because the + lever-3 submit builds its provenance snippet with ``$(cat <<'PYPROV' ...)`` + and that Python code has closing parens in column 0. Comment lines are + skipped outright: that same submit's header *describes* the heredoc in prose + (``$(cat <<'EOF' ...)``), and reading that as a real opener would swallow + the rest of the file. + """ + arms: list[str] = [] + current: list[str] | None = None + heredoc: str | None = None + + for line in text.splitlines(): + stripped = line.strip() + + if heredoc is not None: + if current is not None: + current.append(line) + if stripped == heredoc: + heredoc = None + continue + + if stripped.startswith("#"): + if current is not None: + current.append(line) + continue + + if current is not None: + if stripped == ")": + arms.append("\n".join(current)) + current = None + continue + current.append(line) + elif stripped == "(": + current = [] + + opener = re.search(r"<<-?\s*'?([A-Za-z_][A-Za-z0-9_]*)'?", line) + if opener is not None: + heredoc = opener.group(1) + + return arms + + +def _arms_by_role(path: _Path) -> dict[str, str]: + """The two arms keyed ``control`` / ``feature`` by the checkout each prepends.""" + arms = _arms(path.read_text()) + assert len(arms) == 2, ( + f"{path.name}: expected exactly two `( ... )` arms (control, feature), found {len(arms)}" + ) + + by_role: dict[str, str] = {} + for role in ("CONTROL", "FEATURE"): + matching = [a for a in arms if f"PYTHONPATH=$PYAUTOARRAY_{role}:$PYTHONPATH" in a] + assert len(matching) == 1, ( + f"{path.name}: expected exactly one arm exporting " + f"PYTHONPATH=$PYAUTOARRAY_{role}:$PYTHONPATH, found {len(matching)}" + ) + by_role[role.lower()] = matching[0] + + assert by_role["control"] is not by_role["feature"], ( + f"{path.name}: both roles resolved to the same arm" + ) + return by_role + + +def _run_scripts(path: _Path) -> list[str]: + """The ``python3 -u