Step resolution¶
Resolving the distribution references of program steps.
Internal module
This module is an implementation detail of the compiler and its
tooling. Its __all__ is empty, so none of the names below are
part of the public API, and they may change without notice.
step_resolution
¶
Resolve the distribution references of program steps.
A draw may name a family, a declared morphism, or a let alias. This module resolves those forms to canonical family names and arguments, for the QIEC elaboration and the transpilers alike. It also rejects consumed parameter-source morphisms because their learned weights are absent from the QVR wire representation.
StepResolutionError
¶
Bases: ValueError
A step's distribution reference could not be resolved.
| PARAMETER | DESCRIPTION |
|---|---|
target
|
The consumer the resolution ran for, such as a transpile target.
TYPE:
|
kinds
|
Structured identifiers of what could not be resolved.
TYPE:
|
Source code in src/quivers/dsl/step_resolution.py
ResolvedDist
dataclass
¶
ResolvedDist(family: str, args: tuple[str | float, ...], original_morphism_name: str, via: tuple[str, ...] = ())
The (family, args) pair a sample / observe step resolves to.
family is the canonical QVR family name, exactly as it would
appear if the user had written sample x <- family(args).
args is the tuple of positional arguments after resolution,
held in the legacy wire form str | float for backends that
have not migrated to the structural DrawArg representation.
The original_morphism_name and via fields are diagnostic:
when a sample resolves through a morphism declaration, the
transpiled output can reference both the underlying family and the
original morphism name (some backends prefer one or the other).
param_source_kind
¶
param_source_kind(decl: MorphismDecl, *, target: str) -> str | None
Return the parameter-source kind a morphism declaration names
in its [param_source=...] option, or None when it carries
no such option.
Two surface shapes name a kind. The bare identifier
([param_source=mlp]) parses to an
OptionName whose
value is the kind; the parameterised call
([param_source=mlp(16, 8)]) parses to an
OptionCall whose
func is the kind and whose args are the hidden widths.
Both denote the same source architecture, so both resolve to the
same kind string and hit the same transpile boundary.
Any other option shape (a bare flag, a number, a list) names no architecture, so there is nothing for the message to report and nothing a target could be told it is missing. That is a malformed declaration rather than an unsupported one, and it is rejected here by name instead of reaching a target.
Source code in src/quivers/dsl/step_resolution.py
morphism_table
¶
morphism_table(module: Module) -> dict[str, MorphismDecl]
Return name → MorphismDecl for every morphism declaration in
module, without the parameter-source boundary check.
A plural-name declaration contributes one entry per name (each name is an independent morphism with the same signature and init). Duplicate names are an error.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The parsed module.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, MorphismDecl]
|
The declaration each morphism name denotes. |
| RAISES | DESCRIPTION |
|---|---|
StepResolutionError
|
If a morphism name is declared twice. |
Source code in src/quivers/dsl/step_resolution.py
build_morphism_table
¶
build_morphism_table(module: Module) -> dict[str, MorphismDecl]
Return name → MorphismDecl for every morphism declaration in
module, checked for the transpile boundary.
The table is morphism_table's;
building it is also where a module is checked for parameter-source
morphisms it consumes, in a site, value or composite position; see
_reject_param_source_consumed. The table is the resolver's
authority on what each name denotes, so it is the one place that
sees every declaration at once, which is what deciding a
module-wide boundary needs.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The parsed module.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, MorphismDecl]
|
The declaration each morphism name denotes. |
| RAISES | DESCRIPTION |
|---|---|
StepResolutionError
|
If a morphism name is declared twice, or a parameter-source morphism is consumed. |
Source code in src/quivers/dsl/step_resolution.py
build_let_table
¶
Return name → expr for every top-level let_decl.
Source code in src/quivers/dsl/step_resolution.py
resolve_step_dist
¶
resolve_step_dist(morphism_name: str, raw_args: tuple[DrawArg, ...] | None, *, morphisms: dict[str, MorphismDecl], lets: dict[str, Expr], family_registry: frozenset[str], target: str, _seen: tuple[str, ...] = ()) -> ResolvedDist
Resolve a sample / observe step's morphism slot to a
(family, args) pair.
| PARAMETER | DESCRIPTION |
|---|---|
morphism_name
|
The string in
TYPE:
|
raw_args
|
Positional arguments on the step (
TYPE:
|
morphisms
|
Name → MorphismDecl table from
TYPE:
|
lets
|
Name → Expr table from
TYPE:
|
family_registry
|
Frozen set of canonical QVR family names. When
TYPE:
|
target
|
Backend name (for error messages).
TYPE:
|
_seen
|
Internal: the chain of names visited during resolution. The
resolver detects cycles (
TYPE:
|
Source code in src/quivers/dsl/step_resolution.py
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 746 747 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 | |