Skip to main content

Redback-JAX

Documentation Status Tests codecov

A lightweight JAX-only rewrite of redback for electromagnetic transient modeling and Bayesian inference, designed to run efficiently on GPUs and TPUs in float32.

Overview

Redback-JAX reimplements redback's analytical transient models in JAX, using log10-space arithmetic throughout to stay float32-safe on GPU hardware. All bolometric functions return log10(L) rather than linear luminosities (which exceed the float32 maximum of ~3.4×10³⁸ erg/s). The full spectra pipeline — photosphere, blackbody SED, and bandflux integration — also operates in log10 space end-to-end.

Features

  • Float32-safe physics: All models operate in log10 space; no overflow on GPU even for luminosities ~10⁴⁵ erg/s
  • JIT-compiled and differentiable: Every model is decorated with @jax.jit; gradients flow through the full pipeline via jax.grad
  • vmap-based diffusion integrals: Arnett-style diffusion uses jax.vmap over time points with log-mirror quadrature nodes
  • Spectra pipeline: make_spectra_model(bolometric_fn) wraps any bolometric model to produce time × wavelength spectra for bandflux/magnitude comparison
  • Clean inference API: Prior, Likelihood, NestedSampler, and MCMCSampler — compose a full Bayesian fit in ~15 lines
  • Multi-sampler support: BlackJAX NUTS (MCMC) and nested sampling via blackjax.nss

Models

Bolometric models (return log10_lbol in erg/s)

Function Physics Reference
arnett_bolometric Ni/Co decay + Arnett diffusion Arnett 1982
magnetar_powered_bolometric Dipole spin-down + Arnett diffusion Nicholl+ 2017
csm_interaction_bolometric Forward/reverse shocks + CSM diffusion Chatzopoulos+ 2013
tde_analytical_bolometric t⁻⁵/³ fallback + Arnett diffusion —
shock_cooling_bolometric Shock-cooling envelope (n=10) Piro 2021
shocked_cocoon_bolometric Shocked jet cocoon Piro & Kollmeier 2018
metzger_kilonova_bolometric r-process ODE, 200 shells Metzger 2017
magnetar_boosted_kilonova_bolometric r-process ODE + magnetar injection Yu+ 2013

All bolometric functions return log10_lbol (log base-10 of luminosity in erg/s). This is the natural unit for GPU inference — float32 can represent log10 values for any physically realistic luminosity.

Spectra pipeline

make_spectra_model(bolometric_fn) wraps any bolometric model into a full SED pipeline:

  1. Calls bolometric_fn(time, **kwargs) → log10_lbol
  2. Computes photospheric temperature and radius in log10 space (with temperature floor)
  3. Evaluates blackbody flux density in log10 space
  4. Returns (time, lambdas, spectra) in observer frame

Fitting bolometric data

Since models return log10_lbol, fit observed bolometric luminosities in log10 space:

import jax.numpy as jnp
from redback_jax.models.supernova_models import arnett_bolometric

# Observed data
log10_lbol_obs = jnp.log10(observed_lbol)   # convert once
log10_lbol_err = sigma_lbol / (observed_lbol * jnp.log(10.0))  # propagate errors

# Model prediction
log10_lbol_model = arnett_bolometric(time, f_nickel=0.5, mej=1.0,
                                      vej=10000.0, kappa=0.1, kappa_gamma=10.0)

# Gaussian log-likelihood in log10 space
log_like = -0.5 * jnp.sum(((log10_lbol_obs - log10_lbol_model) / log10_lbol_err)**2)

Bayesian inference — photometric fitting

The Prior / Likelihood / NestedSampler / MCMCSampler API handles the full pipeline: model evaluation, bandflux integration, and sampling.

import jax
from redback_jax.inference import Prior, Uniform, Likelihood, NestedSampler, MCMCSampler
from redback_jax.utils import luminosity_distance_cm
from redback_jax.transient import Transient

REDSHIFT = 0.01
DL_CM    = luminosity_distance_cm(REDSHIFT)   # ~1.37e26 cm

# Free parameters
prior = Prior([
    Uniform(58580, 58620,  name='t0'),        # MJD explosion epoch
    Uniform(0.05,  0.30,   name='f_nickel'),
    Uniform(0.5,   3.0,    name='mej'),
    Uniform(3000,  12000,  name='vej'),
])

# Similar to how you would load a transient for Redback — but with JAX arrays
transient = Transient(
    time=times_list,
    y=mags_list,
    y_err=y_err,
    bands=bands_list,
    data_mode='magnitude',
    name='SN2019abcde',
    redshift=REDSHIFT,
)
# Likelihood — transient.time (MJD), transient.y (AB mag), transient.y_err, transient.bands
likelihood = Likelihood(
    model='arnett_spectra',
    transient=transient,
    fixed_params={
        'redshift':          REDSHIFT,
        'lum_dist':          DL_CM,
        'temperature_floor': 5000.0,
        'kappa':             0.07,
        'kappa_gamma':       0.1,
    },
    evaluation_mode='direct_photometry',  # opt-in fast path for fitting
)

# Nested sampling (BlackJAX)
ns_result = NestedSampler(likelihood, prior, outdir='results/').run(jax.random.PRNGKey(0))
ns_result.summary()

# Or MCMC with NUTS (BlackJAX)
mcmc_result = MCMCSampler(likelihood, prior, n_warmup=500, n_samples=2000, n_chains=4).run(
    jax.random.PRNGKey(1)
)
mcmc_result.summary()

Fast photometric inference modes

Likelihood now has opt-in fast evaluation modes for GPU fitting. The default remains evaluation_mode="full", so existing source-model behaviour is unchanged.

Mode What it does Keeps jax_supernovae.timeseries_multiband_flux? Best use
full Uses the model's default full source grid Yes Backward-compatible default
compact_source Uses a dataset-specific source phase grid for the likelihood Yes Faster fitting while keeping the source-cube infrastructure
direct_photometry Integrates the blackbody model directly through the precomputed bandpasses No Fastest photometric fitting path

Notes:

  • compact_source is inference-only and does not change the model defaults.
  • direct_photometry is currently available for spectra models built with make_spectra_model(...), including arnett_spectra.
  • These are fitting accelerators; if you need a reusable source or exported spectra, keep using the full spectra path.

Example: switching between modes

full_like = Likelihood(
    model='arnett_spectra',
    transient=transient,
    fixed_params=FIXED,
    evaluation_mode='full',
)

compact_like = Likelihood(
    model='arnett_spectra',
    transient=transient,
    fixed_params=FIXED,
    evaluation_mode='compact_source',
    compact_time_grid_size=256,
    compact_grid_pad_days=5.0,
)

fast_like = Likelihood(
    model='arnett_spectra',
    transient=transient,
    fixed_params=FIXED,
    evaluation_mode='direct_photometry',
)

See examples/arnett_ns_fast.py for a complete nested-sampling example using the fast path.

Available models

Pass any string from redback_jax.models.MODELS as the model argument:

from redback_jax.models import MODELS
print(list(MODELS.keys()))
# ['arnett_spectra', 'magnetar_spectra', 'csm_spectra', ...]

Direct spectra / magnitude evaluation

To compute magnitudes outside of inference (e.g. for plotting):

from redback_jax.sources import PrecomputedSpectraSource
from redback_jax.utils import luminosity_distance_cm

source = PrecomputedSpectraSource.from_arnett_model(
    f_nickel=0.15, mej=1.0, vej=8000.0,
    redshift=0.01,
    cosmo_H0=67.66, cosmo_Om0=0.3111,
)

# AB magnitude in ztfr at a set of phases
phases = jnp.linspace(-5, 40, 200)
mags   = source.bandmag({'amplitude': 1.0}, 'ztfr', phases)

Parameter conventions

Some parameters changed from the original redback package for float32 safety:

Model Old parameter New parameter Reason
tde_analytical_bolometric l0 (erg/s, ~10⁴³) log10_l0 Linear value overflows float32
shock_cooling_bolometric mass (Msun), radius (cm), energy (erg) log10_mass, log10_radius, log10_energy Intermediate products overflow float32

All other parameter names match redback exactly.

Float32 design

Physical luminosities of transients (~10³⁸–10⁴⁵ erg/s) exceed float32 max (~3.4×10³⁸). Redback-JAX solves this by:

  • Storing all engine luminosities as log10(L) throughout
  • Using log-sum-exp for combining decay terms (Ni/Co engine)
  • Normalising ODE state variables by a scale factor (E_scale) in the kilonova scan
  • Computing prefactors in log10 before any exponentiation
  • Keeping the blackbody SED, temperature, and photospheric radius all in log10 space

The only step that materialises linear values is the final bandflux integral over the SED — where the flux densities (~10⁻²⁰ erg/s/cm²/Å) are comfortably within float32 range.

Installation

git clone https://github.com/nikhil-sarin/redback-jax.git
cd redback-jax
pip install -e .

Dependencies

Python 3.12+ required.

Core: jax, numpy, scipy, pandas, matplotlib, astropy, wcosmo

Optional (inference): blackjax, flowmc, optax

Related Projects

  • redback — the original full-featured package
  • JAX-bandflux: jax-bandflux
  • JAX — the underlying numerical computing library

License

GNU General Public License v3.0 — see LICENSE.

Acknowledgments/Citations

Based on the original redback package.

If you use Redback-JAX, please cite the redback paper. Please make sure you also cite all relevant papers for the models. These are the same as the papers cited in the original redback package.

If you use magnitude/flux evaluation please also cite

  • JAX-bandflux: jax-bandflux and any other papers recommended by those authors.

If you do any sampling, please cite the relevant sampling papers.

  • BlackJAX: blackjax and any papers recommended by those authors.

Redback-JAX paper

A paper describing the Redback-JAX package is in preparation. Redback-JAX is still very much in development and the API/etc may not be stable.

Metadata

Release files for redback-jax 0.4.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 redback-jax 0.4.1
File Size Uploaded Provenance Actions
redback_jax-0.4.1.tar.gz 108.9 kB With provenance Details for redback_jax-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for redback-jax 0.4.1
File Interpreter ABI Platform Actions
redback_jax-0.4.1-py3-none-any.whl Python 3 none any Details for redback_jax-0.4.1-py3-none-any.whl

Total release size: 188.9 kB

Release files / redback_jax-0.4.1.tar.gz

Download URL redback_jax-0.4.1.tar.gz
Size 108.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a156593e2ed62be5adf57466d9503563493509e2bc1fc09403b46937c2b907b2
BLAKE2b-256 checksum
How to use checksums
8b8422e8a144022c2248e60e0adf83a512d3fa9427cabca3785266e12318c01d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.

Transparency log

Release files / redback_jax-0.4.1-py3-none-any.whl

Download URL redback_jax-0.4.1-py3-none-any.whl
Size 80.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
97f645042f00ba060f83f76ea869955889fbb17865713d0a0a9b49e1b79ba1bb
BLAKE2b-256 checksum
How to use checksums
aecddb842d8f6e3fa626dadd295cc46f217835f90396e5442bd13eb07033f8e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.

Transparency log

Security for redback-jax 0.4.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for redback_jax-0.4.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.

Transparency log

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.

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