Skip to content

Execution and tooling

Every executable QVR declaration is run through one interface. The command line, the REPL with its terminal interface (TUI), and the Python API all list the checked entry points, validate static and value arguments, attach runtime providers, run the reference machine, and return stable qiec-run-* diagnostics. The reference machine is the library's interpreter for QIEC, the Quivers Indexed Effect Core (reference machine).

Check before you run

qvr check parses, compiles, and validates one or more files, each with the modules it imports:

qvr check model.qvr
qvr check model.qvr other.qvr
qvr check --target stan model.qvr
qvr check pkg.experiments.boolean --root .

A dotted module path is resolved below the --root directories (the working directory by default), and a file's imports below its own directory unless --root is given. A diagnostic in an imported module names that module's file and line.

Without --target, it reports parser, constraint, compiler, and QIEC diagnostics. With a target, it also analyzes the reachable QIEC computation graph and reports each feature the target lacks as qiec:capability:* or as a more specific QIEC code. qvr transpile --to TARGET then runs the renderer and writes target source, and it can report restrictions particular to that renderer. Running the generated source tests it with the target's own toolchain. qvr check --json emits the diagnostics as JSON. A typed hole is reported as a note with code qiec-hole, giving its goal type and the bindings in scope; notes are not errors, so a module with holes checks. Posterior inference is run through the inference drivers, not through qvr run.

The language server and the REPL take the same option:

qvr lsp --target numpyro
qvr repl --target numpyro model.qvr

The VS Code and Cursor extension exposes the target as the setting qvr.transpileTarget. A client may change it with workspace/didChangeConfiguration, and the server then rechecks every open document without reparsing it.

The CLI, REPL, language server, and Jupyter kernel share the same target preflight. It first checks reachable capabilities, then derives a target plan if those checks pass. All four preserve diagnostic kinds, messages, and source locations. Retargeting an open document reuses its checked module; a successful preflight still requires rendering and execution with the target's toolchain.

List entry points

An entry point is a named computation or program that a module exposes to qvr run, Program.run, and the transpilers.

qvr run model.qvr --list
qvr run pkg.experiments.boolean:fit '[0.5]' --root .

qvr run takes a file or a dotted module path, optionally with the entry after a colon. The entries are the module's own computations and programs, exported or not; an imported module's entries are listed by running that module. qvr doc renders a module's public interface.

The listing marks each entry as a computation (declared with define) or a program, and shows its value parameters, static binders, residual effects, result type, and, for a program, its sample sites. Omitting both the entry name and --list prints the same listing. In Python:

from quivers.dsl import load

compiled = load("docs/examples/source/bayesian_regression.qvr")
for entry in compiled.entry_points():
    print(entry.name, entry.kind, entry.result)

Run an entry

Computation arguments

Value arguments are JSON literals in declaration order:

qvr run functions.qvr robustify 8.0
qvr run functions.qvr pair 1 '[2.0, 3.0]'

Static binders are closed by name:

qvr run vectors.qvr total 1.0 2.0 3.0 --static n=3

A static value is a closed type, index, effect application, or, for a Nat binder, an integer. No source variable may remain free in it.

--exact runs a computation over the rationals instead of float64. A float argument is the decimal it spells, and the result is exact:

qvr run --exact model.qvr posterior 0.25 0.6 0.2
# posterior = 1/2 : Real

An operation whose result is in general irrational, such as exp, log, sqrt, or sigmoid, stops an exact run with an error that names it (exact evaluation).

qvr run refuses a module with typed holes, listing every hole. --holes runs a computation of such a module on the reference machine instead; a result that needs a hole's value is reported as indeterminate, and a program run is still refused:

qvr run --holes holed.qvr use 4
# use = indeterminate, stopped where ?helper is needed : Int

Program data and sites

A program's parameters are given as positional JSON arguments or as named --data bindings. Each --site NAME=JSON conditions one sample site on a value, and every site not named is drawn:

qvr run model.qvr regression \
  --data x='[0.0, 1.0, 2.0]' \
  --data y='[0.1, 1.2, 1.9]' \
  --site slope=0.9 \
  --site intercept=0.1 \
  --site sigma=0.3 \
  --seed 7 \
  --json

A parameter whose type has an axis named by a finite type, such as Real[Subject, Item], takes labeled data: an array in xarray's dictionary form, {"dims": [...], "coords": {...}, "data": [...]}, or a table, {"columns": {...}}. The labels are checked against the type's axes and coordinates and put in the order the type fixes; a missing or unknown coordinate fails the run with qiec-run-data (Programs and data).

Each invocation owns its data, observations, sites, generator state, parameter store, score accumulator, and execution trace, the record of every site's value and log density. No handler or mutable provider state is shared with the next invocation. Program.run takes the same names:

run = compiled.run(
    "regression",
    data={"x": [0.0, 1.0, 2.0], "y": [0.1, 1.2, 1.9]},
    sites={"slope": 0.9, "intercept": 0.1, "sigma": 0.3},
    seed=7,
)
print(run.value, run.log_joint)

It returns an EntryRun. Numeric values and the log joint remain tensors. The trace holds the events that qvr run --trace prints. The to_data() method converts the tensors to plain data for the payload that qvr run --json prints.

Test a module

qvr test runs the test, property and example declarations a module states beside its code, by default exactly over the rationals:

qvr test model.qvr
qvr test --json models/
qvr test --mutate grammar.qvr

Execution controls

Option Meaning
--seed N seed the reference generator that draws the sites not given with --site
--fuel STEPS stop after STEPS evaluation steps with qiec-run-fuel
--trace print the execution trace events to stderr (without --json)
--json print, on success, the value, result type, runtime label, trace, entry kind, and for a program the log joint, or, on failure, the diagnostics
--runtime FILE.json use the provider configuration in FILE.json

Fuel is a bound on the number of evaluation steps. Without --fuel a run has no bound, so a recursive define or a generated deduction that does not terminate runs until it is stopped.

Runtime providers

A runtime provider is an object that binds handlers and type validators, held only in the running Python process, into a run (RuntimeProvider). It gives the behavior for a typed request, such as drawing from a distribution or calling an attached encoder. A serialized module records only what it needs and under which stable identifier. It never holds a Python callable or a mutable object, so a checked module can be inspected and exchanged without executable content.

A provider configuration names providers and their options:

{
  "providers": [
    {"name": "core", "options": {}}
  ]
}

The core provider gives the reference machine, the distribution families, the standard handlers, search, weights, and parameter lookup. An installed package may register another provider under the quivers.qiec_runtime entry-point group. When a structural program is invoked through Program.run, the core provider is composed with the attachments for its compiled encoders and decoders.

A configuration is data and cannot contain a Python callable. Before evaluation begins, the module and the provider are matched by their stable attachment, handler, instance, and operation identifiers.

REPL and TUI

qvr repl model.qvr starts an interactive session, in the TUI unless --plain is given. The commands that run entry points are:

Command Purpose
:run list entry points
:run NAME JSON ... invoke a computation
:run NAME --data x=JSON --site z=JSON invoke a program
:runtime show the active provider configuration
:runtime core select a registered provider
:runtime FILE.json load a provider configuration
:detach detach every runtime provider
:effects NAME show the declared and inferred effects
:browse index_maps list the module's declared index maps
:dump NAME --json print the declaration's syntax tree as JSON

The TUI status bar shows the active runtime and the last result. Every command and key binding is listed in Interactive tools: REPL, kernel, and language server.

The Jupyter kernel preserves each blank-separated chunk's output and stops at the first error. A closed object prelude in an object-only session shares one preparation pass. Meta-commands, executable declarations, watches, and symbolic extents keep sequential preparation, including their generator state and intermediate diagnostics.

Model retains checked evidence for its original source AST. Binding can reuse that evidence while the source is identical; object specialization, template cloning, and source replacement require fresh checking. Reusing a model thus keeps each binding's data and specialized input contract independent.

Type-expression probes likewise retain the loaded module's checked evidence while allocating fresh native compiler state. Static target renderers reuse one capability selection within each render; a later render checks its own module again.

Language-server features

The QVR language server (LSP) uses the compiler's typed source model. It provides:

  • parser, checker, QIEC, and target capability diagnostics, each with a source range;
  • hovers for declarations, spliced definitions, calls, operations, instances, and inferred rows;
  • definitions, references, and renaming for symbols the QVR source declares, across the modules below the workspace folders, with open buffers read over the files on disk;
  • nested document symbols for handler clauses, locals, calls, program scopes, and index maps with their clauses;
  • completion of operations, names, keywords, built-ins, and paths by context;
  • semantic tokens classified by the rules of the Pygments lexer; and
  • formatting through the QVR emitter.

The VS Code, Cursor, and Zed extensions start qvr-lsp. Neovim and other clients launch it over stdio. Editor support gives the installation, and the LSP capability table lists the supported methods.

Transpilation

qvr transpile --list-targets prints the targets, and qvr transpile --help prints the options: --to TARGET for one target, --to-all for every target, -o FILE for the output of one target, -d DIR for the files of --to-all, and --index-map FILE for the layout of every tensor-typed parameter as JSON, each axis with its name, extent, and coordinates in position order (Transpilation). Check the target first, then transpile:

qvr check --target pyro model.qvr
qvr transpile --to pyro model.qvr

Pyro, NumPyro, PyMC, Edward2, Turing, Gen, WebPPL, and Church render every reachable QIEC computation as a function in the target language, called through one convention for all eight (target calling convention). Stan emits a closed, monomorphic scalar computation with no effects as a user-defined function. BUGS and JAGS accept a measured subset of programs and refuse calls they cannot express (call:graph:*). The generated transpilation support matrix reports, feature by feature and example by example, what each target accepts.

QVR counts indices from zero, and so does every value a program holds that a subscript reads: a factor binder, a marginalized latent, an index covariate such as group_idx, and a class code (a Categorical, OrderedLogistic, or OrderedProbit outcome, or a drawn class). A caller passes every target the same zero-based data, and a drawn class is returned zero-based.

Target Origin of its arrays What the generated program does
Pyro, NumPyro, PyMC, Edward2, WebPPL, Church zero reads every value as QVR does
Stan, Turing, Gen one keeps each value zero-based and adds one where it subscripts an array or where a categorical family scores it, so y[2 - t] reads the entry it reads in QVR
JAGS one as Stan, and binds an observed class code, shifted by one, in its data block
BUGS one as Stan, but refuses an observed class code with observe:class-code:<name>, since BUGS has no data block to shift it in and no statement that adds an arbitrary log density to score it

Stan has no discrete parameters and refuses a drawn class with sample:discrete-latent:<name>. Marginalize the class instead (exact marginalization).

Stable diagnostic families

Prefix Raised by
parse the source grammar
compile and the codes of particular constraints surface resolution and elaboration
qiec-* the QIEC checker: kinds, types, rows, coverage, and module validation
qiec-run-* entry selection, arguments, providers, evaluation, and results
qiec:capability:* a target that cannot represent a reachable checked feature
call:graph:* a target that cannot keep a reachable call

Tests and scripts should match the stable code. The message explains the particular source form, and its wording may change.

Grammar ownership and Panproto

quivers holds the grammar that defines QVR. tree-sitter is the parser generator in which the grammar is written, and panproto is the schema and migration toolkit that versions it.

  • grammars/qvr/grammar.js defines the tree-sitter grammar.
  • The generated parser sources and the compiled parser libraries ship in the quivers wheel.
  • A manifest checks that the grammar, the generated sources, the queries, and the compiled parser agree.
  • quivers installs this parser into panproto's parser registry before it parses any QVR source.

The package panproto-grammars-all gives the grammars of the other languages that the eleven transpile targets emit. Its copy of the QVR grammar may lag behind the one in quivers, and this does not change how quivers parses .qvr files. panproto gives the generic parse tree and composes the chain of grammar migrations that qvr migrate applies.

For editor highlighting, build against grammars/qvr/ in the quivers repository or install one of the quivers editor extensions. An editor pointed at panproto's grammar package may load an older QVR grammar that lacks some tokens.

Format identifiers

Three identifiers name three formats, and each can change without the others:

Identifier Names
qvr-source/v0.22 the source grammar and its elaboration to QIEC
qiec-core/v1alpha2 the typed core that checked modules are written in
qiec-json/v3 the deterministic JSON serialization of a checked module

New syntax that elaborates to existing core terms changes the first identifier and not the second, and a new serialization changes the third without changing how .qvr files parse. Code that exchanges checked modules tests the second and third, and editors and migration tools test the first.

Before a release

The release workflow tutorial checks every source and promised target, runs each public entry point, and inspects a trace before a module is published.