A functional probabilistic programming language that compiles to PyTorch.
Project description
Quivers
A functional probabilistic programming language for PyTorch.
Tutorial · Examples · Guides · API · Semantics
Quivers is a functional probabilistic programming language for PyTorch. The surface will look familiar if you have used Pyro, NumPyro, Stan, or PyMC. But it has a few distinguishing features:
- Programs are typed compositional values. A program has a domain, codomain, algebra, and effect signature (
! Sample, Score, Marginal, Pure), checked at compile time. Programs compose with>>, parallel-compose with@, transport across algebras withchange_base, and marginalize discrete latents withmarginalize z : K <- ... in { ... }. - Shared substrate for inference, deduction, and structural compression. A CKY parser in a
deduction { atoms ... rule ... }block, a transformer-as-encoder over asignature { ... }block, and a Bayesian regression all compile to the same underlying semantics, with the same composition operators, and can therefore compose with each other. - Algebra-parametric semantics. Programs can be parameterized by eleven built-in or user-defined algebras. Homomorphisms between algebras are values you can transport models along, with the laws checked at compile time.
It also has some features you are used to from other PPLs:
- An inference toolkit. Forty distribution families. SVI with nine automatic guides (mean-field through full-rank multivariate normal, low-rank, mixture, IAF, neural-spline flow, AutoDAIS) and four objectives (ELBO, IWAE, Renyi, VR-IWAE) with reparameterized, score-function, sticking-the-landing, and DReG gradient estimators. NUTS and HMC with dual-averaging step-size adaptation and Welford mass-matrix adaptation.
- An analysis toolkit. Static introspection of compiled programs (per-step algebra, chain depth, intermediate shape, source mapping); algebra-aware, saturation-free initialization recipes that adapt to whichever value algebra a program is parameterized over; compile-time diagnostics flagging latents whose default initialization would saturate the active algebra.
- Diagnostics and model comparison. ArviZ ecosystem integration: posteriors from any inference method (NUTS, HMC, or SVI) export to ArviZ for trace plots, rank plots, ESS, and $\hat R$. PSIS-LOO (Pareto-smoothed importance-sampling leave-one-out cross-validation) for ranking competing models; posterior-predictive checks against user-defined test statistics; LOO-PIT for calibration.
- A mixed-effect model API. A brms-style formula frontend for mixed-effect regression compiles formulas to typed QVR programs through a bidirectional lens, with pandas / polars dataframes as the input surface and R-canonical conventions (orthogonal polynomials, R-style transforms in the formula evaluation namespace) as defaults. The emitted QVR is inspectable, so a formula-fitted model is a starting point you can hand-edit rather than a closed black box.
Quick start
pip install quivers
object Item : 100
program regression : Item -> Item ! Sample, Score
sigma <- HalfNormal(1.0)
beta_0 <- Normal(0.0, 5.0)
beta_1 <- Normal(0.0, 2.0)
let mu = beta_0 + beta_1 * x
observe y <- Normal(mu, sigma)
return y
export regression
from quivers.dsl import loads
from quivers.inference import AutoNormalGuide, ELBO, SVI
import torch
program = loads(open("regression.qvr").read())
model = program.morphism
guide = AutoNormalGuide(model, observed_names={"y"})
optim = torch.optim.Adam(guide.parameters(), lr=1e-2)
svi = SVI(model, guide, optim, ELBO())
for _ in range(2000):
svi.step(x_data, {"y": y_data})
The full walkthrough is in the tutorial.
Documentation
- Tutorial: the QVR DSL tutorial walks probabilistic-programming users from linear regression to inference-algorithm choice with PyMC, NumPyro, and Stan equivalents shown side-by-side, while the Python API tutorial covers the typed categorical surface.
- Examples gallery: 36 end-to-end models covering regression, latent-variable, state-space, language models, seq2seq, and formal grammars.
- Conceptual guides: feature-area deep dives.
- API reference: the typed Python surface.
- Denotational semantics: the meaning of every well-typed program in a $\mathcal{V}$-enriched symmetric monoidal closed category.
Installation
pip install quivers
From source:
git clone https://github.com/FACTSlab/quivers
cd quivers
pip install -e ".[dev]"
Requirements: Python 3.14+, PyTorch 2.0+, didactic 0.6.0+, panproto 0.45.0+, panproto-grammars-all 0.45.0+.
Contributing
See CONTRIBUTING.md. Issues and pull requests welcome at github.com/FACTSlab/quivers.
Acknowledgments
This project was developed by Aaron Steven White at the University of Rochester with support from the National Science Foundation (NSF-BCS-2237175 CAREER: Logical Form Induction, NSF-BCS-2040831 Computational Modeling of the Internal Structure of Events). It was architected and implemented with the assistance of Claude Code.
License
MIT. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quivers-0.9.1.tar.gz.
File metadata
- Download URL: quivers-0.9.1.tar.gz
- Upload date:
- Size: 1.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e613d762ec10acf7566ddbd697c669504f9e25f1b3727e95f9f401bc333f17d2
|
|
| MD5 |
3697e85c6e025857e8f2e8c6fa541e86
|
|
| BLAKE2b-256 |
e894b09250970db9981be93465f53625d45e4564b0e283c20bfe96cea0f0da0e
|
Provenance
The following attestation bundles were made for quivers-0.9.1.tar.gz:
Publisher:
release.yml on FACTSlab/quivers
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
quivers-0.9.1.tar.gz -
Subject digest:
e613d762ec10acf7566ddbd697c669504f9e25f1b3727e95f9f401bc333f17d2 - Sigstore transparency entry: 1553499065
- Sigstore integration time:
-
Permalink:
FACTSlab/quivers@2a086a5a6569943db7282057c60c9253cff11caa -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/FACTSlab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2a086a5a6569943db7282057c60c9253cff11caa -
Trigger Event:
push
-
Statement type:
File details
Details for the file quivers-0.9.1-py3-none-any.whl.
File metadata
- Download URL: quivers-0.9.1-py3-none-any.whl
- Upload date:
- Size: 551.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a28912381c5560dca48d70aeb80637ae3c5ddadce9536ccbafbf7b051ec39133
|
|
| MD5 |
30e0397d0689bd20cdd79a5a85e0ac3c
|
|
| BLAKE2b-256 |
754f790b8a08a015bc907b56ee135583ab6eb8e5984bcf47eb13bee5dfd42f5e
|
Provenance
The following attestation bundles were made for quivers-0.9.1-py3-none-any.whl:
Publisher:
release.yml on FACTSlab/quivers
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
quivers-0.9.1-py3-none-any.whl -
Subject digest:
a28912381c5560dca48d70aeb80637ae3c5ddadce9536ccbafbf7b051ec39133 - Sigstore transparency entry: 1553499070
- Sigstore integration time:
-
Permalink:
FACTSlab/quivers@2a086a5a6569943db7282057c60c9253cff11caa -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/FACTSlab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2a086a5a6569943db7282057c60c9253cff11caa -
Trigger Event:
push
-
Statement type: