API Reference¶
The public API of quivers, by subpackage, with each module page generated from its docstrings.
| Task | Start here | Result |
|---|---|---|
| Read the basic concepts | Concepts | Composition of weighted relations, the choice of Algebra, and the steps of a program |
Load a .qvr model |
DSL entry points | Parsed or compiled source, depending on the entry point |
| Build a weighted computation in Python | Objects, morphisms, and algebras | Finite sets, weighted tables between them, and the rules that combine their weights |
| Fit a model to data | Stochastic variational inference (SVI) or Markov chain Monte Carlo (MCMC) | An approximation to the posterior, with different computational tradeoffs |
| Fit a regression formula | Formulas | A generated model and fitted result from tabular data |
| Inspect the results | Diagnostics | Checks of inference behavior and predictive adequacy |
| Extend checking or execution | Quivers Indexed Effect Core | Explicit types, computations, and effect interfaces |
| Translate to another probabilistic programming language (PPL) | Transpilation | Target source, or a diagnostic naming the unsupported feature |
Core Package¶
The core package defines the objects, morphisms, composition rules, and tensor operations
shared by the other packages.
- Objects: finite and enumerated sets, products, coproducts, free monoids, and the categorial (Lambek) types over a set of atoms up to a fixed depth
- Laws: the catalogue of algebraic laws, the evidence for a claim (an argument, a decision procedure, a test, or a declaration), and the claims every member of the algebra hierarchy reports
- Algebras: the
Algebra,Semiring, andIdempotentSemiringclasses and the twelve built-in instances, each a semiring, a t-norm with its t-conorm, or a product with capped sum, plus duals and user-defined instances - Transformations: entrywise maps between
Algebrainstances and row normalizations, applied by change of base - Carriers: expectation, second-order expectation, and product semirings, which carry statistics of derivations beside their weight
- Spanning trees: the partition function and edge marginals of directed spanning trees, by elimination without subtraction
- Morphisms: base morphism classes and their composition
- Tensor Operations: noisy-OR contraction and reduction, noisy-AND reduction, and componentwise lifting of tensors
- Utilities: clamping and logarithm helpers for fuzzy computations
- Contractions: the evaluation of a contraction by variable elimination or in the written order, with its work
- Wiring: einsum contractions of many morphisms under one composition rule
Categorical Package¶
The categorical package contains functors, natural transformations, adjunctions, and monoidal
structures.
- Functors: functors between categories
- Natural Transformations: natural transformations between functors
- Adjunctions: adjoint pairs of functors
- Monoidal: monoidal structures on morphisms
- Change of Base: change of base between Boolean and fuzzy weights
- Traced: traced monoidal structure
Monadic Package¶
The monadic package contains the type class
hierarchy, monad instances, comonads, algebras, distributive laws, and algebraic
effects.
- Typeclass Hierarchy:
Functor,Applicative,Monad,Alternative,MonadPlus,Foldable,Traversable,MonadTransabstract base classes - Stdlib Effect Instances:
Identity,Maybe,Alternative_,Continuation,State,Reader,Writer - Algebraic Effects:
Operation,EffectSignature,Handler,FreeMonad - Bridges:
KleisliandArrowMonad, which connect the monad and arrow hierarchies - Typeclass Theories: the type classes as panproto theories, each the colimit of its extension diagram
- Typeclass Laws: the laws of each type class as checkable records
- Concrete Monads:
KleisliCategory,FuzzyPowersetMonad - Comonads: comonads and their co-Kleisli categories
- Algebras and Coalgebras: algebras of a monad and coalgebras of a comonad
- Distributive Laws: the interface of distributive laws between monads
Arrows Package¶
The arrows package contains the hierarchy of arrows
(Hughes, 2000), which parallels the monad hierarchy.
- Typeclass Hierarchy:
Category_,Arrow,ArrowChoice,ArrowApply,ArrowLoop,ArrowZero,ArrowPlus - Arrow Theories: the arrow classes as panproto theories, each the colimit of its extension diagram
- Arrow Instances: arrows of functions, weighted relations, and stochastic transitions
Theory Engine Package¶
The gat package calls panproto's engine for
generalized algebraic theories and
types its answers.
- Theory Engine: colimits of theory diagrams, views and their proof obligations, rewriting, finite models and their reducts, and theory change classification
- Records: provenance, composition reports and conflicts, witnesses, obligations, models
- Refusals:
CompositionRefused,ViewRefused,ModelRefused
Enriched Package¶
The enriched package contains constructions on categories
enriched over a chosen Algebra.
- Ends & Coends: ends and coends
- Kan Extensions: left and right Kan extensions along functions between finite sets
- Weighted Limits: weighted limits and colimits
- Profunctors: profunctors and their composition
- Yoneda: presheaves and the Yoneda embedding
- Day Convolution: the Day convolution product of presheaves
- Optics: lenses and other optics
Stochastic Package¶
The stochastic package contains finite stochastic morphisms, finite distribution families, and
weighted deduction systems.
- Morphisms: Markov kernels between finite sets, stored as stochastic matrices
- Families: parametric families of finite distributions
- Transforms: conditioning, mixing, and factoring of stochastic morphisms
- Queries: probabilities, marginals, and expectations
- Giry Monad: the distribution monad on finite sets (class
GiryMonad) and its Kleisli categoryFinStoch - Weighted Deduction: rule schemas, chart semirings, and chart parsers
- Agenda, Indexed Charts, Joins, Tries: the evaluation of deduction rules by keyed lookups, Generic Join, and variable elimination
- Plans, Packed Forests, Linear Cyclic Systems: the executor chosen from declared contracts, the derived hypergraph of a run, and cyclic systems solved through the algebra's closure
Continuous Package¶
The continuous package defines continuous spaces, distribution families, parameter sources, and
continuous morphisms.
- Spaces: typed carriers and support constraints for continuous values
- Morphisms: kernels with log densities and sampling methods
- Families: families of continuous distributions
- Programs: probabilistic programs over continuous spaces
- Marginalized responses: laws of responses whose density a marginal score holds
- Subsampled units: coefficients of unit weights under subsampled plates
- Boundaries: discretization and embedding between finite and continuous spaces
- Flows: normalizing flows
DSL Package¶
The dsl package implements the QVR language. A tree-sitter
grammar, driven through panproto, parses source, and
didactic Model types hold the AST nodes and value
types.
- Parser:
parse,parse_file, andParseError - AST Nodes: the
Modelclass of every syntactic node - Compiler: compilation from AST to
Program(Compiler,CompileError) - Resolution: the lenses (
dx.Lens) fromObjectExprto runtime values and back - Program Theory:
QVR_PROGRAM_PROTOCOLandextract_program_schema, which emit a panprotoSchemafor a compiled program
Inference Package¶
The inference package contains variational inference, MCMC, and posterior predictive sampling.
- Trace: execution traces of programs
- Conditioning: conditioning on observations
- Guides: variational guides
- ELBO: the evidence lower bound and related objectives
- SVI: stochastic variational inference
- Predictive: posterior predictive sampling
- Unit likelihoods: log likelihoods of the independent units of a fit's responses
- MCMC: Hamiltonian Monte Carlo (HMC) and No-U-Turn Sampler (NUTS) kernels, and the runner for several chains
Data, Diagnostics, and Formulas¶
These packages connect model definitions to tabular data and Bayesian analysis.
- Data: schemas for data frames and column encoders
- Diagnostics: conversion of traces for ArviZ, model comparison, and posterior predictive checks
- Formulas: R-style formula parsing, QVR generation, and the
fitentry point
Analysis Package¶
The analysis package derives metadata from checked programs without changing them.
- Chain shapes: step shapes and intermediate dimensions, located in the source
- Initialization: initialization recipes for each
Algebra - Saturation diagnostics: warnings tied to source locations
- Program inspection: plate graphs, their renderers, and lexical scope queries
Structural and Effects Packages¶
The structural package defines signatures, encoders, decoders, and attached losses for tree and
graph autoencoders over terms. The effects package gives handler stacks for conditioning,
intervention, reweighting, tracing, replay, and reparameterization.
- Signatures, Encoders, Decoders, Loss Registry, Shapes
- Effects overview, Handler base, Handlers, Traces, Checked programs, Score units, Batched evaluation
Transpilation and QIEC¶
The transpile package lowers checked programs through an IR that no target depends on and
renders them in eleven probabilistic programming languages. The qiec package holds the
Quivers Indexed Effect Core (QIEC), the typed core language that program
elaboration, execution, tooling, and structural computations share.
- Transpilation overview, Plan, Renderers
- QIEC overview, Checking, Evaluator, Execution
- Contracts, Rule presentations, Foreign handler semantics: queries, accuracy, recursion, and work records, deduction rules as QIEC declarations, and the semantics a foreign handler declares
Root Module¶
- Program:
Program, the container a compiled QVR module returns
Cited sources¶
John Hughes. Generalising Monads to Arrows. Science of Computer Programming, 37(1–3):67–111, 2000. URL: https://www.sciencedirect.com/science/article/pii/S0167642399000234, doi:10.1016/S0167-6423(99)00023-4.