Skip to content

Honour PYAUTO_TEST_MODE in LOSSampler to fix los_halos simulator timeouts#559

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/los-halos-test-mode-perf
May 29, 2026
Merged

Honour PYAUTO_TEST_MODE in LOSSampler to fix los_halos simulator timeouts#559
Jammy2211 merged 1 commit into
mainfrom
feature/los-halos-test-mode-perf

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

The los_halos workspace simulators (simulator.py and simulator_jax.py) timed out at the 300s cap under the integration runner, even with PYAUTO_TEST_MODE=2. These scripts run no non-linear search, so test mode had nothing to short-circuit. The real cost is in LOSSampler.galaxies_from():

  • negative_kappa_from runs a nested adaptive scipy.quad with an inner fsolve (~22.5k fsolve calls per plane) — ~3.8s × 9 planes ≈ 35s, and it is grid-independent, so PYAUTO_SMALL_DATASETS=1 never reduced it.
  • The sampler draws ~1100 halos per realisation, blowing up downstream ray-tracing and per-galaxy plotting. simulator_jax.py calls galaxies_from 9× (1 + a batch of 8) ≈ 290s of sampling alone.

This change makes LOSSampler honour PYAUTO_TEST_MODE: it caps the halo population to at most 3 per plane and calls negative_kappa_from with quad_limit=1, quad_epsrel=0.1. The expected scipy IntegrationWarning from the low limit is suppressed only in test mode. With test mode off, behaviour is unchanged (signature unchanged).

Verified under the real workspace integration env (PYAUTO_TEST_MODE=2 PYAUTO_SMALL_DATASETS=1 PYAUTO_FAST_PLOTS=1 PYAUTO_DISABLE_JAX=1):

Script Before (main) After
simulator.py timeout 320s (exit 124), 1100 halos 28s, 27 halos
simulator_jax.py timing out, 1100 halos 45s, 27 halos

Non-test-mode output is bit-identical to main: still 1100 halos with full-accuracy kappa values to 10 decimal places.

API Changes

autolens.lens.los.negative_kappa_from gains two optional keyword arguments, quad_limit=50 and quad_epsrel=1.49e-8 (both scipy's own quad defaults), threaded into its inner and outer integrals. Existing callers are unaffected. LOSSampler.galaxies_from now reads autoconf.test_mode.is_test_mode() internally; its signature is unchanged. No removals or renames. See full details below.

Test Plan

  • pytest test_autolens/lens/test_los.py (new file): loose-quad result matches a finer reference and stays negative; galaxies_from under PYAUTO_TEST_MODE caps halos to <=3 per plane and emits one negative-kappa MassSheet per plane.
  • simulator.py and simulator_jax.py run to exit 0 under the integration env in <50s each.
  • Non-test-mode galaxies_from is bit-identical to main (1100 halos, same 9 kappas).
Full API Changes (for automation & release notes)

Added

  • autolens.lens.los.negative_kappa_from(..., quad_limit=50, quad_epsrel=1.49e-8) — two optional kwargs controlling the adaptive subdivision limit and relative tolerance of both scipy.integrate.quad calls. Defaults equal scipy's own defaults, so behaviour is unchanged for existing callers.

Changed Behaviour

  • autolens.lens.los.LOSSampler.galaxies_from() — when PYAUTO_TEST_MODE is active (autoconf.test_mode.is_test_mode()), caps sampled LOS halos to at most 3 per plane and calls negative_kappa_from with quad_limit=1, quad_epsrel=0.1. The expected scipy IntegrationWarning from the low limit is suppressed only in test mode. With test mode off, behaviour is unchanged (signature unchanged).

Migration

  • None required. All changes are backward compatible.

🤖 Generated with Claude Code

…outs

LOSSampler.galaxies_from now caps the line-of-sight halo population to a
few per plane and loosens the negative-kappa quad integration when
PYAUTO_TEST_MODE is active. This collapses the los_halos simulator
runtime under the workspace integration runner (simulator.py 320s timeout
-> 28s; simulator_jax.py timeout -> 45s) while keeping the full sampling
and ray-tracing code paths exercised. Non-test-mode behaviour is
bit-identical (still samples ~1100 halos with full-accuracy kappa).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label May 29, 2026
@Jammy2211 Jammy2211 merged commit 6560762 into main May 29, 2026
6 checks passed
@Jammy2211 Jammy2211 deleted the feature/los-halos-test-mode-perf branch May 29, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-release PR queued for the next release build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant