Program runtime¶
sample_program and run_program run a program's entry point
on the reference machine and return its
value and log joint density.
sample_program draws the sites it is not given, and run_program replays a value for every
site.
program_runtime
¶
Running program entry points on the reference machine.
An elaborated program is a named computation whose row names the module's
canonical random and score instances. Running it means choosing
handlers for the two: this module wraps the entry point in a scoring
replay of Random and an accumulating Score, so a program applied to
data and to a value for each of its sites yields the value it returns and
the log joint density the sites and observations accumulate. The wrapper is
an ordinary computation added to a copy of the module, so the kernel checks
it like any other before it runs.
ProgramRun
didactic-model
¶
ProgramRun(*, value: HeldValue = field(opaque=True, extras=OPAQUE_BY_IDENTITY), log_joint: Tensor = field(opaque=True, extras=OPAQUE_BY_IDENTITY), result: ExecutionResult = field(opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
What running a program on the reference machine produced.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The value the program returned, as the machine holds it.
TYPE:
|
log_joint
|
The log joint density: every replayed site's log density under its distribution plus every observation's and score's weight, a scalar tensor of the run's real dtype with the gradient of every tensor the run was given.
TYPE:
|
result
|
The underlying execution result, with its trace.
TYPE:
|
DeductionRun
didactic-model
¶
DeductionRun(*, weight: HeldValue = field(opaque=True, extras=OPAQUE_BY_IDENTITY), result: ExecutionResult = field(opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
The outcome of running a deduction on the reference machine.
| PARAMETER | DESCRIPTION |
|---|---|
weight
|
The inside weight of the goal in the deduction's semiring: a
log weight, a Boolean, or a count; or, when an iteration stopped
by a control and the caller asked for it, the last iterate held
as
TYPE:
|
result
|
The machine's full result, with its trace when one was recorded.
TYPE:
|
program_entry
¶
program_entry(module: QiecModule, name: str) -> ProgramEntry
Find a program's entry point in a module.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module.
TYPE:
|
name
|
The program's name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ProgramEntry
|
The entry. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the module has no program of that name. |
Source code in src/quivers/qiec/program_runtime.py
joint_module
¶
joint_module(module: QiecModule, name: str) -> tuple[QiecModule, str]
Extend a module with a computation scoring one program's log joint.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module holding the program.
TYPE:
|
name
|
The program's name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[QiecModule, str]
|
The extended module and the wrapper computation's name. The
wrapper takes the program's parameters, handles its |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the module has no such program. |
Source code in src/quivers/qiec/program_runtime.py
sample_module
¶
sample_module(module: QiecModule, name: str) -> tuple[QiecModule, str]
Extend a module with a computation running one program forward.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module holding the program.
TYPE:
|
name
|
The program's name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[QiecModule, str]
|
The extended module and the wrapper computation's name. The
wrapper takes the program's parameters, handles its |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the module has no such program. |
Source code in src/quivers/qiec/program_runtime.py
broadcast_shared_data
¶
broadcast_shared_data(entry: ProgramEntry, data: Mapping[str, object]) -> dict[str, object]
Spread each shared datum across the plate of the draw it fills.
A parameter that fills a family parameter of a plated draw directly
(ProgramParameter.per_row) is typed with the draw's plate as its
leading axis. A datum supplied without that axis is one value every
row shares, and is replicated once per row so that it inhabits the
checked type.
| PARAMETER | DESCRIPTION |
|---|---|
entry
|
The program's entry point.
TYPE:
|
data
|
The host value of each parameter, by name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, object]
|
The data, each shared datum replicated across its plate. |
static_arguments_for
¶
static_arguments_for(entry: ProgramEntry, data: Mapping[str, object], given: Sequence[StaticArgument] = ()) -> tuple[StaticArgument, ...]
Read a program's static extents off the data it is applied to.
| PARAMETER | DESCRIPTION |
|---|---|
entry
|
The program's entry point, whose telescope names the extents.
TYPE:
|
data
|
The host value of each parameter, by name.
TYPE:
|
given
|
Static arguments supplied explicitly, one per telescope binder in telescope order, or none. A template's object parameter is an extent no data fixes, so a run of the template supplies it; a binder the data does fix must agree with what is supplied.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[StaticArgument, ...]
|
One index literal per telescope binder, in telescope order: the length of the axis of the first parameter whose tensor type is shaped by the binder, else the supplied argument. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If a binder shapes no parameter and none is supplied, or the parameter is not given or has too few axes, or a supplied argument disagrees with the data, or the supplied arguments do not number the telescope. |
Source code in src/quivers/qiec/program_runtime.py
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 | |
run_program
¶
run_program(module: QiecModule, name: str, *, data: Mapping[str, object], sites: Mapping[str, object], parameters: Mapping[str, object] | None = None, static_arguments: Sequence[StaticArgument] = (), fuel: int | None = None, observer: TraceObserver | None = None, providers: tuple[RuntimeProvider, ...] = (), numbers: NumberDomain | None = None, distributions: DistributionBackend | None = None) -> ProgramRun
Run a program with every site replayed and score its log joint.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module holding the program.
TYPE:
|
name
|
The program's name.
TYPE:
|
data
|
A host value for each of the program's parameters, by name: its data, observations, index maps, and map numbers.
TYPE:
|
sites
|
A host value for each sampled site, by label, or by label and
occurrence as
TYPE:
|
parameters
|
The learned weights a deduction the program calls reads, by name; an absent weight reads as zero.
TYPE:
|
static_arguments
|
The program's static extents, one per telescope binder, for an extent no data fixes (a template's object parameter); empty when the data fix every extent.
TYPE:
|
fuel
|
A step budget for the run.
TYPE:
|
observer
|
A callback receiving every trace event as it is emitted.
TYPE:
|
providers
|
Additional typed providers used by computations the program calls.
TYPE:
|
numbers
|
The dtype and device of the run's numbers;
TYPE:
|
distributions
|
The backend that samples and scores the program's distributions;
the installed backend when
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ProgramRun
|
The returned value and the log joint. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the module has no such program, a parameter is not given, or an open extent cannot be read off the data. |
ExecutionFailure
|
If the run fails, a site is missing, or a value does not inhabit its type. |
Source code in src/quivers/qiec/program_runtime.py
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 | |
sample_program
¶
sample_program(module: QiecModule, name: str, *, data: Mapping[str, object], sites: Mapping[str, object] | None = None, parameters: Mapping[str, object] | None = None, static_arguments: Sequence[StaticArgument] = (), fuel: int | None = None, observer: TraceObserver | None = None, providers: tuple[RuntimeProvider, ...] = (), numbers: NumberDomain | None = None, distributions: DistributionBackend | None = None) -> ProgramRun
Run a program forward, drawing every site it is not given.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module holding the program.
TYPE:
|
name
|
The program's name.
TYPE:
|
data
|
A host value for each of the program's parameters, by name: its data, observations, index maps, and map numbers.
TYPE:
|
sites
|
A host value for each conditioned site, by label, or by label
and occurrence as
TYPE:
|
parameters
|
The learned weights a deduction the program calls reads, by name; an absent weight reads as zero.
TYPE:
|
static_arguments
|
The program's static extents, one per telescope binder, for an extent no data fixes; empty when the data fix every extent.
TYPE:
|
fuel
|
A step budget for the run.
TYPE:
|
observer
|
A callback receiving every trace event as it is emitted.
TYPE:
|
providers
|
Additional typed providers used by computations the program calls.
TYPE:
|
numbers
|
The dtype and device of the run's numbers;
TYPE:
|
distributions
|
The backend that samples and scores the program's distributions;
the installed backend when
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ProgramRun
|
The returned value and the log joint of the drawn and given sites together with the program's observations and scores. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the module has no such program, a parameter is not given, or an open extent cannot be read off the data. |
ExecutionFailure
|
If the run fails or a value does not inhabit its type. |
Source code in src/quivers/qiec/program_runtime.py
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 | |
passed_data_notes
¶
passed_data_notes(module: QiecModule, name: str) -> dict[str, str]
Where each datum a program passes straight to a computation goes.
A free name passed only as a call's argument takes the type of the parameter it fills; a call does not map the computation over the entries of a tensor. When a datum of another shape is supplied, the refusal says which call fixed the datum's type and what to write instead.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module holding the program.
TYPE:
|
name
|
The program's name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, str]
|
For each data parameter some call reads as a whole argument, a
located note naming the call, the parameter it fills, and the
remedy: declare the parameter as a tensor and |
Source code in src/quivers/qiec/program_runtime.py
foreign_handler_configuration
¶
foreign_handler_configuration(module: QiecModule, *, on_failure: FailurePolicy = REFUSE, reports: list[AccuracyReport] | None = None, reached: frozenset[HandlerId] | None = None) -> dict[str, object]
The runtime configuration of a module's foreign handlers.
Every foreign handler whose declaration states what it computes is served by that statement: the enumerations and collectors of marginalization blocks, and the searches, collectors and settlements of deductions. Nothing is read off a handler's name.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module.
TYPE:
|
on_failure
|
What a settlement does with a stop by a control: refuse, or record the report and resume with the value.
TYPE:
|
reports
|
Where the settlements record the reports of unestablished stops.
TYPE:
|
reached
|
The handlers a run may install, so a run configures those and no
other declaration of its module;
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, object]
|
The configuration of each such handler, by name. |
Source code in src/quivers/qiec/program_runtime.py
run_deduction
¶
run_deduction(module: QiecModule, name: str, *, tokens: Sequence[str] | None = None, axioms: Sequence[object] | None = None, axiom_weights: Sequence[object] | None = None, parameters: Mapping[str, object] | None = None, observer: TraceObserver | None = None, record_trace: bool = False, fuel: int | None = None, on_failure: FailurePolicy = REFUSE) -> DeductionRun
Run a deduction's entry on the reference machine.
A deduction whose derivations may repeat an item iterates to a
fixed point. A stop is certified when the arithmetic is exact (a
fixed point reached from below is the least one) or when the
iteration found no further derivation; a stop because two iterates
agree within the declared tolerance, or agree in rounded arithmetic
while derivations keep growing, certifies nothing, and the run
refuses it or returns it as unestablished, as on_failure says.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module holding the deduction.
TYPE:
|
name
|
The deduction's name.
TYPE:
|
tokens
|
The sentence, for a deduction with a lexicon.
TYPE:
|
axioms
|
The axiom items, for a deduction without one; runtime constructor values of its item family.
TYPE:
|
axiom_weights
|
One weight per axiom in the semiring's carrier.
TYPE:
|
parameters
|
The learned weights by name; an absent weight reads as zero.
TYPE:
|
observer
|
A callback receiving every trace event as the machine emits it.
TYPE:
|
record_trace
|
Whether the result keeps every event. The search enumerates derivations, so its events grow with the number of derivation steps while its live state grows with the sentence; they are kept only when asked for.
TYPE:
|
fuel
|
A step budget for the run. A run that spends it is refused.
TYPE:
|
on_failure
|
What a stop by a control does: refuse, or return the value as
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DeductionRun
|
The goal's inside weight. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the module has no such deduction. |
ValueError
|
If the input does not fit the deduction: tokens for one that takes axioms, or the reverse. |
ContractNotMet
|
If an iteration stopped by a control and the policy refuses. |
ExecutionFailure
|
If the run fails. |
Source code in src/quivers/qiec/program_runtime.py
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 | |
deduction_item
¶
deduction_item(module: QiecModule, name: str, symbol: str, *fields: object) -> RuntimeConstructor
Build an item of a deduction's family as a host value.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module holding the deduction.
TYPE:
|
name
|
The deduction's name.
TYPE:
|
symbol
|
The atom or constructor symbol, as the deduction spells it.
TYPE:
|
*fields
|
The constructor's fields: integers for position slots, items for the rest; numbers become the machine's tensors.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConstructor
|
The item, which |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the deduction declares no such symbol. |
ValueError
|
If the field count differs from the constructor's arity. |