Skip to content

Programs

A ProgramEntry records how an elaborated computation is exposed as a program: the roles of its parameters, its sites, and its return names (program declaration), so a caller need not reconstruct them from source (public boundary). The body itself is the well-typed computation.

programs

Typed entry-point metadata for programs elaborated into computations.

A program declaration elaborates to an ordinary named computation whose parameters are the program's data, observations, and index maps, and whose body performs the canonical Random.sample and Score.add requests. What the computation alone does not say is which parameter plays which role, which locals are the program's sites, and what the return tuple's labels are. The records here carry that, beside the computation, so a runtime, a transpiler, or a tool can drive the entry point without re-reading the source.

ParameterRole

ParameterRole = Literal['domain', 'scalar', 'data', 'observation', 'index_map', 'weight', 'bias', 'table', 'kernel-input']

How a program parameter is supplied.

domain parameters carry the value the program is applied to, one per real factor of its domain; scalar ones are its declared parameters; data ones are free names its steps read; observation ones are the values observe steps score; index_map ones map observation rows to groups; weight and bias are the numbers of a declared morphism's affine parameter map and table those of a morphism over a finite domain, one row per element; kernel-input holds a kernel's input locations.

SiteKind

SiteKind = Literal['sample', 'observe', 'marginal']

What a program step does at its site.

ProgramParameter didactic-model

ProgramParameter(*, name: str, role: ParameterRole = field(opaque=True, extras=OPAQUE_BY_VALUE), type: TypeExpr = field(opaque=True, extras=OPAQUE_BY_VALUE), axes: tuple[str, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), per_row: bool = False, constraint: Literal['nonnegative'] | None = None, tag: Literal['program_parameter'] = 'program_parameter')

Bases: QiecModel

One parameter of an elaborated program.

PARAMETER DESCRIPTION
name

The parameter's name, which is the computation parameter's.

TYPE: str

role

How the parameter is supplied.

TYPE: ParameterRole DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

type

Its type.

TYPE: TypeExpr DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

axes

The name of each dimension of a tensor-typed parameter, the object or extent it ranges over; empty for a scalar.

TYPE: tuple[str, ...] DEFAULT: field(default=(), opaque=True, extras=OPAQUE_BY_VALUE)

per_row

Whether the parameter fills a family parameter of a plated draw directly, so that its leading axis is the draw's plate: a value without that axis is one value shared by every row, which a run broadcasts across the plate.

TYPE: bool DEFAULT: False

constraint

An additional checked value restriction. "nonnegative" retains a runtime Nat parameter's restriction after lowering its arithmetic carrier to Int; None adds no restriction.

TYPE: Literal['nonnegative'] | None DEFAULT: None

tag

The serialization discriminator; always "program_parameter".

TYPE: Literal['program_parameter'] DEFAULT: 'program_parameter'

ProgramSite didactic-model

ProgramSite(*, name: str, kind: SiteKind = field(opaque=True, extras=OPAQUE_BY_VALUE), family: str, batch: tuple[PlateAxis, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), event: tuple[PlateAxis, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), tag: Literal['program_site'] = 'program_site')

Bases: QiecModel

One probabilistic step of an elaborated program.

PARAMETER DESCRIPTION
name

The site's label, the name the step binds or scores.

TYPE: str

kind

Whether the step samples, observes, or marginalizes.

TYPE: SiteKind DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

family

The distribution family the step draws from.

TYPE: str

batch

The plate's batch axes.

TYPE: tuple[PlateAxis, ...] DEFAULT: field(default=(), opaque=True, extras=OPAQUE_BY_VALUE)

event

The plate's event axes.

TYPE: tuple[PlateAxis, ...] DEFAULT: field(default=(), opaque=True, extras=OPAQUE_BY_VALUE)

tag

The serialization discriminator; always "program_site".

TYPE: Literal['program_site'] DEFAULT: 'program_site'

ProgramEntry didactic-model

ProgramEntry(*, name: str, computation: ComputationId = field(opaque=True, extras=OPAQUE_BY_VALUE), parameters: tuple[ProgramParameter, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), return_names: tuple[str, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), return_labels: tuple[str, ...] | None = field(opaque=True, extras=OPAQUE_BY_VALUE), sites: tuple[ProgramSite, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), random_instance: EffectInstanceId = field(opaque=True, extras=OPAQUE_BY_VALUE), score_instance: EffectInstanceId = field(opaque=True, extras=OPAQUE_BY_VALUE), telescope: Telescope = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), tag: Literal['program_entry'] = 'program_entry')

Bases: QiecModel

The typed entry point a program declaration elaborates to.

PARAMETER DESCRIPTION
name

The program's source name.

TYPE: str

computation

The identity of the named computation holding its body.

TYPE: ComputationId DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

parameters

The computation's parameters with their roles, in order.

TYPE: tuple[ProgramParameter, ...] DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

return_names

The names the program returns, in order.

TYPE: tuple[str, ...] DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

return_labels

The labels of a labelled return tuple, or None.

TYPE: tuple[str, ...] | None DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

sites

The program's probabilistic steps, in source order, those of marginalization scopes included.

TYPE: tuple[ProgramSite, ...] DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

random_instance

The lexical Random instance the program's samples address.

TYPE: EffectInstanceId DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

score_instance

The lexical Score instance the program's scores address.

TYPE: EffectInstanceId DEFAULT: field(opaque=True, extras=OPAQUE_BY_VALUE)

telescope

The static binders the computation takes: one index binder per extent of an input the program's steps leave open, which a run reads off the data it is given.

TYPE: Telescope DEFAULT: field(default=(), opaque=True, extras=OPAQUE_BY_VALUE)

tag

The serialization discriminator; always "program_entry".

TYPE: Literal['program_entry'] DEFAULT: 'program_entry'