setu#

setu logo

A bridge from simulation-based inference to PyMC and NumPyro.

Many scientific models are simulators: they generate data from parameters, but do not provide the likelihood \(p(x \mid \theta)\), the probability of an observation for a given set of parameters. That is exactly what Bayesian tools like PyMC and NumPyro need to recover the parameters behind observed data, so a simulator cannot be plugged into them directly.

setu (Sanskrit for bridge) closes that gap. It learns the likelihood from simulated data and exports it to a probabilistic programming language (PPL) in a single call, so the model, including priors, hierarchy, and posterior-predictive checks, is written in PyMC or NumPyro as usual.

pip install setu-sbi

Three steps take a simulator to a posterior: simulate, train a neural likelihood, export it into a PPL.

import jax
import pymc as pm
import setu

key = jax.random.key(0)

# `prior` samples parameters; `simulator` maps parameters to data.
# No tractable likelihood is required, which is the whole point.
dataset = setu.simulate_dataset(simulator, prior, n_samples=10_000, key=key)

# 1. Train a neural likelihood on the simulations.
nle = setu.create_nle(x_dim=3, theta_dim=3, key=key)
nle = setu.fit_nle(nle, dataset, key=key).nle

# 2. Export it into a PyMC model and sample the posterior as usual.
with pm.Model():
    theta = pm.Normal("theta", 0.0, 1.0, shape=3)
    setu.to_pymc(nle, theta=theta, x_observed=x_obs)
    idata = pm.sample(
        nuts_sampler="blackjax",
        nuts_sampler_kwargs={"chain_method": "vectorized"},
        progressbar=False,
    )

setu fits a specific case: an intractable likelihood together with repeated or hierarchical structure in the data. With a tractable likelihood, a PPL alone (PyMC, NumPyro, Stan) suffices; with high-dimensional observations and no repeated or hierarchical structure, a general SBI toolkit such as sbi or BayesFlow fits better (more on when to use setu). Within that niche it complements both, and tends to be faster on the benchmarked task.

New here? Start with Tutorial 1.

Tutorials

Learning-oriented, hand-held walkthroughs. Go from a simulator to a posterior in one sitting.

Tutorials
How-to guides

Task-oriented recipes for a specific goal, starting with installing the right extras.

How-to guides
Reference

Lookup: the full API, the (G, S, T, *E) shape conventions, and a glossary.

Reference
Explanation

Understanding-oriented essays: what SBI is, why validation matters, why hierarchical inference is powerful, and how fast setu is.

Explanation