Step resolution¶
These functions resolve the distribution a program step names, whether a declared morphism or an inline family call, and the inputs it needs (program elaboration).
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. Each is a
colon-separated path of space-free segments, such as
TYPE:
|
explanation
|
The raise site's account of the failure in prose: what the program does at that site and what to write instead. Empty when the structured kind says everything the site knows.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
target |
The consumer the resolution ran for.
TYPE:
|
kinds |
The structured identifiers.
TYPE:
|
explanation |
The raise site's prose.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a kind contains a space, which would make it prose rather than an identifier a caller can match on. |
Source code in src/quivers/dsl/step_resolution.py
detail
property
¶
The kinds and the explanation as one diagnostic line.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The kinds joined by |
explained_kinds
property
¶
The kinds in the form a transpile refusal reports them.
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
Each kind followed by |
ResolvedDist
didactic-model
¶
ResolvedDist(*, family: str, args: tuple[str | int | float, ...], original_morphism_name: str, via: tuple[str, ...] = ())
Bases: Model
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 let x <- sample family(args).
args is the tuple of positional arguments after resolution,
held in the legacy wire form str | int | 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).
| PARAMETER | DESCRIPTION |
|---|---|
family
|
Canonical distribution family name.
TYPE:
|
args
|
Resolved positional arguments in the backend wire representation.
TYPE:
|
original_morphism_name
|
Source name from which this distribution was resolved.
TYPE:
|
via
|
Intermediate aliases visited during resolution.
TYPE:
|
latent_prior
¶
latent_prior(decl: MorphismDecl) -> MorphismInitFamily | None
The ~ Family(...) prior a latent parameter morphism is drawn as.
A morphism declared [role=parameter] ~ Family(args) is drawn
from as that family, with the arguments its declaration fixes.
| PARAMETER | DESCRIPTION |
|---|---|
decl
|
The declaration.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MorphismInitFamily | None
|
The declared family clause when the declaration has the
|
Source code in src/quivers/dsl/step_resolution.py
prior_draw_refusal
¶
prior_draw_refusal(name: str, prior: MorphismInitFamily | None, args: tuple[DrawArg, ...] | None) -> str | None
Explain why a draw from a latent parameter morphism is refused.
A latent parameter morphism is drawn from as its declared prior, whose arguments the declaration fixes, so a draw that passes arguments to it names parameters no family slot is left to read.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The morphism the step draws from.
TYPE:
|
prior
|
Its declared prior, as
TYPE:
|
args
|
The step's arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The refusal when the morphism has a declared prior and the step
passes it arguments, else |
Source code in src/quivers/dsl/step_resolution.py
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, native_kernel: bool = False, _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:
|
native_kernel
|
Resolve the source identity of a kernel retained by the native runtime. This permits declared parameter sources because the caller retains the actual learned module; wire-only consumers must leave this false and cannot reconstruct its law from the returned default arguments.
TYPE:
|
_seen
|
Internal: the chain of names visited during resolution. The
resolver detects cycles (
TYPE:
|
Source code in src/quivers/dsl/step_resolution.py
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 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 1003 1004 1005 1006 1007 1008 1009 | |