Plan¶
Lower derives a program's target plan from its checked Quivers Indexed Effect Core (QIEC) module, and every target renders from
that plan (lowering). The plan collects
the declarations and dependencies a target needs, checks support before any source is emitted, and
names the operation responsible when a target refuses a model.
plan
¶
The target plan of a program, derived from its checked kernel module.
A program is one named computation of the checked
QiecModule, performing Random.sample and
Score.add on the module's canonical instances, binding pure values,
and calling its marginalization helpers. A probabilistic-programming
target has statements for exactly those things: a draw, an observation,
a deterministic binding, a log-density increment, and an integration
scope. The plan pass reads the computation and recognizes each of them,
producing the IRProgram body the
renderers consume: one IRSample per
Random.sample request, one IRObserve
per scored density at an observation, one
IRDeterministic per pure binding,
one IRScore per other weight, and one
IRMarginalize per helper call whose
answer is scored. The plan's inputs are the entry point's parameters,
typed by the module and constrained by how the body reads them.
The pass reads the source declarations only for what the module does not carry: object cardinalities and bounds, the morphism a site draws through (which fixes a class-index draw's alphabet and a structured family's wire form), and the option blocks of structured families. A construct the target vocabulary has no statement for, a call of a deduction or a recurrence, is reported with the kind of the request or call the plan cannot place, so a renderer never receives a body with a hole in it.
TARGET_NAME_SEPARATOR
module-attribute
¶
TARGET_NAME_SEPARATOR = TARGET_DRAW_SEPARATOR
How a target spells the $ of a name a program draw renamed.
theta$z is the site of the local z of a program drawn under
theta; no target language admits $ in an identifier, so targets
spell it theta____z.
Lower
¶
Bases: Mapping[Module, IRProgram]
Map a parsed Module to an
IRProgram.
The lowering elaborates the module through the QIEC route first; the program's plan is then derived from its checked computation. A module without a program lowers to its checked computations alone. Stateless: every table is derived from the input module on each call.
forward
¶
Lower a parsed module to the transpile IR.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The parsed module, with composite lets already expanded for the target.
TYPE:
|
target
|
The transpile target the lowering serves, named in the diagnostics the QIEC boundary raises.
TYPE:
|
optimize
|
Whether to derive the target-oriented probabilistic plan. When false, retain only the checked QIEC graph so reference execution can test semantics before target-plan recognition or rewriting.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IRProgram
|
The lowered program with its checked kernel module. |
| RAISES | DESCRIPTION |
|---|---|
UnsupportedConstruct
|
If the module has no program and no QIEC surface, uses a construct the elaboration does not admit, or falls in a gap of the elaboration. |
QiecDiagnosticError
|
If a QIEC declaration is rejected. |
Source code in src/quivers/transpile/plan.py
checked_module
¶
checked_module(module: Module, *, target: str, require_target_runtime: bool = True) -> QiecModule | None
Elaborate and check a module at the lowering boundary.
A source with nothing to elaborate takes no checking path. Otherwise
the elaboration constructs the complete
:class:~quivers.qiec.QiecModule and validate_module independently
checks its nominal declarations, static scopes, effect rows, and every
computation type. Capability analysis is deliberately separate: the
lowering always retains the complete typed module, and a selected
renderer uses
:func:quivers.transpile.qiec_ir.analyze_qiec_capabilities to determine
whether it can preserve each feature.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The parsed module.
TYPE:
|
target
|
The transpile target, for diagnostics.
TYPE:
|
require_target_runtime
|
Whether to reject host-only runtime capabilities before deriving a target plan. Disable this only when retaining the checked QIEC graph for reference execution without a target-oriented plan.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QiecModule | None
|
The checked module, or |
| RAISES | DESCRIPTION |
|---|---|
UnsupportedConstruct
|
If a program uses a form the elaboration does not admit; the construct is reported the way a renderer reports one it cannot emit. |
QiecDiagnosticError
|
If a QIEC declaration is rejected. |
Source code in src/quivers/transpile/plan.py
3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 | |
target_name
¶
A source name as every target spells it.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name, as the reference machine labels it.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The injective spelling |
Source code in src/quivers/transpile/plan.py
program_plan
¶
program_plan(module: QiecModule, source: Module, program: ProgramDecl, target: str) -> IRProgram
Derive a program's plan from its checked module.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module.
TYPE:
|
source
|
The expanded source module.
TYPE:
|
program
|
The program.
TYPE:
|
target
|
The transpile target.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IRProgram
|
The plan. |
Source code in src/quivers/transpile/plan.py
checked_program_plan
¶
checked_program_plan(module: QiecModule, source: Module, target: str) -> IRProgram | None
Derive a target plan from an existing checked module.
This is the target-planning half of Lower.forward
for callers such as the CLI and language server that already hold the checked
QIEC module. Reusing it avoids parsing and elaborating the source a second time.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module.
TYPE:
|
source
|
The parsed source module.
TYPE:
|
target
|
The transpile target.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IRProgram | None
|
The target plan, or |
| RAISES | DESCRIPTION |
|---|---|
UnsupportedConstruct
|
If the program falls in an elaboration gap or its checked computation cannot be represented by the target plan. |