Skip to main content

GenSBI Examples

Build Coverage Version Downloads DOI

This repository contains a collection of examples, tutorials, and recipes for GenSBI, a JAX-based library for Simulation-Based Inference using generative methods.

These examples demonstrate how to use GenSBI for various tasks, including:

  • Defining and running inference pipelines.
  • Using different embedding networks (MLP, ResNet, etc.).
  • Handling various data types (1D signals, 2D images).

Installation

To run these examples you need both GenSBI and this examples helper package (gensbi-examples). The helper package is installed automatically through the examples extra of GenSBI.

Using uv (recommended)

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

For GPU support (CUDA 12):

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

Using pip

pip install gensbi[examples]
# with GPU support (CUDA 12):
pip install gensbi[cuda12,examples]

For more installation options, including how to install uv, see the Installation Guide.

Download the example notebooks and scripts

The gensbi-examples package provides the helper utilities, but the notebooks and training scripts live in this repository. To get them, clone the repo:

git clone https://github.com/aurelio-amerio/GenSBI-examples.git

Structure

  • examples/: Contains standalone example scripts and notebooks.
  • src/gensbi_examples: Helper utilities for the examples.

Getting Started

  • My First Model: Open In Colab

Training Models

Models can be trained from the command line by passing a YAML configuration file to one of the provided training scripts. Each configuration file specifies the task, model architecture, training methodology (flow matching, diffusion, or score matching), optimizer settings, and training hyperparameters. Example configuration files can be found alongside each benchmark task under the config/ subdirectory (e.g., examples/sbi-benchmarks/two_moons/flow_flux/config/config_flow_flux.yaml).

General SBI tasks. For the standard SBI benchmark tasks (Two Moons, Gaussian Linear, SLCP, etc.), use the general-purpose training script:

python scripts/train_sbi_model.py --config <path_to_config.yaml>

This script trains the model, runs sampling, and computes diagnostic metrics (C2ST, TARP, SBC, LC2ST) automatically.

SBIBM benchmarks (budget/model/methodology scans). To reproduce the results reported in the main paper—including scans over training budget, model type, and methodology—use the dedicated SBIBM training script:

python scripts/train_sbi_model_sbibm.py --config <path_to_config.yaml>

This script additionally accepts a --dsize flag to control the training dataset size (default: 100,000), which is used for the budget scan experiments:

python scripts/train_sbi_model_sbibm.py --config <path_to_config.yaml> --dsize 10000

Advanced tasks. For more complex tasks such as gravitational waves and strong lensing, dedicated training scripts are provided in the corresponding example directories (e.g., examples/sbi-benchmarks/gravitational_waves/train-gw.py and examples/sbi-benchmarks/lensing/train-lensing.py).

Neural Density Estimators (NDE)

These examples demonstrate the usage of Neural Density Estimators for unconditional density estimation tasks.

  • Diffusion EDM 2D Unconditional: Open In Colab
  • Diffusion SM 2D Unconditional: Open In Colab
  • Flow Matching 2D Unconditional: Open In Colab
  • Flow Matching 2D Unconditional (Flux1Joint): Open In Colab

SBI Benchmark Examples

This repository includes a comprehensive suite of Simulation-Based Inference (SBI) benchmarks. These examples cover a range of standard tasks used to evaluate SBI methods, including simple distributions, physical systems, and complex toy problems. For each task, we provide implementations using various generative methods available in GenSBI, such as Flow Matching and Diffusion models with different architectures (Flux, SimFormer).

Two Moons

  • Diffusion Flux: Open In Colab
  • Diffusion Flux1Joint: Open In Colab
  • Diffusion SimFormer: Open In Colab
  • Flow Flux: Open In Colab
  • Flow Flux1Joint: Open In Colab
  • Flow SimFormer: Open In Colab

Bernoulli GLM

  • Flow Flux: Open In Colab
  • Flow Flux1Joint: Open In Colab

Gaussian Linear

  • Flow Flux: Open In Colab
  • Flow Flux1Joint: Open In Colab

Gaussian Mixture

  • Flow Flux: Open In Colab
  • Flow Flux1Joint: Open In Colab

Gravitational Waves

  • GW Example: Open In Colab

Lensing

  • Lensing Example: Open In Colab

SLCP

  • Flow Flux: Open In Colab
  • Flow Flux1Joint: Open In Colab
  • Flow SimFormer: Open In Colab

Release files for gensbi-examples 0.4.4

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

Source distribution (sdist)

Source distribution for gensbi-examples 0.4.4
File Size Uploaded
gensbi_examples-0.4.4.tar.gz 138.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gensbi-examples 0.4.4
File Interpreter ABI Platform
gensbi_examples-0.4.4-py3-none-any.whl Python 3 none any Details

Total release size: 277.6 kB

Release files / gensbi_examples-0.4.4.tar.gz

Download URL gensbi_examples-0.4.4.tar.gz
Size 138.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c1f67fe8b00cc468b6b6a15ef7061af6804c1559bf843172d0423c23706273ef
BLAKE2b-256 checksum
How to use checksums
06db5fa478c7977dd7c49c02227f3a7bd7509f1e0b214782a81f177cf5d32916
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","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}

Release files / gensbi_examples-0.4.4-py3-none-any.whl

Download URL gensbi_examples-0.4.4-py3-none-any.whl
Size 139.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c43d66788e46db35007443b0df07312894307558ac87860f9837fcf66a7e90b
BLAKE2b-256 checksum
How to use checksums
7658fb64ebbc670cb347ebe919f9064f2da542fccf8afd33c7bb6948df4b3056
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","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}

Release history Release notifications | RSS feed

This release

0.4.4 This release

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.6

2 release files

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