Skip to content

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, and IdempotentSemiring classes 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 Algebra instances 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.

Monadic Package

The monadic package contains the type class hierarchy, monad instances, comonads, algebras, distributive laws, and algebraic effects.

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.

Stochastic Package

The stochastic package contains finite stochastic morphisms, finite distribution families, and weighted deduction systems.

Continuous Package

The continuous package defines continuous spaces, distribution families, parameter sources, and continuous morphisms.

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, and ParseError
  • AST Nodes: the Model class of every syntactic node
  • Compiler: compilation from AST to Program (Compiler, CompileError)
  • Resolution: the lenses (dx.Lens) from ObjectExpr to runtime values and back
  • Program Theory: QVR_PROGRAM_PROTOCOL and extract_program_schema, which emit a panproto Schema for 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 fit entry point

Analysis Package

The analysis package derives metadata from checked programs without changing them.

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.

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.

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.