Skip to main content

GPU-accelerated, differentiable microlensing modeling in JAX

Project description

microJAX is a GPU-accelerated, differentiable microlensing modeling library written in JAX.

microJAX

Python JAX PyPI Status License

microJAX is a fully‑differentiable, GPU‑accelerated software for modelling gravitational microlensing light curves produced by binary, and triple lens systems, using the image-centered ray shooting (ICRS) method (e.g., Bennett 2010). Written entirely in JAX, it delivers millisecond‑level evaluations of extended-source magnifications and exact gradients for every model parameter through the use of automatic differentiation, enabling gradient‑based Bayesian inference workflows such as Hamiltonian Monte Carlo (HMC) and variational inference.

This software is under active development and not yet feature complete.


Documentation

For detailed guides, tutorials, and the API reference, visit the hosted microJAX documentation. The rendered HTML bundle also lives in docs/ if you prefer browsing locally.


📦 Installation

From PyPI:

pip install microjaxx

Notes:

  • PyPI package name: microjaxx
  • Python import name: microjax
import microjax

Development install (from source, recommended):

# clone the repository
git clone https://github.com/ShotaMiyazaki94/microjax.git
cd microjax
pip install -e ".[dev]"

GPU support: JAX/JAXLIB with CUDA/ROCm depends on your environment. Please follow the official JAX installation guide to install the appropriate jaxlib for your accelerator:


🚀 Quickstart

Compute an extended-source binary-lens magnification light curve using the image-centered ray shooting (ICRS) method:

Note: mag_binary also works on CPU but is very slow.

import jax
import jax.numpy as jnp
from microjax.inverse_ray.lightcurve import mag_binary
jax.config.update("jax_enable_x64", True)

# Binary-lens parameters
s, q = 1.0, 0.01            # separation and mass ratio (m2/m1)
rho = 0.02                  # source radius (Einstein units)
tE, u0 = 30.0, 0.0          # Einstein time [days], impact parameter
alpha = jnp.deg2rad(10.0)  # trajectory angle
t0 = 0.0

# Source trajectory
N_points = 1000
t = t0 + jnp.linspace(-tE, tE, N_points)
tau = (t - t0)/tE
y1 = -u0*jnp.sin(alpha) + tau*jnp.cos(alpha)
y2 =  u0*jnp.cos(alpha) + tau*jnp.sin(alpha)
w_points = jnp.array(y1 + y2 * 1j, dtype=complex)

# Extended-source magnification (binary lens)
mu = mag_binary(w_points, rho, s=s, q=q)

For point-source magnification, use:

Note: mag_point_source runs on CPU (and GPU), so it works without a GPU.

from microjax.point_source import mag_point_source
mu_point = mag_point_source(w_points, nlenses=2, s=s, q=q)

Example output

Visualization of the ICRS method (binary-lens) Triple-lens magnification and its gradients Compare with VBBL (uniform source, binary-lens)
ICRS Triple-lens Compare VBBL

Refer to the example directory for code that creates these plots.

Note: Finite-source calculation with microJAX is extremely slow without a GPU. So, the latter two examples are significantly slower on a CPU.


⚠️ Known Limitations

  • Finite-source magnification trades memory/runtime for accuracy through resolution parameters; tune these settings to match your GPU's available memory and throughput.
  • For numerical stability and agreement across libraries, enable 64-bit precision in JAX (jax_enable_x64=True).
  • Triple-lens hexadecapole/ghost-image test is not yet implemented: triple-lens calculations fall back to full contour integration everywhere, which can be substantially slower.
  • GPU tests are opt-in; run them explicitly with pytest -m gpu. If JAX cannot see a CUDA GPU, those tests are skipped.

📚 References

🤝 Contributing

Pull requests are welcome! Please see CONTRIBUTING.md for coding style, test suite, and CI guidelines. Bug reports can be filed via GitHub Issues.

Running Tests

CPU-only tests:

pytest -q

GPU-only tests are opt-in and skipped by default. To run them on a CUDA-capable machine:

# optionally: export JAX_PLATFORMS=cuda
pytest -m gpu -q

These tests require JAX to detect a CUDA device. If not available, they are skipped. No additional environment flag is required beyond the -m gpu marker.

📜 License

This project is licensed under the MIT License. Third-party components bundled in the tree and their respective licenses are listed in third_party/README.md. If you use microJAX in academic work, please cite the upcoming Miyazaki et al. (2025) methods paper.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

microjaxx-0.1.1.tar.gz (75.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

microjaxx-0.1.1-py3-none-any.whl (88.6 kB view details)

Uploaded Python 3

File details

Details for the file microjaxx-0.1.1.tar.gz.

File metadata

  • Download URL: microjaxx-0.1.1.tar.gz
  • Upload date:
  • Size: 75.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for microjaxx-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b49484c93cd617e8f350e721072b506a81bd274513df7ad6ab90904f37c865a2
MD5 e0f50b464ccfd42ed9a9a251d95fe77d
BLAKE2b-256 0439ee265fa71ab0461f3ac6ab793e4d9a394eb18edab456108f405d482d7f6b

See more details on using hashes here.

File details

Details for the file microjaxx-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: microjaxx-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 88.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for microjaxx-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 156f020af20e9dec41ac6cf966bfa60ca14d3cff76c2f3be5c34f92488a67935
MD5 cd637a7d2a4f81c7b0e77a7d1bcc264a
BLAKE2b-256 5e6f6add668dfda7a75460669bf522bb06549fb373c70bc1dea192df06b615c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page