Program runtime¶
Running program entry points on the reference machine.
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
dataclass
¶
ProgramRun(value: object, log_joint: float, result: ExecutionResult)
What running a program on the reference machine produced.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The value the program returned.
TYPE:
|
log_joint
|
The log joint density: every replayed site's log density under its distribution plus every observation's and score's weight.
TYPE:
|
result
|
The underlying execution result, with its trace.
TYPE:
|
DeductionRun
dataclass
¶
DeductionRun(weight: object, result: ExecutionResult)
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.
TYPE:
|
result
|
The machine's full result, with its trace.
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
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
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 | |
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, ...] = ()) -> 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, fibrations, 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:
|
| 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
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | |
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, ...] = ()) -> 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, fibrations, 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:
|
| 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
646 647 648 649 650 651 652 653 654 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 | |
foreign_handler_configuration
¶
foreign_handler_configuration(module: QiecModule) -> dict[str, object]
The runtime configuration of a module's elaborated foreign handlers.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, object]
|
By handler name: the enumeration handlers of marginalization blocks, the collecting handlers of those blocks and of deductions, and the search handlers of deductions, each with the options its name records. |
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, fuel: int | None = None) -> DeductionRun
Run a deduction's entry on the reference machine.
| 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:
|
fuel
|
A step budget for the run.
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. |
ExecutionFailure
|
If the run fails. |
Source code in src/quivers/qiec/program_runtime.py
919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 | |
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.
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. |