Renderers¶
The per-backend renderers consuming the IR.
renderers
¶
Per-backend renderers consuming the transpile IR.
Each backend implements the Renderer
protocol: one public render(ir: IRProgram) -> panproto.Schema method
plus four dispatch points (declare, sample, marginalize,
broadcast) that receive the call's
RenderContext. The IR-walk
dispatch, index-substitution helpers, the atom enumeration a marginalize
block is scored under, and the structural invariants
(assert_no_dangling_refs, assert_no_dropped_param_map,
assert_no_lists) live on
RendererBase, which every
in-tree renderer subclasses.
BlockKind
¶
BlockKind = Literal['data', 'parameters', 'transformed_parameters', 'model', 'generated_quantities', 'function_body']
Where a declaration lands in the target's program structure.
Each backend interprets the kind per its own program layout: Stan has actual blocks, while NumPyro's block is the function body.
SchemaFragment
¶
One panproto schema fragment.
Either an opaque vertex id, or the empty string when the dispatch point emits nothing of its own.
IRArgTransform
didactic-model
¶
IRArgTransform(*, inner: IRArg, transform: Literal['inv_square', 'inv', 'neg', 'log', 'exp', 'one_minus', 'pow_neg'], operand: IRArg | None = None, kind: Literal['transform'] = 'transform')
Bases: IRArg
A renderer-applied transform on an IR arg.
The renderer constructs this during emission when an
arg_aliases rename targets a parameterisation that requires
arithmetic conversion (e.g. BUGS tau = 1/(scale*scale) for
Normal). Per-renderer _ALIAS_TRANSFORMS tables key the
transform on the renamed target name; RendererBase provides
the constructor.
Most transforms act on inner alone (inv, neg,
one_minus = 1 - inner, ...). The two-operand pow_neg
additionally reads operand, emitting pow(inner, -operand):
the JAGS / BUGS Weibull rate parameterisation needs the
concentration argument as the exponent, so the reorder helper
threads it in as operand.
IRArgTransform is a renderer-side IR extension. Lower
never constructs it.
| PARAMETER | DESCRIPTION |
|---|---|
inner
|
The argument transformed.
TYPE:
|
transform
|
The transform applied.
TYPE:
|
operand
|
The second operand of
TYPE:
|
kind
|
The discriminator; always
TYPE:
|
IRMarginalAtom
didactic-model
¶
IRMarginalAtom(*, value: IRArgNumber, weight_family: str, weight_args: tuple[IRArg, ...], weight_arg_names: tuple[str, ...], scope: tuple[IRNode, ...])
Bases: Model
One atom of a marginalized latent's finite support.
RendererBase.marginal_atoms
returns one of these per support point of an
IRMarginalize. Together
they carry the whole integrated density: writing L_a for the
log-density the target accumulates while emitting scope, and
w_a for the log-density of weight_family(weight_args) at
value, the block contributes
logsumexp_a (w_a + L_a)
to the program's log-density, elementwise over whatever rows the scope's own plates carry. No latent variable is declared: the atoms replace it.
weight_family is not always the latent's own family. The
Bernoulli relaxations are integrated over the atoms 0 and 1 with
discrete Bernoulli weights, matching what the QVR compiler
enumerates, so weight_family reads "Bernoulli" and
weight_args carries only the probability argument.
IRMarginalAtom is a renderer-side IR extension. Lower
never constructs it.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The support point.
TYPE:
|
weight_family
|
The family whose log-density at
TYPE:
|
weight_args
|
The arguments
TYPE:
|
weight_arg_names
|
The parameter name of each of
TYPE:
|
scope
|
The block's body with the latent replaced by
TYPE:
|
RenderContext
¶
RenderContext(sb: SchemaBuilder, morphisms: dict[str, MorphismDecl], defines: dict[str, Expr], fresh_counter: int = 0, cards: dict[str, int] | None = None)
The mutable state of one render call.
A renderer creates one per call and threads it through the IR-walk dispatch and its helpers as the first positional argument. It holds the panproto schema builder the target program is assembled in, the resolved morphism and define tables, a counter for fresh vertex names, and the cardinality table. Unlike the IR it is mutable and does not round-trip.
| PARAMETER | DESCRIPTION |
|---|---|
sb
|
The schema builder the renderer emits into.
TYPE:
|
morphisms
|
The module's morphism declarations, by name.
TYPE:
|
defines
|
The module's define expressions, by name.
TYPE:
|
fresh_counter
|
The next fresh-name ordinal.
TYPE:
|
cards
|
The cardinality of each finite object, by name; empty when not supplied.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
sb |
The schema builder the renderer emits into.
|
morphisms |
The module's morphism declarations, by name.
|
defines |
The module's define expressions, by name.
|
fresh_counter |
The next fresh-name ordinal; helpers increment it as they mint names.
|
cards |
The cardinality of each finite object, by name.
TYPE:
|
Source code in src/quivers/transpile/renderers/_base.py
Renderer
¶
Bases: Protocol
The protocol every backend renderer satisfies.
transpile calls render on a lowered
IRProgram; the four dispatch points
are what the shared IR walk of
RendererBase calls per
node.
render
abstractmethod
¶
render(ir: IRProgram) -> Schema
Render a program to the target's panproto schema.
| PARAMETER | DESCRIPTION |
|---|---|
ir
|
The lowered program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Schema
|
The target program, in the target grammar's theory. |
Source code in src/quivers/transpile/renderers/_base.py
declare
abstractmethod
¶
declare(ctx: RenderContext, name: str, constraint: ConstraintSpec, plate: Plate, *, block: BlockKind) -> SchemaFragment
Emit the declaration of a named variable in block.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
block
|
Where the declaration lands in the target program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/_base.py
sample
abstractmethod
¶
sample(ctx: RenderContext, name: str, family: str, args: tuple[IRArg, ...], arg_names: tuple[str, ...], constraint: ConstraintSpec, plate: Plate, observed: bool) -> SchemaFragment
Emit the ~ statement of a sample or observe step.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The site's name.
TYPE:
|
family
|
The distribution family's QVR name.
TYPE:
|
args
|
The family's arguments, in family order.
TYPE:
|
arg_names
|
The parameter name of each argument.
TYPE:
|
constraint
|
The site's support.
TYPE:
|
plate
|
The site's event and batch dimensions.
TYPE:
|
observed
|
Whether the site is conditioned on data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/_base.py
marginalize
abstractmethod
¶
marginalize(ctx: RenderContext, node: IRMarginalize) -> SchemaFragment
Emit the scope integrating a discrete latent out.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
node
|
The marginalize block.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/_base.py
broadcast
abstractmethod
¶
broadcast(ctx: RenderContext, value: IRArg, target_shape: tuple[int, ...]) -> SchemaFragment
Emit the target's broadcast of value to target_shape.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
value
|
The argument broadcast.
TYPE:
|
target_shape
|
The shape broadcast to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/_base.py
RendererBase
¶
Bases: ABC
Shared IR-walk dispatch and helpers for backend renderers.
Subclasses implement target_protocol, declare, sample,
marginalize, broadcast, and may override render to wrap
the inherited walk with per-backend pre / post processing
(block emission, function header, etc.).
target_protocol
abstractmethod
¶
Return the panproto protocol for the renderer's target language.
Each renderer builds its schema from this protocol's
schema() builder.
| RETURNS | DESCRIPTION |
|---|---|
Protocol
|
The protocol of the target grammar. |
Source code in src/quivers/transpile/renderers/_base.py
declare
abstractmethod
¶
declare(ctx: RenderContext, name: str, constraint: ConstraintSpec, plate: Plate, *, block: BlockKind) -> SchemaFragment
Emit the declaration of a named variable in block.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
block
|
Where the declaration lands in the target program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/_base.py
sample
abstractmethod
¶
sample(ctx: RenderContext, name: str, family: str, args: tuple[IRArg, ...], arg_names: tuple[str, ...], constraint: ConstraintSpec, plate: Plate, observed: bool) -> SchemaFragment
Emit the ~ statement of a sample or observe step.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The site's name.
TYPE:
|
family
|
The distribution family's QVR name.
TYPE:
|
args
|
The family's arguments, in family order.
TYPE:
|
arg_names
|
The parameter name of each argument.
TYPE:
|
constraint
|
The site's support.
TYPE:
|
plate
|
The site's event and batch dimensions.
TYPE:
|
observed
|
Whether the site is conditioned on data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/_base.py
marginalize
abstractmethod
¶
marginalize(ctx: RenderContext, node: IRMarginalize) -> SchemaFragment
Emit the scope integrating a discrete latent out.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
node
|
The marginalize block.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/_base.py
broadcast
abstractmethod
¶
broadcast(ctx: RenderContext, value: IRArg, target_shape: tuple[int, ...]) -> SchemaFragment
Emit the target's broadcast of value to target_shape.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
value
|
The argument broadcast.
TYPE:
|
target_shape
|
The shape broadcast to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/_base.py
render
¶
render(ir: IRProgram) -> Schema
Walk the IR and route each node to the right dispatch.
The default walk dispatches on the IRNode discriminator:
| node | dispatch |
|---|---|
IRDataInput |
declare(name, ..., block="data") |
IRSample (latent) |
declare + sample(observed=False) |
IRObserve |
declare + sample(observed=True) |
IRDeterministic |
declare + sample(observed=True) (deterministic) |
IRScore |
renderer-specific (target +=) |
IRMarginalize |
marginalize(node) |
IRReturn |
_emit_return(names) |
Subclasses may override render to wrap the walk with
their own block prologue / epilogue.
| PARAMETER | DESCRIPTION |
|---|---|
ir
|
The lowered program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Schema
|
The target program, in the target grammar's theory. |
Source code in src/quivers/transpile/renderers/_base.py
index_for
¶
index_for(ctx: RenderContext, plate: Plate) -> tuple[str, ...]
Return loop-index names for the plate's batch_dims.
Returns one name per batch_dim, generated via
ctx.fresh_counter. Renderers pair these with each batch
dim's size to emit nested for (m_i in 1:B_i) loops.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
plate
|
The plate whose batch dimensions are looped over.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
One index name per batch dimension, outermost first. |
Source code in src/quivers/transpile/renderers/_base.py
substitute_indices
¶
Apply the loop-index names from names to the arg's
bracket indices.
Used by sample / observe rendering to thread the
surrounding plate's loop variables through an
IRArgRef's index list so
the emitted call form is name[m_0, m_1, ...].
| PARAMETER | DESCRIPTION |
|---|---|
arg
|
The argument whose index list is rewritten.
TYPE:
|
names
|
The surrounding plate's loop-index names.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IRArg
|
The argument with its nested indices substituted; any other argument unchanged. |
Source code in src/quivers/transpile/renderers/_base.py
marginal_atoms
¶
marginal_atoms(node: IRMarginalize, *, support_size: int | None = None) -> tuple[IRMarginalAtom, ...]
Expand an IRMarginalize node into weighted atoms.
Each returned IRMarginalAtom pins the latent within a copy of
node.scope. The renderer combines each atom's weight with its scope
log density and reduces the result with node.reduction.
support_size gives the class count for a "class_index" atom set;
binary atom sets ignore it.
| PARAMETER | DESCRIPTION |
|---|---|
node
|
The marginalize block.
TYPE:
|
support_size
|
The class count of a
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[IRMarginalAtom, ...]
|
One atom per support point, in support order. |
| RAISES | DESCRIPTION |
|---|---|
UnsupportedConstruct
|
If the family is unknown, has no supported marginal, or its class count is unresolved. |
Source code in src/quivers/transpile/renderers/_base.py
BUGSRenderer
¶
Bases: RendererBase
Render an IRProgram to BUGS.
Implements the four
RendererBase
dispatch points (declare, sample, marginalize, broadcast)
plus target_protocol and overrides render to install the
model { ... } block prologue and to wire the BUGS-specific
declaration-plate table that drives slice-emission for vector
arg positions.
target_protocol
¶
Return the panproto protocol for the BUGS tree-sitter grammar.
| RETURNS | DESCRIPTION |
|---|---|
Protocol
|
The protocol of the target grammar. |
Source code in src/quivers/transpile/renderers/bugs.py
render
¶
render(ir: IRProgram) -> Schema
Emit the BUGS source schema for ir.
Wraps the IR walk in a source_file -> model_block shell so
the emitted bytes are a complete BUGS file. The model_block's
ptrace-0 = Tmodel constraint forces the emitter to render
the optional model keyword.
| PARAMETER | DESCRIPTION |
|---|---|
ir
|
The lowered program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Schema
|
The target program, in the target grammar's theory. |
Source code in src/quivers/transpile/renderers/bugs.py
declare
¶
declare(ctx: RenderContext, name: str, constraint: ConstraintSpec, plate: Plate, *, block: BlockKind) -> SchemaFragment
No-op: BUGS has no declaration syntax distinct from ~ / data.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
block
|
Where the declaration lands in the target program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/bugs.py
sample
¶
sample(ctx: RenderContext, name: str, family: str, args: tuple[IRArg, ...], arg_names: tuple[str, ...], constraint: ConstraintSpec, plate: Plate, observed: bool) -> SchemaFragment
Emit a ~ statement with surrounding for loops.
BUGS treats observed and latent draws identically at the
syntactic level: the caller's data list pins the value of
observed variables and the same ~ line carries the
likelihood factor.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
family
|
The distribution family's QVR name.
TYPE:
|
args
|
The family's arguments, in family order.
TYPE:
|
arg_names
|
The parameter name of each argument.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
observed
|
Whether the site is conditioned on data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/bugs.py
marginalize
¶
marginalize(ctx: RenderContext, node: IRMarginalize) -> SchemaFragment
Emit an IRMarginalize
as the collapsed dcat row its atoms sum to when the scope is
a categorical mixture, and refuse it otherwise.
QVR's marginalize denotes the integral over the latent of
the measure the scope carries. A program that declares the
latent instead denotes a measure on the product of the
latent's support with the scope's, which differs from the
integral by an amount that moves with the data, so it is no
rendering of the block. BUGS has no statement that adds a
free log-density term to the joint, which is what a general
logsumexp reduction would need, so every scope the collapse
does not write is refused.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
node
|
The marginalize block.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/bugs.py
broadcast
¶
broadcast(ctx: RenderContext, value: IRArg, target_shape: tuple[int, ...]) -> SchemaFragment
Render a scalar-to-vector broadcast as a filled helper array.
BUGS has neither scalar-to-vector coercion nor a repetition function, so the renderer emits an indexed fill loop and references its resulting slice. Helpers are reused for identical scalar and extent pairs.
Only plate-free scalars can be hoisted outside enclosing plate loops.
Values that depend on loop indices and broadcasts to ranks other than
one raise UnsupportedConstruct.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
value
|
The argument broadcast.
TYPE:
|
target_shape
|
The shape broadcast to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/bugs.py
ChurchRenderer
¶
Bases: RendererBase
Render an IRProgram to a
Scheme schema in the Church probabilistic-programming idiom.
Subclass of RendererBase:
overrides render to wrap the IR walk in a top-level
(define (model <inputs...>) <body...>) form, then dispatches
each IRNode through declare /
sample / marginalize / broadcast.
target_protocol
¶
Return the panproto protocol of the target grammar.
| RETURNS | DESCRIPTION |
|---|---|
Protocol
|
The protocol of the target grammar. |
Source code in src/quivers/transpile/renderers/church.py
render
¶
render(ir: IRProgram) -> Schema
Render a program to the target's panproto schema.
| PARAMETER | DESCRIPTION |
|---|---|
ir
|
The lowered program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Schema
|
The target program, in the target grammar's theory. |
Source code in src/quivers/transpile/renderers/church.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
declare
¶
declare(ctx: RenderContext, name: str, constraint: ConstraintSpec, plate: Plate, *, block: BlockKind) -> SchemaFragment
Church has no separate declaration block.
Sample / observe bind their result names directly via
(define name (map ...)); data inputs land in the model
signature in render. This dispatch is a no-op for every
block.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
block
|
Where the declaration lands in the target program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/church.py
sample
¶
sample(ctx: RenderContext, name: str, family: str, args: tuple[IRArg, ...], arg_names: tuple[str, ...], constraint: ConstraintSpec, plate: Plate, observed: bool, via: str | None = None) -> SchemaFragment
Emit the per-batch-axis sample / observe form.
For a non-observed step with N batch dims:
(define <name>
(map (lambda (m_<a0>)
(map (lambda (m_<a1>) (sample <dist>))
(iota <B1>)))
(iota <B0>)))
For an observed step: a for-each over the observation
plate, with (observe <dist> (list-ref <obs> m)) inside
each iteration.
Half-support families (HalfNormal, HalfCauchy) inject a
loc=0 argument and wrap the base distribution in the
runtime half fold; references bound on an aligned plate
are indexed by the per-row loop variable; and a scalar family
stamped with event axes (via over=) wraps an inner map
over the event dims so each draw is the declared vector.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
family
|
The distribution family's QVR name.
TYPE:
|
args
|
The family's arguments, in family order.
TYPE:
|
arg_names
|
The parameter name of each argument.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
observed
|
Whether the site is conditioned on data.
TYPE:
|
via
|
The fibration an observe gathers its rows through, or
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/church.py
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 | |
marginalize
¶
marginalize(ctx: RenderContext, node: IRMarginalize) -> SchemaFragment
Lower IRMarginalize
to the forms that integrate its latent out.
The top-level
render
consumes the multi-form expansion via
_render_marginalize_forms so the latent sample and scope
observes sit as siblings of the surrounding (define (model
...) ...) body. When marginalize is invoked as a single
dispatch point (per the Renderer protocol contract), the
forms collapse into a (begin ...) block.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
node
|
The marginalize block.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/church.py
broadcast
¶
broadcast(ctx: RenderContext, value: IRArg, target_shape: tuple[int, ...]) -> SchemaFragment
(make-list K <value>) for 1-D broadcasts.
Higher-rank broadcasts raise
UnsupportedConstruct
with arg:broadcast-rank-2+ (Church has no canonical
matrix form, so a rank-2 broadcast has no idiomatic
rendering).
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
value
|
The argument broadcast.
TYPE:
|
target_shape
|
The shape broadcast to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/church.py
Edward2Renderer
¶
Bases: RendererBase
Render an IRProgram to TFP
Edward2 Python source.
Output shape (single function, all inputs defaulted to None):
def model(alpha=None, beta=None, word_idx=None, w=None):
theta = edward2.Dirichlet(tf.fill([3], alpha),
sample_shape=[20], name="theta")
phi = edward2.Dirichlet(tf.fill([200], beta),
sample_shape=[3], name="phi")
z = edward2.Categorical(probs=theta,
sample_shape=[20], name="z")
w = edward2.Categorical(probs=phi[z[word_idx]], name="w")
return theta
The walk overrides
RendererBase.render
because Edward2's program shape (single function, no block
structure) does not map onto the inherited block-by-block default
walk.
target_protocol
¶
Return the panproto protocol of the target grammar.
| RETURNS | DESCRIPTION |
|---|---|
Protocol
|
The protocol of the target grammar. |
Source code in src/quivers/transpile/renderers/edward2.py
render
¶
render(ir: IRProgram) -> Schema
Render a program to the target's panproto schema.
| PARAMETER | DESCRIPTION |
|---|---|
ir
|
The lowered program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Schema
|
The target program, in the target grammar's theory. |
Source code in src/quivers/transpile/renderers/edward2.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
emit_bytes
¶
emit_bytes(ir: IRProgram) -> bytes
Convenience: render ir and run emit_pretty to bytes.
| PARAMETER | DESCRIPTION |
|---|---|
ir
|
The lowered program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bytes
|
The target program's source. |
Source code in src/quivers/transpile/renderers/edward2.py
declare
¶
declare(ctx: RenderContext, name: str, constraint: ConstraintSpec, plate: Plate, *, block: BlockKind) -> SchemaFragment
No-op: Edward2 has no separate declarations.
Data inputs are emitted as function parameters by render;
sample / observe declarations are subsumed into the
edward2.<Family>(...) call assigned to the bound name.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
block
|
Where the declaration lands in the target program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/edward2.py
sample
¶
sample(ctx: RenderContext, name: str, family: str, args: tuple[IRArg, ...], arg_names: tuple[str, ...], constraint: ConstraintSpec, plate: Plate, observed: bool) -> SchemaFragment
Build the edward2.<Family>(...) call vertex.
The IR-walk in render calls this from a fresh PyCtx
wrapping ctx.sb. Edward2 has no native obs= keyword;
observations are surfaced by carrying them as default-None
function parameters and conditioning via the caller's
interceptor mechanism, so observed does not change the
emitted call.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
family
|
The distribution family's QVR name.
TYPE:
|
args
|
The family's arguments, in family order.
TYPE:
|
arg_names
|
The parameter name of each argument.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
observed
|
Whether the site is conditioned on data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/edward2.py
marginalize
¶
marginalize(ctx: RenderContext, node: IRMarginalize) -> SchemaFragment
No-op at the protocol dispatch point: the renderer drives
the enumeration through _emit_marginalize, which needs the
binding tables the top-level walk threads.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
node
|
The marginalize block.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/edward2.py
broadcast
¶
broadcast(ctx: RenderContext, value: IRArg, target_shape: tuple[int, ...]) -> SchemaFragment
Emit a tf.fill([...], <value>) call.
1D targets render as tf.fill([K], <value>); 2D as
tf.fill([R, C], <value>). The shape literal is a plain
Python list (Edward2 / TF accept it).
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
value
|
The argument broadcast.
TYPE:
|
target_shape
|
The shape broadcast to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/edward2.py
GenRenderer
¶
Bases: RendererBase
Render an IR program as a Gen.jl @gen function definition.
Inherits the IR-walk dispatch from
RendererBase.
Overrides the per-node dispatch in render to collect declarations
plus statements into the @gen function envelope; implements
declare, sample, marginalize, broadcast per the Gen.jl
idiom described in the module docstring.
target_protocol
¶
Return the panproto protocol of the target grammar.
| RETURNS | DESCRIPTION |
|---|---|
Protocol
|
The protocol of the target grammar. |
Source code in src/quivers/transpile/renderers/gen.py
render
¶
render(ir: IRProgram) -> Schema
Render a program to the target's panproto schema.
| PARAMETER | DESCRIPTION |
|---|---|
ir
|
The lowered program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Schema
|
The target program, in the target grammar's theory. |
Source code in src/quivers/transpile/renderers/gen.py
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 | |
declare
¶
declare(ctx: RenderContext, name: str, constraint: ConstraintSpec, plate: Plate, *, block: BlockKind) -> SchemaFragment
Emit the declaration of a named variable in block.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
block
|
Where the declaration lands in the target program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/gen.py
sample
¶
sample(ctx: RenderContext, name: str, family: str, args: tuple[IRArg, ...], arg_names: tuple[str, ...], constraint: ConstraintSpec, plate: Plate, observed: bool) -> SchemaFragment
Emit the ~ statement of a sample or observe step.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
family
|
The distribution family's QVR name.
TYPE:
|
args
|
The family's arguments, in family order.
TYPE:
|
arg_names
|
The parameter name of each argument.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
observed
|
Whether the site is conditioned on data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/gen.py
marginalize
¶
marginalize(ctx: RenderContext, node: IRMarginalize) -> SchemaFragment
Emit the scope integrating a discrete latent out.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
node
|
The marginalize block.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/gen.py
broadcast
¶
broadcast(ctx: RenderContext, value: IRArg, target_shape: tuple[int, ...]) -> SchemaFragment
Emit the target's broadcast of value to target_shape.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
value
|
The argument broadcast.
TYPE:
|
target_shape
|
The shape broadcast to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/gen.py
JAGSRenderer
¶
Bases: RendererBase
Render an IRProgram as a
JAGS model source.
Subclasses RendererBase:
overrides render to wrap the IR walk in a single top-level
model { ... } block. The four dispatch points (declare,
sample, marginalize, broadcast) follow the JAGS surface
conventions described in section 5.1 of the design spec.
target_protocol
¶
Use the auto-derived jags tree-sitter protocol.
| RETURNS | DESCRIPTION |
|---|---|
Protocol
|
The protocol of the target grammar. |
render
¶
render(ir: IRProgram) -> Schema
Walk the IR and emit a complete JAGS module.
Overrides the base IR walk because JAGS programs need a
model { ... } wrapper around every body statement; the
wrapper is a single model_block vertex whose children are
the statements emitted by _dispatch_jags_node.
| PARAMETER | DESCRIPTION |
|---|---|
ir
|
The lowered program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Schema
|
The target program, in the target grammar's theory. |
Source code in src/quivers/transpile/renderers/jags.py
declare
¶
declare(ctx: RenderContext, name: str, constraint: ConstraintSpec, plate: Plate, *, block: BlockKind) -> SchemaFragment
JAGS variables are declared implicitly by their first ~
or <- binding; data inputs ride on the host's external
.data file. This dispatch is a no-op for every block.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
block
|
Where the declaration lands in the target program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/jags.py
sample
¶
sample(ctx: RenderContext, name: str, family: str, args: tuple[IRArg, ...], arg_names: tuple[str, ...], constraint: ConstraintSpec, plate: Plate, observed: bool) -> SchemaFragment
Emit a per-batch-axis for (m_<axis> in 1:N_<axis>) { <lhs>
~ d<family>(args) } form.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
family
|
The distribution family's QVR name.
TYPE:
|
args
|
The family's arguments, in family order.
TYPE:
|
arg_names
|
The parameter name of each argument.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
observed
|
Whether the site is conditioned on data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/jags.py
marginalize
¶
marginalize(ctx: RenderContext, node: IRMarginalize) -> SchemaFragment
Lower an IRMarginalize
to the weighted sum over its latent's atoms.
QVR's marginalize denotes the integral over the latent of
the measure the scope carries, so the emitted program has to
score that integral and declare no latent site: a program that
draws the latent instead denotes a measure on the product of
the latent's support with the scope's, which differs from the
integral by an amount that moves with the data.
JAGS has no reduction over a parameterised family, but it has every piece the integral needs. The support is finite, so the sum
p(y_n) = sum_a w_a * f_a(y_n)
is an ordinary arithmetic expression once the atom count is
known, and the zeros trick adds its logarithm to the joint.
_emit_marginal_reduction
writes it.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
node
|
The marginalize block.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/jags.py
broadcast
¶
broadcast(ctx: RenderContext, value: IRArg, target_shape: tuple[int, ...]) -> SchemaFragment
Render a scalar-to-vector broadcast as JAGS' rep builtin.
JAGS has no scalar-to-vector broadcast operator, but its base
function library provides rep(x, times), which returns a
length-times vector filled with x. A scalar
concentration over a K-atom Dirichlet event axis thus
emits rep(<scalar>, K): a valid vector parent whose repeated
entries reproduce the symmetric-Dirichlet measure the QVR
[over=K] clause denotes.
Only a scalar reference or numeric literal can be repeated; a
rank other than one has no rep form and raises rather than
emitting an invalid parent.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
value
|
The argument broadcast.
TYPE:
|
target_shape
|
The shape broadcast to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/jags.py
NumPyroRenderer
¶
Bases: RendererBase
Render an IRProgram as NumPyro
Python source.
Subclasses RendererBase
and supplies the four required dispatch points
(declare, sample, marginalize, broadcast) plus a render
override that wraps the IR walk with the def model(...): ...
function header.
target_protocol
¶
Use the auto-derived Python tree-sitter protocol.
| RETURNS | DESCRIPTION |
|---|---|
Protocol
|
The protocol of the target grammar. |
Source code in src/quivers/transpile/renderers/numpyro.py
render
¶
render(ir: IRProgram) -> Schema
Walk the IR and emit a complete NumPyro module.
Overrides the base IR walk because NumPyro programs need a
function header that lists every
IRDataInput in the
signature (observed values get a =None default).
| PARAMETER | DESCRIPTION |
|---|---|
ir
|
The lowered program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Schema
|
The target program, in the target grammar's theory. |
Source code in src/quivers/transpile/renderers/numpyro.py
declare
¶
declare(ctx: RenderContext, name: str, constraint: ConstraintSpec, plate: Plate, *, block: BlockKind) -> SchemaFragment
No-op outside "function_body".
NumPyro declarations ARE sample calls; the function-header
parameter list is built up front by render from
IRDataInput entries.
Function-body declarations land at the
sample
dispatch point when the IR walker reaches the binding step.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
block
|
Where the declaration lands in the target program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/numpyro.py
sample
¶
sample(ctx: RenderContext, name: str, family: str, args: tuple[IRArg, ...], arg_names: tuple[str, ...], constraint: ConstraintSpec, plate: Plate, observed: bool) -> SchemaFragment
Emit a numpyro.sample call inside the surrounding plate
stack.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
family
|
The distribution family's QVR name.
TYPE:
|
args
|
The family's arguments, in family order.
TYPE:
|
arg_names
|
The parameter name of each argument.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
observed
|
Whether the site is conditioned on data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/numpyro.py
marginalize
¶
marginalize(ctx: RenderContext, node: IRMarginalize) -> SchemaFragment
Integrate an IRMarginalize
latent out, adding the reduced density to the model's
log-density with numpyro.factor.
The block emits one scored copy of the scope per atom of the latent's finite support, then reduces across atoms:
gated_rate = 0.0 * rate
__marg_z_0 = numpyro.distributions.Poisson(gated_rate).log_prob(y)
gated_rate = 1.0 * rate
__marg_z_1 = numpyro.distributions.Poisson(gated_rate).log_prob(y)
__marg_z_w = jnp.stack([jnp.log1p(-pi_z), jnp.log(pi_z)], axis=-1)
__marg_z = jnp.stack([__marg_z_0, __marg_z_1], axis=-1)
numpyro.factor(
"z", jnp.sum(jsp.logsumexp(__marg_z_w + __marg_z, axis=-1))
)
Each atom's deterministic bindings are re-emitted under their own names immediately before that atom is scored, so the scoring call reads the values that atom pins. No site is declared for the latent: the atoms replace it, and the emitted program denotes the same measure the QVR reference integrates.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
node
|
The marginalize block.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/numpyro.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | |
broadcast
¶
broadcast(ctx: RenderContext, value: IRArg, target_shape: tuple[int, ...]) -> SchemaFragment
Emit jnp.full((K,), value) for 1D / jnp.full((R, C),
value) for 2D.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
value
|
The argument broadcast.
TYPE:
|
target_shape
|
The shape broadcast to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/numpyro.py
PyMCRenderer
¶
Bases: RendererBase
Render an IRProgram to a
PyMC build_model function under the python tree-sitter grammar.
The output has the shape:
def build_model(<inputs>=None):
with pymc.Model(coords={...}) as model:
theta = pymc.Dirichlet("theta", a=..., dims=(...))
phi = pymc.Dirichlet("phi", a=..., dims=(...))
pymc.Categorical("w", p=phi[...], observed=w, dims=(...))
return model
target_protocol
¶
Return the panproto protocol of the target grammar.
| RETURNS | DESCRIPTION |
|---|---|
Protocol
|
The protocol of the target grammar. |
render
¶
render(ir: IRProgram) -> Schema
Render an IRProgram to a
PyMC schema. Subclasses normally call
render_with_tables
when morphism / let tables are available.
| PARAMETER | DESCRIPTION |
|---|---|
ir
|
The lowered program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Schema
|
The target program, in the target grammar's theory. |
Source code in src/quivers/transpile/renderers/pymc.py
render_with_tables
¶
render_with_tables(ir: IRProgram, *, morphisms: dict[str, MorphismDecl], lets: dict[str, Expr]) -> Schema
Same as render but pre-populates ctx.morphisms / ctx.defines
so IRArgFamilyRef
rendering can read the referenced morphism's init_family
clause.
| PARAMETER | DESCRIPTION |
|---|---|
ir
|
The lowered program.
TYPE:
|
morphisms
|
The module's morphism declarations, by name.
TYPE:
|
lets
|
The module's define expressions, by name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Schema
|
The target program, in the target grammar's theory. |
Source code in src/quivers/transpile/renderers/pymc.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
declare
¶
declare(ctx: RenderContext, name: str, constraint: ConstraintSpec, plate: Plate, *, block: BlockKind) -> SchemaFragment
PyMC declarations ARE the constructor calls (emitted in
sample). declare is thus a no-op; the caller's emit
handles both declaration and assignment in one node.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
block
|
Where the declaration lands in the target program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/pymc.py
marginalize
¶
marginalize(ctx: RenderContext, node: IRMarginalize) -> SchemaFragment
No-op at the protocol dispatch point: the renderer drives
the enumeration through _emit_marginalize, which needs the
PyMC-specific with-body context.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
node
|
The marginalize block.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/pymc.py
broadcast
¶
broadcast(ctx: RenderContext, value: IRArg, target_shape: tuple[int, ...]) -> SchemaFragment
Emit np.full((K,), <value>) for 1D, np.full((R, C),
<value>) for 2D target shapes.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
value
|
The argument broadcast.
TYPE:
|
target_shape
|
The shape broadcast to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/pymc.py
sample
¶
sample(ctx: RenderContext, name: str, family: str, args: tuple[IRArg, ...], arg_names: tuple[str, ...], constraint: ConstraintSpec, plate: Plate, observed: bool) -> SchemaFragment
Renderer protocol entry: PyMC's emit is structurally
joined with declare (the constructor call IS the declaration).
Not called by the PyMC walker (which calls _emit_sample
directly); kept here so external callers using the abstract
protocol can drive the renderer.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
family
|
The distribution family's QVR name.
TYPE:
|
args
|
The family's arguments, in family order.
TYPE:
|
arg_names
|
The parameter name of each argument.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
observed
|
Whether the site is conditioned on data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/pymc.py
PyroRenderer
¶
Bases: RendererBase
Render an IRProgram to a
Python source panproto.Schema under the
Pyro PPL idiom.
target_protocol
¶
Return the panproto protocol of the target grammar.
| RETURNS | DESCRIPTION |
|---|---|
Protocol
|
The protocol of the target grammar. |
render
¶
render(ir: IRProgram) -> Schema
Walk the IR and emit a Pyro def model(...): ... function.
Overrides the inherited walk so the function header (with
<observed>=None default parameters drawn from the IR's
IRObserve nodes) and the body block are constructed up
front; the inherited dispatch then routes each node into
the body.
| PARAMETER | DESCRIPTION |
|---|---|
ir
|
The lowered program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Schema
|
The target program, in the target grammar's theory. |
Source code in src/quivers/transpile/renderers/pyro.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
declare
¶
declare(ctx: RenderContext, name: str, constraint, plate: Plate, *, block: BlockKind) -> SchemaFragment
No-op outside "function_body": Pyro picks data inputs up
in the model function signature, not via a declaration block.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
constraint
|
The variable's support.
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
block
|
Where the declaration lands in the target program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/pyro.py
sample
¶
sample(ctx: RenderContext, name: str, family: str, args: tuple[IRArg, ...], arg_names: tuple[str, ...], constraint, plate: Plate, observed: bool) -> SchemaFragment
Build the pyro.sample(...) call; the caller threads the
return vertex into the enclosing with / block.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
family
|
The distribution family's QVR name.
TYPE:
|
args
|
The family's arguments, in family order.
TYPE:
|
arg_names
|
The parameter name of each argument.
TYPE:
|
constraint
|
The variable's support.
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
observed
|
Whether the site is conditioned on data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/pyro.py
marginalize
¶
marginalize(ctx: RenderContext, node: IRMarginalize) -> SchemaFragment
Emit nothing: Pyro integrates latents from its own walk.
render routes
each marginalize block through the Pyro walk, which carries the
function-body state this dispatch point does not receive, so the
shared dispatch point contributes no fragment of its own.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
node
|
The marginalize block.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The empty fragment. |
Source code in src/quivers/transpile/renderers/pyro.py
broadcast
¶
broadcast(ctx: RenderContext, value: IRArg, target_shape: tuple[int, ...]) -> SchemaFragment
Emit torch.full((K,), <value>) for rank-1, torch.full(
(R, C), <value>) for rank-2.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
value
|
The argument broadcast.
TYPE:
|
target_shape
|
The shape broadcast to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/pyro.py
StanRenderer
¶
StanRenderer(*, source_module: Module | None = None)
Bases: RendererBase
Render an IRProgram to a
Stan panproto.Schema.
Subclasses
RendererBase
and overrides the four dispatch points
(declare, sample, marginalize, broadcast) plus the two
list / matrix arg helpers per the spec.
Initialise the renderer.
| PARAMETER | DESCRIPTION |
|---|---|
source_module
|
Optional original
TYPE:
|
Source code in src/quivers/transpile/renderers/stan.py
target_protocol
¶
Return the panproto protocol of the target grammar.
| RETURNS | DESCRIPTION |
|---|---|
Protocol
|
The protocol of the target grammar. |
render
¶
render(ir: IRProgram) -> Schema
Walk the IR and emit a Stan schema.
Override of the base render so the program-level layout
(the program vertex with five child blocks) is built once
per call.
| PARAMETER | DESCRIPTION |
|---|---|
ir
|
The lowered program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Schema
|
The target program, in the target grammar's theory. |
Source code in src/quivers/transpile/renderers/stan.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | |
declare
¶
declare(ctx: RenderContext, name: str, constraint: ConstraintSpec, plate: Plate, *, block: BlockKind) -> SchemaFragment
Emit a declaration for name in block.
Dispatches purely on the support predicates of §2.2 of the
spec, threaded through
ConstraintSpec.to_constraint.
The table is the §5 Stan table.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
block
|
Where the declaration lands in the target program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/stan.py
sample
¶
sample(ctx: RenderContext, name: str, family: str, args: tuple[IRArg, ...], arg_names: tuple[str, ...], constraint: ConstraintSpec, plate: Plate, observed: bool) -> SchemaFragment
Emit a target += <family>_lpdf(...) statement for a
sample / observe step.
Stan's ~ sampling notation drops every term that does not
depend on a parameter, so model.log_prob(jacobian=False)
on a ~-built program omits data-only contributions and the
omitted amount moves with the data. The explicit
target += <family>_lpdf(<lhs> | <args>) form keeps every
normalizing constant, which is what the constant-spread
equivalence contract requires: the emitted program computes
the joint exactly, not up to a data-dependent offset.
Wraps the increment in nested for (m_<axis> in 1:<size>)
loops for each batch dim. Indexes the LHS and every arg whose
ref-name sits on the plate.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
family
|
The distribution family's QVR name.
TYPE:
|
args
|
The family's arguments, in family order.
TYPE:
|
arg_names
|
The parameter name of each argument.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
observed
|
Whether the site is conditioned on data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/stan.py
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 | |
marginalize
¶
marginalize(ctx: RenderContext, node: IRMarginalize) -> SchemaFragment
Emit a marginalized latent.
Families with declared finite marginal support are enumerated with a
log_sum_exp reduction. This includes relaxation families whose
marginal heads declare discrete atoms. Families without finite support
become constrained Stan parameters: the renderer adds their prior
density and emits the scope with that parameter in context. Stan then
samples the resulting joint model.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
node
|
The marginalize block.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/stan.py
1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 | |
broadcast
¶
broadcast(ctx: RenderContext, value: IRArg, target_shape: tuple[int, ...]) -> SchemaFragment
Emit a Stan broadcast call:
rep_vector(<value>, K) for 1D, rep_matrix(<value>, R, C)
for 2D.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
value
|
The argument broadcast.
TYPE:
|
target_shape
|
The shape broadcast to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/stan.py
TuringRenderer
¶
Bases: RendererBase
Render an IRProgram as a
Turing.jl model.
Overrides render
to wrap the IR-walk with the @model function model(...) ... end
prologue / epilogue Turing.jl requires. The per-node dispatches
(declare, sample, marginalize, broadcast) accumulate Julia
schema vertices into a single function body block.
Construct a renderer.
morphisms and lets are the resolved tables from the surface
module; the renderer consults morphisms when an
IRArgFamilyRef needs
the referenced morphism's ~ Family(...) init clause. Both
default to empty so callers driving a synthetic
IRProgram (tests) can
instantiate the renderer with no surface context.
| PARAMETER | DESCRIPTION |
|---|---|
morphisms
|
The module's morphism declarations, by name.
TYPE:
|
lets
|
The module's define expressions, by name.
TYPE:
|
Source code in src/quivers/transpile/renderers/turing.py
target_protocol
¶
Return the panproto protocol of the target grammar.
| RETURNS | DESCRIPTION |
|---|---|
Protocol
|
The protocol of the target grammar. |
Source code in src/quivers/transpile/renderers/turing.py
render
¶
render(ir: IRProgram) -> Schema
Render a program to the target's panproto schema.
| PARAMETER | DESCRIPTION |
|---|---|
ir
|
The lowered program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Schema
|
The target program, in the target grammar's theory. |
Source code in src/quivers/transpile/renderers/turing.py
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
declare
¶
declare(ctx: RenderContext, name: str, constraint: ConstraintSpec, plate: Plate, *, block: BlockKind) -> SchemaFragment
No-op: in Turing.jl, declarations are the ~ statements
themselves. The function signature is populated from the
IRDataInput list in render.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
block
|
Where the declaration lands in the target program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/turing.py
sample
¶
sample(ctx: RenderContext, name: str, family: str, args: tuple[IRArg, ...], arg_names: tuple[str, ...], constraint: ConstraintSpec, plate: Plate, observed: bool, *, via: str | None = None) -> SchemaFragment
Emit one ~ / .~ statement for a sample or observe step.
Plate handling:
* batch_dims=() and no via: plain name ~ Family(args).
* batch_dims=(B,) and no arg references a batch-plated name
via index: name ~ filldist(Family(args), B).
* Otherwise (index-dependent args or a via fibration):
broadcast-dot form name .~ Family.(idx_args), or the
arraydist([Family(args[i]) for i in 1:B]) fallback when no
via is present.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
family
|
The distribution family's QVR name.
TYPE:
|
args
|
The family's arguments, in family order.
TYPE:
|
arg_names
|
The parameter name of each argument.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
observed
|
Whether the site is conditioned on data.
TYPE:
|
via
|
The fibration an observe gathers its rows through, or
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/turing.py
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 | |
marginalize
¶
marginalize(ctx: RenderContext, node: IRMarginalize) -> SchemaFragment
Integrate an IRMarginalize
latent out, adding the reduced density to the model's
log-joint with Turing.@addlogprob!.
One scored copy of the scope per atom of the latent's finite support, then an elementwise reduction across atoms:
__marg_state_0 = logpdf.(Categorical(eachrow(emission_rows)[1]), obs)
...
__marg_state_w = log.(initial_row)
__marg_state_t_0 = __marg_state_w[1] .+ __marg_state_0
...
__marg_state_m = max.(__marg_state_t_0, ..., __marg_state_t_7)
__marg_state = __marg_state_m .+ log.(
exp.(__marg_state_t_0 .- __marg_state_m) + ...
)
@addlogprob! sum(__marg_state)
The max-shifted form is the numerically stable logsumexp
written in Base, so the emitted model needs no import beyond
what using Turing already brings into scope. No site is
declared for the latent: the atoms replace it, and the emitted
program denotes the same measure the QVR reference integrates.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
node
|
The marginalize block.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/turing.py
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 | |
broadcast
¶
broadcast(ctx: RenderContext, value: IRArg, target_shape: tuple[int, ...]) -> SchemaFragment
Emit the target's broadcast of value to target_shape.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
value
|
The argument broadcast.
TYPE:
|
target_shape
|
The shape broadcast to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/turing.py
WebPPLRenderer
¶
WebPPLRenderer(*, source_module: Module | None = None)
Bases: RendererBase
Render an IRProgram to a
WebPPL panproto.Schema.
Subclasses
RendererBase
and overrides the four dispatch points
(declare, sample, marginalize, broadcast) plus the two
list / matrix arg helpers per the spec.
Initialise the renderer.
| PARAMETER | DESCRIPTION |
|---|---|
source_module
|
Optional original
TYPE:
|
Source code in src/quivers/transpile/renderers/webppl.py
target_protocol
¶
Return the panproto protocol of the target grammar.
| RETURNS | DESCRIPTION |
|---|---|
Protocol
|
The protocol of the target grammar. |
Source code in src/quivers/transpile/renderers/webppl.py
render
¶
render(ir: IRProgram) -> Schema
Walk the IR and emit a WebPPL schema.
Override of the base render so the program-level shape
(a single var model = function(<inputs>) { ... };
declaration) is built once per call.
| PARAMETER | DESCRIPTION |
|---|---|
ir
|
The lowered program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Schema
|
The target program, in the target grammar's theory. |
Source code in src/quivers/transpile/renderers/webppl.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
declare
¶
declare(ctx: RenderContext, name: str, constraint: ConstraintSpec, plate: Plate, *, block: BlockKind) -> SchemaFragment
No-op: WebPPL's var <name> = sample(...); binding is
emitted by sample directly. The declaration table threads
the name's binding plate / support into the renderer's
bookkeeping so later sample steps can index into the name
correctly.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
block
|
Where the declaration lands in the target program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/webppl.py
sample
¶
sample(ctx: RenderContext, name: str, family: str, args: tuple[IRArg, ...], arg_names: tuple[str, ...], constraint: ConstraintSpec, plate: Plate, observed: bool) -> SchemaFragment
Emit a sample / observe statement for a sample / observe
step.
Wraps the call in repeat(B, function() { ... }) per batch
dim when no arg uses the per-element index; uses
mapIndexed(function(m, _) { ... }, repeat(B, function() {
return 0; })) when an arg refers to a name whose binding
plate aligns with the surrounding plate's batch dims.
For an observed step the emit shape is
mapIndexed(function(n, <obs>_n) { observe(<dist>, <obs>_n);
}, <obs>); when batched; the unbatched case emits a bare
observe(<dist>, <obs>); statement.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
name
|
The variable's name.
TYPE:
|
family
|
The distribution family's QVR name.
TYPE:
|
args
|
The family's arguments, in family order.
TYPE:
|
arg_names
|
The parameter name of each argument.
TYPE:
|
constraint
|
The variable's support.
TYPE:
|
plate
|
The variable's event and batch dimensions.
TYPE:
|
observed
|
Whether the site is conditioned on data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/webppl.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 | |
marginalize
¶
marginalize(ctx: RenderContext, node: IRMarginalize) -> SchemaFragment
Integrate an
IRMarginalize latent
out, adding the reduced density to the program's log-density
with WebPPL's factor.
One scored copy of the scope per atom of the latent's finite support, then a reduction across atoms:
var __marg_z_atom_0 = function () {
var gated_rate = _qvr_bcast("*", 0, rate);
return mapIndexed(function (n, y_n) {
return (Poisson({mu:gated_rate[n]})).score(y_n);
}, y);
};
var __marg_z_0 = __marg_z_atom_0();
...
var __marg_z_t_0 = _qvr_bcast("+", __marg_z_w_0, __marg_z_0);
...
var __marg_z = _qvr_logsumexp([__marg_z_t_0, __marg_z_t_1]);
factor(_qvr_total(__marg_z));
Each atom's deterministic bindings live inside that atom's own
function, which is what gives them a scope: WebPPL's
single-assignment subset rejects a second var gated_rate in
the same block. No site is declared for the latent: the atoms
replace it, and the emitted program denotes the same measure
the QVR reference integrates.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
node
|
The marginalize block.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/webppl.py
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 | |
broadcast
¶
broadcast(ctx: RenderContext, value: IRArg, target_shape: tuple[int, ...]) -> SchemaFragment
Emit a WebPPL broadcast call:
repeat(K, function() { return <value>; }) for 1D, nested
for higher rank.
Rank-0 returns the value unchanged. The renderer raises with a precise kind tag for rank > 2 because the canonical WebPPL Dirichlet / MVN call shapes only exercise rank-1 and rank-2 broadcast positions.
| PARAMETER | DESCRIPTION |
|---|---|
ctx
|
The render call's mutable state.
TYPE:
|
value
|
The argument broadcast.
TYPE:
|
target_shape
|
The shape broadcast to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaFragment
|
The emitted vertex id, or |
Source code in src/quivers/transpile/renderers/webppl.py
assert_no_dangling_refs
¶
assert_no_dangling_refs(ir: IRProgram) -> None
Raise if the IR contains an IRArgRef whose name is not bound
by a declaration, a previous step, or an input.
Source code in src/quivers/transpile/renderers/_base.py
assert_no_dropped_param_map
¶
assert_no_dropped_param_map(ir: IRProgram, target: str) -> None
Reject scalar family arguments whose reference width cannot match the site.
A declared conditional kernel may carry a learned parameter map from its domain to its family heads. Those learned weights do not occur in emitted source or sample sites. The IR must thus not reduce such a map to a bare reference with a different static width.
Scalar arguments may broadcast from width one. Indexed references, mixture arguments, and values gathered through an observation fibration are excluded because their effective widths follow other rules. Families whose argument ranks are unavailable are also skipped.
Source code in src/quivers/transpile/renderers/_base.py
assert_no_lists
¶
assert_no_lists(ir: IRProgram) -> None
Raise if the IR contains an IRArgList /
IRArgMatrix in a position a
backend does not support.
The default implementation is permissive: list / matrix args are
legal in the IR; only renderers that lack a native list / matrix
literal raise. Per-renderer assert_no_lists overrides plug in
the per-target rejection rule.