Family spelling¶
How each dynamic target spells a kernel distribution on host expressions.
family_spelling
¶
How each dynamic target spells a QIEC distribution on host expressions.
A DistributionValue names a family of the semantic registry and
supplies its parameters by name. A host runtime needs that construction
as an expression of its own language, built from the host expressions
its arguments render to. This module owns those spellings: one function
per target that takes rendered argument expressions and returns the
target's constructor expression, applying the target's parameterization
conventions (rate against scale, complemented probabilities, reordered
or prepended arguments, leading matrix dimensions, folded half-line
families) and naming the runtime helpers the target must graft for
families it does not ship.
The conventions here are the ones the sample-step renderers apply to a
program's sample and observe steps; a family constructed as a
first-class value must score exactly as the same family sampled at a
site, so the two spellings agree parameter for parameter.
DYNAMIC_TARGET_LANGUAGES
module-attribute
¶
DYNAMIC_TARGET_LANGUAGES: dict[str, str] = {'pyro': 'python', 'numpyro': 'python', 'pymc': 'python', 'edward2': 'python', 'turing': 'julia', 'gen': 'julia', 'webppl': 'javascript', 'church': 'scheme'}
The dynamic targets, each mapped to the host language it renders to.
DistributionSpelling
didactic-model
¶
Bases: Model
One target's expression for a distribution construction.
| PARAMETER | DESCRIPTION |
|---|---|
expression
|
The host expression constructing the distribution.
TYPE:
|
helpers
|
Runtime helper roots the target must graft for the expression to resolve.
TYPE:
|
bridge_source
¶
The target's QIEC distribution bridge.
The bridge defines, in the target's host language, the array
conversion tensor-valued arguments pass through, the log-density
evaluation a LogDensity term renders to, and any wrapper a
support convention needs.
| PARAMETER | DESCRIPTION |
|---|---|
target
|
A dynamic target.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The bridge's source text. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If |
Source code in src/quivers/transpile/family_spelling.py
can_spell
¶
Whether a target spells a family as a first-class distribution.
| PARAMETER | DESCRIPTION |
|---|---|
target
|
A dynamic target.
TYPE:
|
family
|
A registry family name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
Source code in src/quivers/transpile/family_spelling.py
spell_distribution
¶
spell_distribution(target: str, family: str, arguments: Mapping[str, str], event_shape: tuple[int, ...] | None) -> DistributionSpelling
Spell a distribution construction for a dynamic target.
| PARAMETER | DESCRIPTION |
|---|---|
target
|
The dynamic target.
TYPE:
|
family
|
The family's registry name.
TYPE:
|
arguments
|
The supplied parameters, each a host expression, keyed by the registry's parameter names.
TYPE:
|
event_shape
|
The literal event shape of the constructed
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DistributionSpelling
|
The expression and the helpers it needs. |
| RAISES | DESCRIPTION |
|---|---|
UnsupportedConstruct
|
If the target has no spelling for the family, or a parameter it needs is absent. |
Source code in src/quivers/transpile/family_spelling.py
helper_roots
¶
The runtime helper roots a target grafts for the given families.
| PARAMETER | DESCRIPTION |
|---|---|
target
|
A dynamic target.
TYPE:
|
families
|
Family names constructed by the program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
frozenset[str]
|
The roots (helper class or function names) those families need. |
Source code in src/quivers/transpile/family_spelling.py
helper_families
¶
The families a target serves through grafted runtime helpers.
| PARAMETER | DESCRIPTION |
|---|---|
target
|
A dynamic target.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
frozenset[str]
|
The family names. |