Skip to main content

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.


Metadata

Release files for microjaxx 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for microjaxx 0.1.1
File Size Uploaded Provenance
microjaxx-0.1.1.tar.gz 75.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for microjaxx 0.1.1
File Interpreter ABI Platform
microjaxx-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 164.0 kB

Release files / microjaxx-0.1.1.tar.gz

Download URL microjaxx-0.1.1.tar.gz
Size 75.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b49484c93cd617e8f350e721072b506a81bd274513df7ad6ab90904f37c865a2
BLAKE2b-256 checksum
How to use checksums
0439ee265fa71ab0461f3ac6ab793e4d9a394eb18edab456108f405d482d7f6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Release files / microjaxx-0.1.1-py3-none-any.whl

Download URL microjaxx-0.1.1-py3-none-any.whl
Size 88.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
156f020af20e9dec41ac6cf966bfa60ca14d3cff76c2f3be5c34f92488a67935
BLAKE2b-256 checksum
How to use checksums
5e6f6add668dfda7a75460669bf522bb06549fb373c70bc1dea192df06b615c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Security for microjaxx 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page