Bridgestan
BridgeStan provides efficient in-memory access through Python, Julia, and R to the methods of a Stan model.
Install / Use
/learn @roualdes/BridgestanREADME
BridgeStan
BridgeStan provides efficient in-memory access through Python, Julia, Rust, and R to the methods of a Stan model, including log densities, gradients, Hessians, and constraining and unconstraining transforms. The motivation was developing inference algorithms in higher-level languages for arbitrary Stan models.
Stan is a probabilistic programming language for coding statistical models. For an introduction to what can be coded in Stan, see the Stan User's Guide.
BridgeStan is currently shipping with Stan version 2.38.0
Documentation is available at https://roualdes.us/bridgestan/
Compatibility
BridgeStan has been tested with the following operating system and C++ compiler combinations.
- Linux: Ubuntu 20.04 with gcc 9.4.0
- Apple: Mac OS X 12.2 with Apple clang 11.0.3
- Microsoft: Windows 10 with gcc MSYS2 5.3.0
Installing BridgeStan
Installing the core of BridgeStan is as simple as
installing a C++ toolchain
(libraries, compiler, and the make command), and downloading this
repository. To download the latest development version, you can run
git clone --recurse-submodules https://github.com/roualdes/bridgestan.git
For a full guide on installing, configuring, and using BridgeStan, consult the documentation
Using BridgeStan
Compiling a Stan program
To compile the Stan model in test_models/multi/multi.stan to a binary
shared object (.so file), use the following.
$ cd bridgestan
$ make test_models/multi/multi_model.so
This will require internet access the first time you run it in order
to download the appropriate Stan compiler for your platform into
<bridgestan-dir>/bin/stanc[.exe]
Example programs
This repository includes examples of calling Stan through BridgeStan in Python, Julia, R, Rust, and C.
-
From Python:
example.py -
From Julia:
example.jl -
From R:
example.r -
From Rust:
example.rs -
From C:
example.c
Examples of other functionality can be found in the test folder for each interface.
Software using BridgeStan
We are aware of the following projects using BridgeStan.
Julia
- https://github.com/sethaxen/StanLogDensityProblems.jl
- https://github.com/Julia-Tempering/Pigeons.jl
- https://github.com/TuringLang/TuringBenchmarking.jl
Python
- https://github.com/pymc-devs/nutpie (through Rust)
- https://github.com/UoL-SignalProcessingGroup/retrospectr
- https://github.com/UoL-SignalProcessingGroup/SMC-NUTS
R
- https://github.com/JTorgander/hmc-sandbox
- https://github.com/UCL/rmcmc
- https://github.com/CerulloE1996/BayesMVP/
Other
- https://github.com/xhep-lab/polystan
Research using BridgeStan
If you use BridgeStan in your research, please consider citing our JOSS paper and letting us know so we can list your project here.
- Verified Density Compilation for a Probabilistic Programming Language
- Variational Inference with Gaussian Score Matching
- Stein Π-Importance Sampling
- Batch and match: black-box variational inference with a score-based divergence
- Variational Inference in Location-Scale Families: Exact Recovery of the Mean and Correlation Matrix
- Sampling From Multiscale Densities With Delayed Rejection Generalized Hamiltonian Monte Carlo
- MCBench: A Benchmark Suite for Monte Carlo Sampling Algorithms
- Efficient scenario analysis in real-time Bayesian election forecasting via sequential meta-posterior sampling
- Fisher meets Feynman: score-based variational inference with a product of experts
- Generalized Guarantees for Variational Inference in the Presence of Even and Elliptical Symmetry
Acknowledgements
The Julia and Python APIs were derived from the Stan Model Server API, which in turn was derived from ReddingStan.
Thanks to Sebastian Weber (GitHub @wds15) for enabling multi-threaded calls from Julia to a single Stan model instance.
Thanks to Adrian Seyboldt (GitHub @aseyboldt) for providing the Rust wrapper.
Related Skills
node-connect
344.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
claude-opus-4-5-migration
99.2kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
frontend-design
99.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
model-usage
344.4kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
