Draw arguments¶
This adapter reads the DrawArg AST of
arguments at a distribution call,
matching the named arguments to a complete family parameterization so that
elaboration can build the draw.
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.
draw_args
¶
Reading adapter over the DSL DrawArg AST for the transpile.
The DSL models a draw-step argument with a recursive DrawArg
tagged union: an atom is a DrawArgScalar (number), a DrawArgName
(identifier), or a DrawArgIndex (bracket-indexed reference); a
vector literal [a, b] is a DrawArgList whose items are
atoms; a matrix literal [[a, b], [c, d]] is a DrawArgList
whose items are themselves DrawArgLists.
The transpile pipeline reads those arguments as flat forms: atoms
(numbers, identifiers, bracket-encoded references), vectors of
atoms, and matrices of atoms. This module is the single boundary
that translates the recursive AST shape into those flat forms, so
the lowering pass, the resolver, and the backend renderers never
match DrawArg variants or reach into items themselves. They
call atom_value, list_items, list_atoms, is_matrix, and
matrix_rows instead.
A bracket-indexed reference re-serialises to the repeated-bracket
surface form theta[i] / w[i][j] that the backends' own
index regex consumes, via encode_index.
argument_value
¶
bind_family_arguments
¶
bind_family_arguments(family: str, args: tuple[DrawArg, ...], canonical: tuple[str, ...] = (), *, allow_defaults: bool = True) -> tuple[tuple[str, DrawArg], ...]
Validate and order one keyword-only family construction.
The AST retains the names authors wrote. This boundary matches those names against one complete schema and returns values in that schema's canonical order, so positional target APIs never depend on source order.
| PARAMETER | DESCRIPTION |
|---|---|
family
|
Authored family name, including any surface alias.
TYPE:
|
args
|
Authored constructor arguments.
TYPE:
|
canonical
|
Fallback schema for a family without a registered surface schema.
TYPE:
|
allow_defaults
|
Whether an empty argument list delegates to the caller's existing default-construction policy. Explicit nested values require a complete schema instead.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[tuple[str, DrawArg], ...]
|
Named values in the selected schema's canonical order. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If arguments are positional, repeated, or do not match a complete schema. |
Source code in src/quivers/dsl/draw_args.py
encode_index
¶
encode_index(arg: DrawArgIndex) -> str
Serialise a bracket-indexed reference to its repeated-bracket
surface form: theta[i] for a single index, w[i][j] for
several. This is the wire form the backends' index parser reads.
Source code in src/quivers/dsl/draw_args.py
is_atom
¶
is_atom(arg: DrawArg) -> bool
True when arg is an atomic variant: a scalar, a bare name,
or a bracket-indexed reference.
atom_value
¶
atom_value(arg: DrawArg) -> Atom
Return the flat wire value of an atomic DrawArg.
A DrawArgScalar yields its float, a DrawArgName its
identifier text, and a DrawArgIndex its bracket-encoded
surface string. Raises for compound variants (DrawArgList,
DrawArgDist), which carry no single atomic value.
Source code in src/quivers/dsl/draw_args.py
list_items
¶
list_items(arg: DrawArgList) -> tuple[DrawArg, ...]
Return the recursive child DrawArgs of a list literal.
Use this when the children may themselves be compound (a matrix
row, a nested distribution); use list_atoms when every child
is known to be atomic.
Source code in src/quivers/dsl/draw_args.py
list_atoms
¶
list_atoms(arg: DrawArgList) -> tuple[Atom, ...]
Return the atomic wire values of a vector-literal
DrawArgList. Raises when any child is compound (guard matrix
inputs with is_matrix).
Source code in src/quivers/dsl/draw_args.py
is_matrix
¶
is_matrix(arg: DrawArg) -> bool
True when arg is a matrix literal: a non-empty DrawArgList
whose every item is itself a DrawArgList.
Source code in src/quivers/dsl/draw_args.py
matrix_rows
¶
matrix_rows(arg: DrawArgList) -> tuple[tuple[Atom, ...], ...]
Return the row-major atom values of a matrix-literal
DrawArgList (each item is a DrawArgList of atoms).
Callers should gate this with is_matrix.
Source code in src/quivers/dsl/draw_args.py
is_literal
¶
is_literal(arg: DrawArg) -> bool
Whether an argument is a number or a nested list of numbers.
| PARAMETER | DESCRIPTION |
|---|---|
arg
|
The argument, named or positional.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True for a numeric literal and for a vector or matrix literal whose every entry is one; False for a name, an indexed reference, or a nested family. |
Source code in src/quivers/dsl/draw_args.py
argument_text
¶
argument_text(arg: DrawArg) -> str
Render a draw argument as the source spells it.
| PARAMETER | DESCRIPTION |
|---|---|
arg
|
The argument.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The surface text: |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
Source code in src/quivers/dsl/draw_args.py
kernel_argument_refusal
¶
kernel_argument_refusal(morphism: str, family: str, args: tuple[DrawArg, ...]) -> tuple[DrawArg, str] | None
Explain why a kernel declaration's family arguments are refused.
A kernel declared ~ Family(...) either fixes its family with
literal arguments, one complete schema of numbers, or leaves the
argument list empty and takes every parameter from its learned
parameter source. An argument that names a value (scale=q)
has nothing to read in a declaration, which binds no program
value, so every execution path refuses it with this message.
| PARAMETER | DESCRIPTION |
|---|---|
morphism
|
The declared morphism's name.
TYPE:
|
family
|
The family its initializer names.
TYPE:
|
args
|
The initializer's arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[DrawArg, str] | None
|
The first argument that is not a literal and the refusal
naming it, or |