Skip to main content

GenSBI is a library for Simulation-Based Inference using generative models in JAX.

Project description

GenSBI

Build Coverage GenSBI Logo

[!IMPORTANT]
This library is at an early stage of development. The API is potentially subject to change.

Overview

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

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.

Key Features

  • Modern SBI Algorithms: Implements cutting-edge techniques like Optimal Transport Conditional Flow Matching and Diffusion Models 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

pip install git+https://github.com/aurelio-amerio/GenSBI.git

For GPU support and other options, 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

two-moons posterior sampling two-moons posterior sampling

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_2d_unconditional.ipynb Open In Colab
    Demonstrates how to use diffusion models in 2D for unconditional density estimation.

Conditional Density Estimation:

  • two_moons_flow_simformer.ipynb Open In Colab
    Uses the Simformer model for posterior density estimation on the two-moons benchmark.
  • two_moons_flow_flux.ipynb Open In Colab
    Uses the Flux1 model for posterior density estimation on the two-moons benchmark.
  • gaussian_linear_flow_flux1joint.ipynb Open In Colab
    Uses the Flux1Joint model for posterior density estimation on the Gaussian Linear benchmark.
  • slcp_flow_simformer.ipynb Open In Colab
    Uses the Simformer model for posterior density estimation on the SLCP benchmark.

[!NOTE] A full list of the currently available examples is available at the examples documentation page.

Citing GenSBI

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

@misc{GenSBI,
  author       = {Amerio, Aurelio},
  title        = "{GenSBI: Generative models for Simulation-Based Inference}",
  year         = {2025}, 
  publisher    = {GitHub},
  journal      = {GitHub repository},
  howpublished = {\url{https://github.com/aurelio-amerio/GenSBI}}
}

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.

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

gensbi-0.0.2.tar.gz (20.5 MB view details)

Uploaded Source

Built Distribution

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

gensbi-0.0.2-py3-none-any.whl (151.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gensbi-0.0.2.tar.gz
  • Upload date:
  • Size: 20.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gensbi-0.0.2.tar.gz
Algorithm Hash digest
SHA256 0eaf5ce13aec286e4e51c7e2c4ea81eb0544cbb5b9aea7c469ad71fe0777809f
MD5 09794ed1498de70bb92d4ed37ed1ae35
BLAKE2b-256 add6c84a9c1601ff91f5d2af89ef517d669d63c1bd445f82c9548bd4c1f7cf2e

See more details on using hashes here.

Provenance

The following attestation bundles were made for gensbi-0.0.2.tar.gz:

Publisher: python-publish.yml on aurelio-amerio/GenSBI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: gensbi-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 151.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gensbi-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e014f6de9cf1f0d2bbefa34599303b0f961a2fc77fc306c8b675bd660fdc4f39
MD5 d0908dfbef8fb48f7c1a0a5cc98dcc7e
BLAKE2b-256 8bed1441e07082d5ff984c233dd79f068d7fddb615a740f02ae64da7c0bb8f6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for gensbi-0.0.2-py3-none-any.whl:

Publisher: python-publish.yml on aurelio-amerio/GenSBI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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