Skip to main content

Quivers

A functional probabilistic programming language for PyTorch.

CI Docs PyPI Python 3.14+ License: MIT

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 first-class composable typed values. A program has a domain, codomain, algebra, and effect signature ([effects=[Sample, Score, Marginal]]), checked at compile time. Programs compose with >>, parallel-compose with @, change base across algebras with change_base, and marginalize discrete latents with a scoped marginalize z : K <- ... block.
  • Shared substrate for inference, deduction, and structural compression. A CKY parser in a deduction block (its atoms, rule, and lexicon entries), a transformer-as-encoder over a signature block, and a Bayesian regression all compile to the same underlying semantics, with the same composition operators, and can thus 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.
  • Interactive tooling out of the box. qvr repl is a GHCi-style four-pane Textual TUI with live syntax highlighting, env browser, file-watcher auto-reload, command palette, and meta-commands (:type, :info, :browse, :edit, :save, :watch, …). qvr-lsp is a full LSP 3.17 language server (hover, definition, references, document symbols, semantic tokens, completion, formatting, live diagnostics) that VS Code, Cursor, Zed, and Neovim consume out of the box. A Jupyter kernel (qvr-kernel install) drives the same elaborator from notebooks.

Quick start

pip install quivers
object Item : FinSet 100

program regression : Item -> Item [effects=[Sample, Score]]
    sample sigma  <- HalfNormal(1.0)
    sample beta_0 <- Normal(0.0, 5.0)
    sample beta_1 <- Normal(0.0, 2.0)
    let mu = beta_0 + beta_1 * x
    observe y : Item <- 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: 41 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.7.1+, panproto 0.58.0+, panproto-grammars-all 0.58.0+.

Optional extras:

pip install 'quivers[repl]'    # Textual TUI, prompt_toolkit, rich, ipykernel
pip install 'quivers[lsp]'     # pygls language server
pip install 'quivers[repl,lsp]'  # both

After installing [repl] you can drop into the interactive type explorer:

qvr repl path/to/model.qvr

After installing [lsp] you have qvr-lsp on your PATH; the vscode-qvr and zed-extension-qvr extensions auto-discover it.

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quivers-0.16.0.tar.gz (5.8 MB view details)

Uploaded Source

Built Distribution

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

quivers-0.16.0-py3-none-any.whl (852.3 kB view details)

Uploaded Python 3

File details

Details for the file quivers-0.16.0.tar.gz.

File metadata

  • Download URL: quivers-0.16.0.tar.gz
  • Upload date:
  • Size: 5.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for quivers-0.16.0.tar.gz
Algorithm Hash digest
SHA256 a4f76d573e6b954052af580568d990fba8624c6e62a242c206189283ece79ca1
MD5 8af2c16073d91994c8c20c2f35a6e1fb
BLAKE2b-256 9e23a6cfed20742967176637362e9cc844caa62e406cd5ec7c650e2080710e7f

See more details on using hashes here.

Provenance

The following attestation bundles were made for quivers-0.16.0.tar.gz:

Publisher: release.yml on FACTSlab/quivers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quivers-0.16.0-py3-none-any.whl.

File metadata

  • Download URL: quivers-0.16.0-py3-none-any.whl
  • Upload date:
  • Size: 852.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for quivers-0.16.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70fede1a62b34c26df345f020f782a83a48d62abd9cd69a2f29b6315577fa112
MD5 a5e02d524ca5aaa68d2a166c6dc97181
BLAKE2b-256 3973ab2a523c0b682b6350b4fb670af420463b10f7cfa79c885f755f96eb9ac1

See more details on using hashes here.

Provenance

The following attestation bundles were made for quivers-0.16.0-py3-none-any.whl:

Publisher: release.yml on FACTSlab/quivers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.18.0

2 files

0.17.0

2 files

This release

0.16.0 This release

2 files

0.15.0

2 files

0.14.1

2 files

0.14.0

2 files

0.13.0

2 files

0.12.0

2 files

0.11.5

2 files

0.11.4

2 files

0.11.3

2 files

0.11.2

2 files

0.11.1

2 files

0.11.0

2 files

0.10.0

2 files

0.9.1

2 files

0.9.0

2 files

0.8.0

2 files

0.7.1

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 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