XLuminA, a highly-efficient, auto-differentiating discovery framework for super-resolution microscopy
📄 Read our paper here:
Automated discovery of experimental designs in super-resolution microscopy with XLuminA
Carla Rodríguez, Sören Arlt, Leonhard Möckl and Mario Krenn
📰 Read the press release:
10,000 times faster than traditional methods: new computational framework automatically discovers experimental designs in microscopy
📚 Related works featuring XLuminA:
Machine Learning and the Physical Sciences Workshop - Poster
AI4Science Workshop - Oral contribution
AI4Science Workshop - Oral contribution
Create a new conda environment and install xluminafrom PyPI. We recommend using python=3.11:
conda create -n xlumina_env python=3.11
conda activate xlumina_env
pip install xlumina
It should be installed in about 10 seconds. The package automatically installs:
-
JAX (CPU only) and jaxlib (the version of JAX used in this project is v0.4.33),
-
Optax (the version of Optax used in this project is v0.2.3),
-
SciPy (the version of SciPy used in this project is v1.14.1).
git clone https://github.com/artificial-scientist-lab/XLuminA.git
To install JAX with NVIDIA GPU support (Note: wheels only available on linux), use CUDA 12 installation:
pip install --upgrade "jax[cuda12]"
XLuminA has been tested on the following operating systems:
Linux Enterprise Server 15 SP4 15.4,
and it has been successfully installed in Windows 10 (64-bit) and MacOS Monterey 12.6.2
XLuminA allows for the simulation, in a (very) fast and efficient way, of classical light propagation through optics hardware configurations,and enables the optimization and automated discovery of new setup designs.
The simulator contains many features:
✦ Light sources (of any wavelength and power) using both scalar or vectorial optical fields.
✦ Phase masks (e.g., spatial light modulators (SLMs), polarizers and general variable retarders (LCDs)).
✦ Amplitude masks (e.g., spatial light modulators (SLMs) and pre-defined circles, triangles and squares).
✦ Beam splitters, fluorescence model for STED, and more!
✦ The light propagation methods available in XLuminA are:
-
Chirped z-transform. This algorithm is an accelerated version of the Rayleigh-Sommerfeld method, which allows for arbitrary selection and sampling of the region of interest.
-
Propagation through high NA objective lenses is available to replicate strong focusing conditions using polarized light.
Examples of some experiments that can be reproduced with XLuminA are:
- Optical telescope (or 4f-correlator),
- Polarization-based beam shaping as used in STED (stimulated emission depletion) microscopy,
- The sharp focus of a radially polarized light beam.
The code for each of these optical setups is provided in the Jupyter notebook of examples.ipynb.
➤ A step-by-step guide on how to add noise to the optical elements can be found in noisy_4f_system.ipynb.
We evaluated our framework by conducting several tests - see Figure 1. The experiments were run on an Intel CPU Xeon Gold 6130 and Nvidia GPU Quadro RTX 6000.
(1) Average execution time (in seconds) over 100 runs, within a computational window size of
(2) We compare the gradient evaluation time of numerical methods (using Diffractio's optical simulator and SciPy's BFGS optimizer) vs autodiff (analytical) differentiation (using XLuminA's optical simulator with JAX's ADAM optimizer) across various resolutions:
(3) We compare the convergence time of numerical methods (using Diffractio's optical simulator and SciPy's BFGS optimizer) vs autodiff (analytical) differentiation (using XLuminA's optical simulator with JAX's ADAM optimizer) across various resolutions:
➤ The Jupyter notebook used for running these simulations is provided as test_diffractio_vs_xlumina.ipynb.
➤ The Python files corresponding to numerical/autodiff evaluations are numerical_methods_evaluation_diffractio.py, and autodiff_evaluation_xlumina.py
If you want to run the comparison test of the propagation functions, you need to install Diffractio - The version of Diffractio used in this project is v0.1.1.
With XLuminA we were able to rediscover three foundational optics experiments. In particular, we discover new, superior topologies together with their parameter settings using purely continuous optimization.
➤ Optical telescope (or 4f-correlator),
➤ Polarization-based beam shaping as used in STED (stimulated emission depletion) microscopy,
➤ The sharp focus of a radially polarized light beam.
The Python files used for the discovery of these optical setups, as detailed in our paper, are organized in pairs of optical_table and optimizer as follows:
| Experiment name | 🔬 Optical table | 🤖 Optimizer | 📄 File for data |
|---|---|---|---|
| Optical telescope | four_f_optical_table.py | four_f_optimizer.py | Generate_synthetic_data.py |
| Pure topological discovery: large-scale sharp focus (Dorn, Quabis and Leuchs, 2004) | hybrid_with_fixed_PM.py | hybrid_optimizer.py | N/A |
| Pure topological discovery: STED microscopy | hybrid_with_fixed_PM.py | hybrid_optimizer.py | N/A |
| 6x6 grid: pure topological discovery | six_times_six_ansatz_with_fixed_PM.py | hybrid_optimizer.py | N/A |
| Large-scale polarization-based STED | hybrid_sted_optical_table.py | hybrid_optimizer.py | N/A |
| Large-scale sharp focus (Dorn, Quabis and Leuchs, 2004) | hybrid_sharp_optical_table.py | hybrid_optimizer.py | N/A |
✦ Importantly, to ensure simulations which approximate real-world experimental conditions we have included imperfections, misalignment, and noise sources in all optical components (during post-processing and/or during optimization). All the results presented in the paper are computed considering a wide variety of experimental errors.
➤ A step-by-step guide on how to setup the optimization using this scheme can be found in noisy_optimization.ipynb.
➤ A step-by-step guide on how to add noise to the optical elements can be found in noisy_4f_system.ipynb.
✦ The optimization procedure is as follows: for each optimization step, we execute vmap. Then, we sample random noise and apply it to all available physical variables across each of the
- Phase values for spatial light modulators (SLMs) and wave plates (WP) in the range of
$\pm$ (0.01 to 0.1) radians, covering all qualities available in current experimental devices. - Misalignment ranging from
$\pm$ (0.01 to 0.1) millimeters, covering both expert-level precision ($\pm$ 0.01 mm) and beginner-level accuracy ($\pm$ 0.1 mm). - 1% imperfection on the transmissivity/reflectivity of beam splitters (BS), which is a realistic approach given the high quality of the currently available hardware.
We then simulate the optical setup for each of the
Importantly, before applying the updated parameters and proceeding to the next iteration, we resample new random noise for each optical table. This ensures that each optimization step encounters different noise values, further enhancing the robustness of the solution. This procedure is repeated iteratively until convergence.
In this section we list the available functions in different files and a brief description:
-
In wave_optics.py: module for scalar optical fields.
Class Functions Description ScalarLightClass for scalar optical fields defined in the XY plane: complex amplitude $U(r) = A(r)*e^{-ikz}$ ..drawPlots intensity and phase. .apply_circular_maskApply a circular mask of variable radius. .apply_triangular_maskApply a triangular mask of variable size. .apply_rectangular_maskApply a rectangular mask of variable size. .apply_annular_apertureApply annular aperture of variable size. .RS_propagationRayleigh-Sommerfeld diffraction integral in z-direction (z>0 and z<0). .get_RS_minimum_zGiven a quality factor, determines the minimum (trustworthy) distance for RS_propagation..CZTChirped z-transform - efficient diffraction using the Bluestein method. LightSourceClass for scalar optical fields defined in the XY plane - defines light source beams. .gaussian_beamGaussian beam. .plane_wavePlane wave. -
In vectorized_optics.py: module for vectorized optical fields.
Class Functions Description VectorizedLightClass for vectorized optical fields defined in the XY plane: $\vec{E} = (E_x, E_y, E_z)$ .drawPlots intensity, phase and amplitude. .draw_intensity_profilePlots intensity profile. .VRS_propagationVectorial Rayleigh-Sommerfeld diffraction integral in z-direction (z>0 and z<0). .get_VRS_minimum_zGiven a quality factor, determines the minimum (trustworthy) distance for VRS_propagation..VCZTVectorized Chirped z-transform - efficient diffraction using the Bluestein method. PolarizedLightSourceClass for polarized optical fields defined in the XY plane - defines light source beams. .gaussian_beamGaussian beam. .plane_wavePlane wave. -
In optical_elements.py: shelf with all the optical elements available.
Function Description Scalar light devices - phase_scalar_SLMPhase mask for the spatial light modulator available for scalar fields. SLMSpatial light modulator: applies a phase mask to incident scalar field. Jones matrices - jones_LPJones matrix of a linear polarizer jones_general_retarderJones matrix of a general retarder. jones_sSLMJones matrix of the superSLM. jones_sSLM_with_amplitudeJones matrix of the superSLM that modulates phase & amplitude. jones_LCDJones matrix of liquid crystal display (LCD). Polarization-based devices - sSLMsuper-Spatial Light Modulator: adds phase mask (pixel-wise) to $E_x$ and$E_y$ independently.sSLM_with_amplitudesuper-Spatial Light Modulator: adds phase mask and amplitude mask (pixel-wise) to $E_x$ and$E_y$ independently.LCDLiquid crystal device: builds any linear wave-plate. linear_polarizerLinear polarizer. BS_symmetricSymmetric beam splitter. BS_symmetric_SISymmetric beam splitter with single input. BSSingle-side coated dielectric beam splitter. high_NA_objective_lensHigh NA objective lens (only for VectorizedLight).VCZT_objective_lensPropagation through high NA objective lens (only for VectorizedLight).General elements - lensTransparent lens of variable size and focal length. cylindrical_lensTransparent plano-convex cylindrical lens of variable focal length. axicon_lensAxicon lens function that produces a Bessel beam. circular_maskCircular mask of variable size. triangular_maskTriangular mask of variable size and orientation. rectangular_maskRectangular mask of variable size and orientation. annular_apertureAnnular aperture of variable size. forked_gratingForked grating of variable size, orientation, and topological charge. 👷♀️ Pre-built optical setups - bb_amplitude_and_phase_modBasic building unit. Consists of a sSLM(amp & phase modulation), andLCDlinked viaVRS_propagation.building_blockBasic building unit. Consists of a sSLM, andLCDlinked viaVRS_propagation.fluorescenceFluorescence model. vectorized_fluorophoresVectorized version of fluorescence: Allows to compute effective intensity across an array of detectors.robust_discovery3x3 setup for hybrid (topology + optical settings) discovery with single wavelength. Longitudinal intensity (Iz) is measured across all detectors. Includes noise for robustness. hybrid_setup_fixed_slms_fluorophores3x3 optical table with SLMs randomly positioned displaying fixed phase masks; to be used for pure topological discovery; contains the fluorescence model in all detectors. (Fig. 4a of our paper) hybrid_setup_fixed_slms3x3 optical table with SLMs randomly positioned displaying fixed phase masks; to be used for pure topological discovery. (Fig. 4b of our paper) hybrid_setup_fluorophores3x3 optical table to be used for hybrid (topological + optical parameter) discovery; contains the fluorescence model in all detectors . (Fig. 5a and Fig. 6 of our paper) hybrid_setup_sharp_focus3x3 optical table to be used for hybrid (topological + optical parameter) discovery. (Fig. 5b of our paper) six_times_six_ansatz6x6 optical table to be used for pure topological discovery. (Extended Data Fig. 6 of our paper) 🫨 Add noise to the optical elements - shake_setupLiterally shakes the setup: creates noise and misalignment for the optical elements. Accepts noise settings (dictionary) as argument. Can't be used with jitacross parallel optical tables.shake_setup_jitSame as shake_setup. Doesn't accept noise settings as argument. Intended to be pasted in the optimizer file to enablejitcompilation across parallel optical tables. -
In toolbox.py: file with useful functions.
Function Description Basic operations - spaceBuilds the space where light is placed. wrap_phaseWraps any phase mask into $[-\pi, \pi]$ range.is_conserving_energyComputes the total intensity from the light source and compares is with the propagated light - Ref. softminDifferentiable version for min() function. delta_kroneckerKronecker delta. build_LCD_cellBuilds the cell for LCD.draw_sSLMPlots the two phase masks of sSLM.draw_sSLM_amplitudePlots the two amplitude masks of sSLM.moving_avgCompute the moving average of a dataset. image_to_binary_maskConverts image (png, jpeg) to binary mask. rotate_maskRotates the (X, Y) frame w.r.t. given point. gaussianDefines a 1D Gaussian distribution. gaussian_2dDefines a 2D Gaussian distribution. lorentzianDefines a 1D Lorentzian distribution. lorentzian_2dDefines a 2D Lorentzian distribution. fwhm_1d_fitComputes FWHM in 1D using fit for gaussianorlorentzian.fwhm_2d_fitComputes FWHM in 2D using fit for gaussian_2dorlorentzian_2d.profileDetermines the profile of a given input without using interpolation. spot_sizeComputes the spot size as $\pi (\text{FWHM}_x \cdot \text{FWHM}_y) /\lambda^2$ .compute_fwhmComputes FWHM in 1D or 2D using fit: gaussian,gaussian_2d,lorentzian,lorentzian_2.📑 Data loader - MultiHDF5DataLoaderData loader class for 4f system training. -
In loss_functions.py: file with loss functions.
Function Description small_area_hybridSmall area loss function valid for hybrid (topology + optical parameters) optimization vMSE_IntensityParallel computation of Mean Squared Error (Intensity) for a given electric field component $E_x$ ,$E_y$ or$E_z$ .MSE_IntensityMean Squared Error (Intensity) for a given electric field component $E_x$ ,$E_y$ or$E_z$ .vMSE_PhaseParallel computation of Mean Squared Error (Phase) for a given electric field component $E_x$ ,$E_y$ or$E_z$ .MSE_PhaseMean Squared Error (Phase) for a given electric field component $E_x$ ,$E_y$ or$E_z$ .vMSE_AmplitudeParallel computation of Mean Squared Error (Amplitude) for a given electric field component $E_x$ ,$E_y$ or$E_z$ .MSE_AmplitudeMean Squared Error (Amplitude) for a given electric field component $E_x$ ,$E_y$ or$E_z$ .mean_batch_MSE_IntensityBatch-based MSE_Intensity.
-
By default, JAX uses
float32precision. If necessary, enablejax.config.update("jax_enable_x64", True)at the beginning of the file. -
Basic units are microns (um) and radians. Other units (centimeters, millimeters, nanometers, and degrees) are available at
__init.py__. -
IMPORTANT - RAYLEIGH-SOMMERFELD PROPAGATION: FFT-based diffraction calculation algorithms can be innacurate depending on the computational window size (sampling).
Before propagating light, one should check which is the minimum distance available for the simulation to be accurate.
You can use the following functions:get_RS_minimum_z, forScalarLightclass, andget_VRS_minimum_z, forVectorizedLightclass.
Some functionalities of XLuminA’s optics simulator (e.g., optical propagation algorithms, lens or amplitude masks) are inspired in an open-source NumPy-based Python module for diffraction and interferometry simulation, Diffractio. We have rewritten and modified these approaches to combine them with JAX just-in-time (jit) functionality. We labeled these functions as such in the docstrings. On top of that, we developed completely new functions (e.g., sSLMs, beam splitters, LCDs or propagation through high NA objective lens with CZT methods, to name a few) which significantly expand the software capabilities.
If you use this software, please cite as:
Rodríguez, C., Arlt, S., Möckl, L. and Krenn, M. Automated discovery of experimental designs in super-resolution microscopy with XLuminA. Nat Commun 15, 10658 (2024). https://doi.org/10.1038/s41467-024-54696-y
BibTeX format:
@article{NatCommun.15.10658,
title={Automated discovery of experimental designs in super-resolution microscopy with {XLuminA}},
author={Rodríguez, Carla and Arlt, Sören and Möckl, Leonhard and Krenn, Mario},
journal={Nature Communications},
volume={15},
pages={10658},
year={2024},
publisher={Nature Publishing Group},
doi={10.1038/s41467-024-54696-y}
}




