Plan¶
Deriving a program's target plan from its checked kernel module, and the lowering entry point every target renders from.
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
¶
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, and no target language admits $ in an identifier.
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
2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 | |
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
2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 | |
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 name with each |
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. |