Program encoding¶
The kernel encoding of a MonadicProgram.
program_module
¶
The kernel encoding of a MonadicProgram.
A MonadicProgram is a sequence of host steps: a draw from a torch
morphism at an input built from earlier bindings, a deterministic binding
computed by a host closure, or a score contributed by one. The kernel has
no term for a host function, and does not need one: each step's host part
is an instance of the prelude's Compute interface, performed on the
values it reads (the arguments of a draw, the names a closure declares,
or every value bound so far when it declares none), and each draw is the
canonical Random.sample request on the sampleable the host part
returns.
The computation this module builds therefore makes the program's data flow
and effect structure explicit while every tensor operation stays in the
host, behind a handler a runtime provider installs. The user's effect
handlers are lexical handlers of the same random and score
instances, so conditioning, intervention, replay, reweighting, and tracing
compose by the kernel's own rules.
HostStep
dataclass
¶
HostStep(instance: EffectInstanceId, effect: EffectRef, kind: str, spec: Step | None, environment: tuple[str, ...], answer_type: TypeExpr, site: str | None = None)
One host part of the program, as the runtime provider serves it.
| PARAMETER | DESCRIPTION |
|---|---|
instance
|
The
TYPE:
|
effect
|
The applied
TYPE:
|
kind
|
TYPE:
|
spec
|
The program's step record, or
TYPE:
|
environment
|
The names of the locals the step reads, in the order the environment tuple carries them.
TYPE:
|
answer_type
|
The type the host part returns.
TYPE:
|
site
|
The site label of a draw step, else
TYPE:
|
ProgramKernel
dataclass
¶
ProgramKernel(module: QiecModule, program: MonadicProgram, steps: tuple[HostStep, ...], sites: tuple[str, ...], site_types: dict[str, TypeExpr], data: tuple[str, ...], random: NamedEffectInstance, score: NamedEffectInstance, param: NamedEffectInstance, result_type: TypeExpr, locals: dict[str, Local] = dict())
A program's computation with the record the runtime needs to serve it.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The kernel module: the interfaces, the instances, and the entry computation, without handlers; a run adds its own.
TYPE:
|
program
|
The program encoded.
TYPE:
|
steps
|
The host steps, in body order.
TYPE:
|
sites
|
The site label of every draw, in order.
TYPE:
|
site_types
|
The value type of each site, by label.
TYPE:
|
data
|
The names of the host data inputs after the program's input, in parameter order.
TYPE:
|
random
|
The canonical
TYPE:
|
score
|
The canonical
TYPE:
|
param
|
The canonical
TYPE:
|
result_type
|
The entry computation's result type.
TYPE:
|
space_type
¶
space_type(space: SetObject | ContinuousSpace) -> TypeExpr
The kernel type of a value of a space.
| PARAMETER | DESCRIPTION |
|---|---|
space
|
A program's domain, codomain, or a morphism's codomain.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TypeExpr
|
|
Source code in src/quivers/effects/program_module.py
program_kernel
¶
program_kernel(program: MonadicProgram, data: Sequence[str] = ()) -> ProgramKernel
Encode a program as a kernel module.
| PARAMETER | DESCRIPTION |
|---|---|
program
|
The program.
TYPE:
|
data
|
The names of the host data inputs a run supplies beside the program's input, in parameter order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ProgramKernel
|
The module and the record the runtime serves it by. |