Batched evaluation¶
PotentialFn.log_density_batch
scores a program at many positions in
one pass. Whether each step can be
evaluated this way is declared, by the
step for a Python
callable and by the
morphism for a
distribution. batching_obstacles lists the steps
of a program that declare nothing, or whose terms would differ between positions, and
UnbatchableProgramError carries them.
batching
¶
Which programs can be scored at many positions in one pass.
A program's log joint is evaluated at B positions by running its
steps once, on values that carry the position axis
(quivers._positions). Whether a step can run this way is declared, by
the step for a Python callable the program cannot inspect and by the
morphism for a distribution, and is never found out by running it.
batching_obstacles reads the declarations of a program and of the
programs it calls and scans, and the batch methods of
PotentialFn raise
UnbatchableProgramError when any of them stands in the way.
PositionLayoutError
¶
Bases: ValueError
A value of a batched callable does not lead with the position axis.
A callable declared batched keeps the position axis leading every
value that depends on the position. A result that does not, or a
validator that refuses a value whose leading axis is not the position
axis, cannot be read per position.
BatchingObstacle
didactic-model
¶
Bases: ValueModel
A step that cannot be evaluated at many positions, and why.
| ATTRIBUTE | DESCRIPTION |
|---|---|
step |
The step: its kind and the names it binds.
TYPE:
|
reason |
Why it cannot.
TYPE:
|
UnbatchableProgramError
¶
UnbatchableProgramError(obstacles: tuple[BatchingObstacle, ...])
Bases: ValueError
A program that cannot be scored at many positions in one pass.
| PARAMETER | DESCRIPTION |
|---|---|
obstacles
|
The steps standing in the way, in program order, and why each does.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
obstacles |
The same.
TYPE:
|
Source code in src/quivers/effects/batching.py
batching_obstacles
¶
batching_obstacles(program: MonadicProgram, latents: Collection[str], given: Collection[str]) -> tuple[BatchingObstacle, ...]
The steps of a program that cannot be evaluated at many positions.
| PARAMETER | DESCRIPTION |
|---|---|
program
|
The program.
TYPE:
|
latents
|
The sites whose values the position gives.
TYPE:
|
given
|
The sites and host data whose values every position shares.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[BatchingObstacle, ...]
|
One entry per step, in the order the program runs them, those of the programs it calls and scans included. Empty for a program that can be scored at many positions. |
Source code in src/quivers/effects/batching.py
inner_names
¶
inner_names(program: MonadicProgram) -> frozenset[str]
The sites of a program another one runs.
| PARAMETER | DESCRIPTION |
|---|---|
program
|
The called or scanned program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
frozenset[str]
|
The names its draws bind. A site of it has a label of its own in the run, so whether it is given a value is checked when the run reaches it. |
Source code in src/quivers/effects/batching.py
draws_at_random
¶
draws_at_random(program: MonadicProgram) -> bool
Whether a program draws at random even when every site has a value.
| PARAMETER | DESCRIPTION |
|---|---|
program
|
The program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|