Skip to content

feat: batched_simulate_substructure via jax.vmap#545

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/batched-simulate-vmap
May 27, 2026
Merged

feat: batched_simulate_substructure via jax.vmap#545
Jammy2211 merged 1 commit into
mainfrom
feature/batched-simulate-vmap

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

  • Adds batched_simulate_substructure — wraps simulate_substructure with jax.vmap over halo params, masks, sheet kappas, and PRNGKeys
  • Adds los_realizations_to_arrays — stacks multiple LOSSampler Galaxy lists into batched (B, n_planes, max_N, n_params) padded arrays
  • Produces (B, H, W) image stacks — ~1024 noisy lensed images per GPU launch

API

from autolens.lens.substructure_util import (
    batched_simulate_substructure,
    los_realizations_to_arrays,
)

# Stack B realizations
hp_batch, hm_batch, sk_batch = los_realizations_to_arrays(
    realization_galaxies, plane_redshifts, max_n=200,
    profile_cls=ag.mp.NFWTruncatedSph,
)
keys = jax.random.split(jax.random.PRNGKey(0), batch_size)

# Batch simulate
images = jax.jit(batched_simulate_substructure)(
    grid, image_shape, hp_batch, hm_batch, scaling_matrix,
    macro_fn, macro_mask, sk_batch, source_fn,
    psf, exposure_time, sky, keys, ag.mp.NFWTruncatedSph,
)  # shape: (B, H, W)

Test plan

  • 8-element batch matches sequential loop (atol=1e-5)
  • jax.jit(batched_simulate_substructure) compiles and matches
  • Different realizations produce different images
  • Companion PR: autolens_workspace_test#129

Ref: PyAutoLens#542 (prompt 4 of 4) — completes the full feature series

🤖 Generated with Claude Code

Adds batched_simulate_substructure wrapping simulate_substructure with
jax.vmap over halo params, masks, sheet kappas, and PRNGKeys. Also adds
los_realizations_to_arrays helper to stack multiple LOSSampler outputs
into batched padded arrays. Produces (B, H, W) image stacks.

Ref: PyAutoLens#542 prompt 4 of 4.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Jammy2211 Jammy2211 merged commit b744801 into main May 27, 2026
6 checks passed
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