FlowLensing: Simulating Gravitational Lensing with Flow Matching

Hamees Sayed, Pranath Reddy, Michael W. Toomey, Sergei Gleyzer

TL;DR

This paper introduces FlowLensing, a novel deep learning model that rapidly and accurately simulates gravitational lensing images, a crucial tool for studying dark matter. By leveraging flow matching and diffusion transformers, FlowLensing achieves over 200x speedup compared to traditional methods while maintaining high fidelity, making large-scale dark matter substructure studies more feasible.

What Problem Does This Paper Address?

Gravitational lensing, the bending of light by massive objects, is a powerful astronomical tool for understanding dark matter distribution and testing cosmological models. However, simulating these lensed images with high fidelity is computationally intensive, especially when accounting for complex dark matter substructures. Current methods, like ray-tracing and forward-modeling, are too slow for the massive datasets required by modern surveys (e.g., Euclid). While deep learning offers speedups, existing generative models often struggle with maintaining physical consistency, precise control over lensing parameters, or suffer from slow inference due to iterative sampling. This bottleneck hinders detailed dark matter studies, particularly those focused on substructure.

Methods

The core of FlowLensing is a flow-matching model built upon a Diffusion Transformer (DiT) architecture. Flow matching is a continuous-time generative modeling technique that directly learns a vector field to transform samples from a simple prior distribution (like Gaussian noise) to the target data distribution. Unlike traditional diffusion models that rely on a fixed noising schedule and iterative denoising, flow matching learns a deterministic path, leading to faster and more stable sampling.

The DiT backbone allows the model to process images in patches and leverage self-attention mechanisms. Conditioning information, representing either discrete dark matter models or continuous lensing parameters, is integrated using adaptive layer normalization. The authors also employ classifier-free guidance to improve controllability, randomly dropping conditioning during training to enable both conditional and unconditional generation at inference time.

Datasets

The paper utilizes two simulated datasets generated using the lenstronomy software package to mimic Euclid-like survey observations:

  1. Dark Matter Model Conditioned (Discrete): This dataset comprises 89,104 images, each 64x64 pixels. It features three classes of dark matter substructure:
  2. CDM: Baseline with no simulated substructure.
  3. CDM with substructure: Host halo with truncated NFW substructures.
  4. Axionic dark matter: Modeled with vortex-like defects.
  5. Lensing Model Parameters (Continuous): This dataset contains 30,000 CDM images (with and without substructure). It is conditioned on continuous parameters:
  6. Einstein radius ($\theta_E$)
    • Source coordinates (x, y)
    • Subhalo mass function slope ($\beta$)

Key Insights and Ideas

  • Flow Matching for Speed and Stability: The adoption of flow matching, rather than traditional diffusion, is a key innovation. It bypasses the iterative denoising process, leading to significantly faster inference and more stable generation.
  • Diffusion Transformers for Scalability: Using a DiT architecture allows for efficient processing of image patches and effective integration of complex conditioning information, crucial for handling diverse dark matter models and lensing parameters.
  • Bridging Discrete and Continuous Conditioning: FlowLensing's ability to handle both categorical (dark matter types) and continuous (lensing parameters) conditioning is vital for its practical application in astrophysical simulations.
  • Physics Consistency as a Proxy for Fidelity: The authors use downstream classification and regression tasks (predicting dark matter class and lensing parameters from generated images) as indirect evidence of the model's physical consistency, a critical aspect for scientific simulations.

Key Results

  • Speedup: FlowLensing achieves a speedup of over 200x compared to classical simulators for intensive dark matter models, with inference taking only 0.36 seconds per sample (vs. 4.8 seconds for the baseline).
  • Image Quality: The model produces high-fidelity images, outperforming a baseline DDPM with a U-Net backbone in terms of PSNR (68.68 vs. 30.78) and SSIM (0.9993 vs. 0.8870).
  • Downstream Task Performance: FlowLensing demonstrates excellent physical consistency, achieving perfect classification AUC (1.00) for dark matter models and strong regression R² scores (0.833–0.945) for lensing parameters.
  • Efficiency: The model requires only 100 denoising steps for inference, compared to 1000 steps for the baseline, highlighting its computational efficiency.

Limitations and Future Work

  • Limitations: While the model shows strong performance, the authors acknowledge that the Inception model used for FID calculation is not trained on domain-specific data, potentially limiting its interpretability as an astrophysical realism indicator. The paper also notes that while classification and regression results serve as indirect evidence of physics consistency, directly weaving lensing equations into the model's architecture is a goal for deeper physical fidelity.
  • Future Work: The authors plan to:
  • Integrate lensing equations directly into the model architecture for enhanced physical accuracy.
  • Benchmark FlowLensing against other generative models like GANs and VAEs to explore its strengths.
  • Further investigate its capabilities for probing small-scale structures in surveys like Euclid.

Summary updated

Abstract

Gravitational lensing is one of the most powerful probes of dark matter, yet creating high-fidelity lensed images at scale remains a bottleneck. Existing tools rely on ray-tracing or forward-modeling pipelines that, while precise, are prohibitively slow. We introduce $\texttt{FlowLensing}$, a Diffusion Transformer-based compact and efficient flow-matching model for strong gravitational lensing simulation. $\texttt{FlowLensing}$ operates in both discrete and continuous regimes, handling classes such as different dark matter models as well as continuous model parameters ensuring physical consistency. By enabling scalable simulations, our model can advance dark matter studies, specifically for probing dark matter substructure in cosmological surveys. We find that our model achieves a speedup of over 200$\times$ compared to classical simulators for intensive dark matter models, with high fidelity and low inference latency. $\texttt{FlowLensing}$ enables rapid, scalable, and physically consistent image synthesis, offering a practical alternative to traditional forward-modeling pipelines.
BibTeX
@inproceedings{sayed2025flowlensing,
  author = {Hamees Sayed and Pranath Reddy and Michael W. Toomey and Sergei Gleyzer},
  title = {{FlowLensing: Simulating Gravitational Lensing with Flow Matching}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=9AAb6BzlwG},
}
Figure