Skip to main content

GenSBI: Generative Methods for Simulation-Based Inference in JAX

Build Coverage Version Downloads DOI

GenSBI Logo

Overview

GenSBI is a JAX-based library for Simulation-Based Inference (SBI) using state-of-the-art generative methods, currently revolving around Optimal Transport Flow Matching, Diffusion Models, and Normalizing Flows.

It is designed for researchers and practitioners who need a flexible, high-performance toolkit to solve complex inference problems where the likelihood function is intractable.

The companion paper with a review of methodologies and functionalities is available at: https://arxiv.org/abs/2605.27499

Key Features

  • Modern SBI Algorithms: Implements cutting-edge techniques like Optimal Transport Conditional Flow Matching, Diffusion Models, and Normalizing Flows for robust and flexible posterior inference.
  • Built on JAX and Flax NNX: Leverages the power of JAX for automatic differentiation, vectorization, and seamless execution on CPUs, GPUs, and TPUs.
  • High-Level Recipes API: A simplified interface for common workflows, allowing you to train models and run inference with just a few lines of code.
  • Powerful Transformer Models: Includes implementations of recent, high-performing models like Flux1, Flux1Join, and Simformer for handling complex, high-dimensional data.
  • Modular and Extensible: A clean, well-structured codebase that is easy to understand, modify, and extend for your own research.

Installation

Using uv (recommended):

uv add gensbi
# or, for a standalone install:
uv pip install gensbi

For GPU support:

uv add gensbi[cuda12]
# or
uv pip install gensbi[cuda12]

Or using pip:

pip install gensbi

For GPU support and other options, including how to install uv, see the Installation Guide.

Quick Start

To get started immediately, you can use the high-level API to train a model.

[!TIP] Check out the my_first_model.ipynb notebook for a complete, step-by-step introductory tutorial.

from flax import nnx
from gensbi.recipes import Flux1FlowPipeline
from gensbi.models import Flux1Params

train_dataset = ... # define a training dataset (infinite iterator)
val_dataset = ...   # define a validation dataset (infinite iterator)
dim_obs = ...       # dimension of the parameters (theta)
dim_cond = ...      # dimension of the simulator observations (x)
params = Flux1Params(...) # the parameters for your model

# Instantiate the pipeline
pipeline = Flux1FlowPipeline(
    train_dataset,
    val_dataset,
    dim_obs,
    dim_cond,
    params=params,
)

# Train the model
# Note: GenSBI uses Flax NNX, so we pass a random key generator
pipeline.train(rngs=nnx.Rngs(0))

# After training, get a sampler for posterior sampling
key = jax.random.PRNGKey(42)
samples = pipeline.sample(key, x_observed, num_samples=10_000)

Examples

Examples for this library are available separately in the GenSBI-examples repository.

Some key examples include:

Getting Started:

  • my_first_model.ipynb Open In Colab
    A beginner-friendly notebook introducing the core concepts of GenSBI on a simple problem.

Unconditional Density Estimation:

  • flow_matching_2d_unconditional.ipynb Open In Colab
    Demonstrates how to use flow matching in 2D for unconditional density estimation.
  • diffusion_EDM_2d_unconditional.ipynb Open In Colab
    Demonstrates how to use EDM diffusion models in 2D for unconditional density estimation.
  • diffusion_SM_2d_unconditional.ipynb Open In Colab
    Demonstrates how to use score-matching diffusion models in 2D for unconditional density estimation.

Conditional Density Estimation:

  • two_moons_flow_flux.ipynb Open In Colab
    Uses the Flux1 model for posterior density estimation on the two-moons benchmark.
  • two_moons_diffusion_flux.ipynb Open In Colab
    Uses the Diffusion model for posterior density estimation on the two-moons benchmark.

[!NOTE] A complete list of the currently available examples can be found at the examples documentation page.

Citing GenSBI

If you use this library, please consider citing this work and the original methodology papers, see references.

For the paper:

@article{amerio2026gensbi_paper,
      title={GenSBI: Generative Methods for Simulation-Based Inference in JAX}, 
      author={Aurelio Amerio},
      year={2026},
      eprint={2605.27499},
      archivePrefix={arXiv},
      primaryClass={cs.LG},
      url={https://arxiv.org/abs/2605.27499}, 
}

For the software:

@software{amerio2026gensbi_software,
  author       = {Amerio, Aurelio},
  title        = {GenSBI: Generative Methods for Simulation-Based Inference in JAX
                  },
  month        = may,
  year         = 2026,
  publisher    = {Zenodo},
  version      = {v0.3.4},
  doi          = {10.5281/zenodo.20410084},
  url          = {https://doi.org/10.5281/zenodo.20410084},
}

Reference implementations

[!NOTE] AI Usage Disclosure
This project utilized large language models, specifically Google Gemini and GitHub Copilot, to assist with code suggestions, documentation drafting, and grammar corrections. All AI-generated content has been manually reviewed and verified by human authors to ensure accuracy and adherence to scientific standards.

Download files

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

Source Distribution

gensbi-0.4.1.tar.gz (190.3 kB view details)

Uploaded Source

Built Distribution

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

gensbi-0.4.1-py3-none-any.whl (262.0 kB view details)

Uploaded Python 3

File details

Details for the file gensbi-0.4.1.tar.gz.

File metadata

  • Download URL: gensbi-0.4.1.tar.gz
  • Upload date:
  • Size: 190.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gensbi-0.4.1.tar.gz
Algorithm Hash digest
SHA256 5cc55fb484ed9f6640772458b2c4e7a38a181a7fd90377c9f93dc05610d47d5b
MD5 9b9f618aa1517e17f0a223ee0e98b277
BLAKE2b-256 cabf0d3b9b43f0a8c8bf0621d969a00862b27b96ea7403819cf763d45e311e96

See more details on using hashes here.

File details

Details for the file gensbi-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: gensbi-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 262.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gensbi-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 de66a3f795ab1c99ec575cd9da37e13e3dbf7721948630dcb15369ef4c7a1211
MD5 27189dd39ae17fdad2839f746ed842d0
BLAKE2b-256 f6fd45b33481c9743fa6a27df888a3457ee44806b18be2cab9bb475d6ffc4c01

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