Skip to main content

Examples for the GenSBI library

Project description

GenSBI Examples

Build Coverage Version Downloads

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

Prerequisites

You need to have GenSBI and the examples package installed.

With CUDA 12 support (Recommended):

pip install gensbi[cuda12, examples]

CPU-only:

pip install gensbi

Install Examples Package

To download these examples, clone the github repository:

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 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

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_examples-0.4.2.tar.gz (137.8 kB view details)

Uploaded Source

Built Distribution

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

gensbi_examples-0.4.2-py3-none-any.whl (139.3 kB view details)

Uploaded Python 3

File details

Details for the file gensbi_examples-0.4.2.tar.gz.

File metadata

  • Download URL: gensbi_examples-0.4.2.tar.gz
  • Upload date:
  • Size: 137.8 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for gensbi_examples-0.4.2.tar.gz
Algorithm Hash digest
SHA256 5458fbe899867144f1de5a8af4994bd5c1b873c79c250cd6802e24dc35e473d4
MD5 68dbf8ecd600b046d0a3105b651cf210
BLAKE2b-256 e4253c1ad12516a9183e770e3df45daadc30f580c68235e749003e3e86ef434f

See more details on using hashes here.

File details

Details for the file gensbi_examples-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: gensbi_examples-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 139.3 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for gensbi_examples-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 91fd32b6f0e6e771f0e107a0eaa6c22f6a4ed57a9fa5027651b5dd7cdf9aa3f8
MD5 bf62c5c13af14521dfeb90ce25f8594c
BLAKE2b-256 fe3f2e3d5c9923f9e4eda8f3682d5c247b5f574cc0c5442d66f18f67e110fb04

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