Skip to content

perf(tracer): skip the second ray-trace of the over-sampled grid at sub-size 1 (PyAutoArray#514) - #718

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/numpy-deflections-p1
Sep 2, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/numpy-deflections-p1

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Phase 1 of the numpy-deflections-cpu epic (PyAutoArray#514). Tracer.traced_grid_2d_list_from traced a Grid2D twice: once for the grid and once for grid.over_sampled, unconditionally. At a uniform over-sample size of 1 (the pixelization grid of every CPU likelihood evaluation, over_sample_size_pixelization=1) the over-sampled grid is the slim grid in the same order, so the second trace doubled every deflection-angle calculation for a bit-identical result. The over-sample size is host numpy, so the new guard is a static Python bool at JAX trace time, not a traced cond; at sub-size > 1 the existing second trace runs unchanged.

Measured with autolens_profiling/scripts/lens/deflections/total.py --instrument hst (15,361 pixels, OMP_NUM_THREADS=1): tracer-to-raw-call ratio Isothermal 2.52× → 1.41×, PowerLaw 1.94× → 0.88× (the raw call includes the direct-Grid2D decorator overhead the companion PyAutoArray PR removes). Every deflection pin passes at rtol 1e-6; the pixelization_numba.py hst likelihood pin (27661.910133664103, rtol 1e-6) passes. numpy and JAX (jax.jit) results agree at sub-size 1 and 4.

API Changes

None — internal changes only. The traced Grid2D.over_sampled at sub-size 1 is now a Grid2DIrregular copy of the traced slim grid rather than a second, identical trace.
See full details below.

Test Plan

  • test_autolens: 576 passed (new tests in test_autolens/lens/test_tracer.py: traced .over_sampled equals traced(grid.over_sampled) and differs from the untraced grid, at sub-size 1 and 4; at sub-size 1 it equals the traced slim grid exactly).
  • JAX jit probe: numpy vs jax.jit traced grids agree at sub-size 1 and 4.
  • autolens_profiling lens cells + pixelization_numba.py hst: pins PASSED.
  • CI green.
Full API Changes (for automation & release notes)

Changed Behaviour

  • autolens.lens.tracer.Tracer.traced_grid_2d_list_from — when every entry of grid.over_sample_size is 1, the over-sampled traced grids are built from the already-traced slim grids instead of a second ray-trace of grid.over_sampled (bit-identical values; one fewer duplicate subgraph under jax.jit).

Generated by the PyAutoLabs agent workflow. Companion PRs: PyAutoArray (to_grid / Grid2D.over_sampled), PyAutoGalaxy (Galaxy.traced_grid_2d_from, same guard), autolens_profiling (scripts/lens/ measurement package).

Companion: PyAutoLabs/PyAutoArray#516
Companion: PyAutoLabs/PyAutoGalaxy#595

…ub-size 1 (PyAutoArray#514)

`Tracer.traced_grid_2d_list_from` traced the input `Grid2D` and then traced
`grid.over_sampled` a second time to fill the returned grids' `over_sampled`
attribute. When the grid's over-sampler is uniform at sub-size 1 — the
pixelization grid in every CPU likelihood cell — `grid.over_sampled` is the
slim grid in the same order, so the second trace recomputes a bit-identical
answer at full cost.

The sub-size is host numpy, so the guard is a static Python bool and the
branch is resolved at JAX trace time rather than becoming a traced `cond`.

Measured on `autolens_profiling/scripts/lens/deflections/total.py --instrument hst`
(the tracer/raw ratio, which normalises out laptop variance): Isothermal
2.52x -> 1.41x, PowerLaw 1.94x -> 0.88x, IsothermalSph 2.78x -> 1.61x,
PowerLawSph 2.43x -> 1.38x. Every pinned value still PASSES — the change is
bit-identical.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HWjPT94MPbEHT45kJmDpDh
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Sep 2, 2026
@Jammy2211
Jammy2211 merged commit 0fd9fd3 into main Sep 2, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/numpy-deflections-p1 branch September 2, 2026 21:23
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant