Structural runtime¶
This module runs checked encoder, decoder, and structural loss computations through registered Python implementations (differentiating through a run). A run needs a provider for each requested operation, and a transpile target must support those operations to run the translated computation.
FiniteDecoderSupport
checks a supplied set of closed structural terms against one object sort of
the decoder's shared rule presentation. Its distribution(code) produces
a finite law on those terms in the presentation's nominal QIEC family.
structural_runtime
¶
Run host-backed structural computations on the reference machine.
PreparedDecoderSupport
didactic-model
¶
PreparedDecoderSupport(*, sort: str, max_candidates: int, families: SignatureFamilies = field(opaque=True, extras=OPAQUE_BY_VALUE), candidates: tuple = field(opaque=True, extras=OPAQUE_BY_VALUE), layout: tuple = field(opaque=True, extras=OPAQUE_BY_VALUE))
Bases: ValueModel
Static candidates, kept independently of a live neural decoder.
| PARAMETER | DESCRIPTION |
|---|---|
sort
|
The structural sort.
TYPE:
|
max_candidates
|
The bound used to prepare this support.
TYPE:
|
families
|
The signature's families, whose root family the points inhabit.
TYPE:
|
candidates
|
Pairs of typed run-time values and their source structural terms.
TYPE:
|
layout
|
The support-defining decoder declarations.
TYPE:
|
element
property
¶
element: TypeApplication
The type of a point.
| RETURNS | DESCRIPTION |
|---|---|
TypeApplication
|
The family of the support's sort. |
distribution
¶
distribution(decoder: Decoder, code: Tensor) -> FiniteSampleable
Score this support with the decoder at the current invocation.
| PARAMETER | DESCRIPTION |
|---|---|
decoder
|
The same structural decoder configuration and a floating code of the declared width, with any live parameters.
TYPE:
|
code
|
The same structural decoder configuration and a floating code of the declared width, with any live parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FiniteSampleable
|
The fixed typed points with fresh differentiable log weights. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the code or decoder configuration does not match the support. |
Source code in src/quivers/qiec/structural_runtime.py
FiniteDecoderSupport
didactic-model
¶
FiniteDecoderSupport(*, decoder: Decoder = field(opaque=True, extras=OPAQUE_BY_IDENTITY), sort: str, candidates: tuple[Term, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), max_candidates: int, module: str = '')
Bases: QiecModel
A decoder restricted to an explicit finite set of closed terms.
The candidates are values of the signature's sort family in a module
(see quivers.structural.families), so a draw from the law is an
ordinary family value that computations analyze by cases. Repeated
identical candidates name the same term. Only first-order term
signatures are supported, since a closed candidate of a binding
signature would need variables in its scopes.
| PARAMETER | DESCRIPTION |
|---|---|
decoder
|
The decoder whose log probability determines the conditional law.
TYPE:
|
sort
|
The object sort of the candidates.
TYPE:
|
candidates
|
The supplied finite support. Every term must be in the decoder's domain, including its depth and data-vocabulary restrictions.
TYPE:
|
max_candidates
|
A positive bound on the number of supplied entries, checked before validating terms. Exceeding the bound refuses the entire support.
TYPE:
|
module
|
The module whose families the candidates are values of; the signature's own name when empty.
TYPE:
|
families
cached
property
¶
families: SignatureFamilies
The families the candidates are values of.
| RETURNS | DESCRIPTION |
|---|---|
SignatureFamilies
|
The signature's families in the support's module. |
element
property
¶
element: TypeApplication
The nominal QIEC type of a point of this support.
| RETURNS | DESCRIPTION |
|---|---|
TypeApplication
|
The family of the selected structural sort. |
complete
classmethod
¶
complete(decoder: Decoder, *, sort: str, max_candidates: int, module: str = '') -> FiniteDecoderSupport
Prepare the complete support of a productive depth-bounded decoder.
| PARAMETER | DESCRIPTION |
|---|---|
decoder
|
The first-order decoder and its depth bound.
TYPE:
|
sort
|
The root object sort to expand.
TYPE:
|
max_candidates
|
The most terms to materialize. It must be positive.
TYPE:
|
module
|
The module whose families the candidates are values of.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FiniteDecoderSupport
|
Every term admitted by the given structural decoder at this root. When its local distributions are valid, its normalized law agrees with the original decoder. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a reachable branch is unproductive, the domain is unsupported, or the number of terms exceeds the bound. |
Source code in src/quivers/qiec/structural_runtime.py
distribution
¶
distribution(code: Tensor) -> FiniteSampleable
Build the conditional decoder law at one unbatched code.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
One embedding of the selected object sort.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FiniteSampleable
|
The same supplied terms with freshly evaluated log masses, normalized over this set by the finite sampleable. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the code has the wrong shape or the decoder's signature, depth or vocabularies have changed. |
RuntimeError
|
If a supplied term violates the decoder's depth or vocabulary restriction, or the decoder lacks a required component. |
DistributionError
|
If the finite law has no positive mass or invalid log masses. |
Source code in src/quivers/qiec/structural_runtime.py
StructuralRuntimeProvider
didactic-model
¶
StructuralRuntimeProvider(*, runtimes: tuple[RuntimeHandler, ...] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), term_types: Mapping[TypeId, tuple[SignatureFamilies, str]] = field(default=MappingProxyType({}), opaque=True, extras=OPAQUE_BY_VALUE), graph_types: frozenset[TypeId] = field(default=frozenset(), opaque=True, extras=OPAQUE_BY_VALUE), name: str = 'structural')
Bases: QiecModel
PyTorch components and validators for one structural invocation.
| PARAMETER | DESCRIPTION |
|---|---|
runtimes
|
The host handlers implementing the module's structural computations.
TYPE:
|
term_types
|
Type identities of signature sort families, with their families and sorts; a value of one is a runtime constructor of the family.
TYPE:
|
graph_types
|
Type identities of graph families, whose host values are
structural :class:
TYPE:
|
name
|
The provider name recorded in execution results and traces.
TYPE:
|
attach
¶
attach(module: QiecModule, attachments: RuntimeAttachments) -> None
Attach each host computation handler.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module, unused because the handlers were selected while constructing this provider.
TYPE:
|
attachments
|
The invocation's attachment table.
TYPE:
|
Source code in src/quivers/qiec/structural_runtime.py
validator_for
¶
validator_for(type_: TypeExpr) -> RuntimeValidator | None
Return the validator for structural values and torch values.
| PARAMETER | DESCRIPTION |
|---|---|
type_
|
The closed QIEC type a host argument or result must inhabit.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeValidator | None
|
A predicate for scalar weights, family values, graphs, tensors,
and structural products, or |
Source code in src/quivers/qiec/structural_runtime.py
prepared_support
¶
prepared_support(decoder: Decoder, module: str) -> PreparedDecoderSupport
A bounded decoder's complete support as values of a module's families.
| PARAMETER | DESCRIPTION |
|---|---|
decoder
|
A decoder whose declaration bounds its support; compilation records the bound and the checked candidate terms on it.
TYPE:
|
module
|
The module whose families the points are values of.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PreparedDecoderSupport
|
The support, prepared once per decoder and module. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the decoder declares no bounded support. |
Source code in src/quivers/qiec/structural_runtime.py
module_families
¶
module_families(module: QiecModule, program: Program) -> dict[TypeId, tuple[SignatureFamilies, str]]
The sort families of a compiled program's term signatures in a module.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module.
TYPE:
|
program
|
The compiled program, which holds the runtime signatures.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Each family's type identity with its families and sort. |
Source code in src/quivers/qiec/structural_runtime.py
structural_handler_definition
¶
structural_handler_definition(effect: EffectRef, result: TypeExpr, *, instance_name: str, computation_name: str) -> HandlerDef
Build the stable checked handler signature for one neural attachment.
| PARAMETER | DESCRIPTION |
|---|---|
effect
|
The applied
TYPE:
|
result
|
The closed result type returned by the host component.
TYPE:
|
instance_name
|
The source-derived effect-instance name.
TYPE:
|
computation_name
|
The source-derived structural computation name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
HandlerDef
|
A stable foreign handler declaration for the component. |
Source code in src/quivers/qiec/structural_runtime.py
structural_runtime_provider
¶
structural_runtime_provider(module: QiecModule, program: Program) -> StructuralRuntimeProvider
Build the typed neural-attachment provider for a compiled module.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked QIEC module whose structural instances need handlers.
TYPE:
|
program
|
The compiled container supplying the corresponding PyTorch objects.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StructuralRuntimeProvider
|
A provider containing one validated runtime handler per structural instance. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If a structural component returns a type with no host validator. |
Source code in src/quivers/qiec/structural_runtime.py
structural_runtime_configuration
¶
structural_runtime_configuration(module: QiecModule, program: Program) -> RuntimeConfiguration
Return the standard runtime configuration for structural entries.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked QIEC module whose structural entries may be invoked.
TYPE:
|
program
|
The compiled container supplying their PyTorch attachments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConfiguration
|
A configuration selecting the structural provider when the module has structural runtimes, or no providers otherwise. |
Source code in src/quivers/qiec/structural_runtime.py
host_arguments
¶
host_arguments(module: QiecModule, program: Program, name: str, arguments: Sequence[object]) -> tuple[object, ...]
Read structural terms given to a computation as family values.
A value of a signature's sort family is a structural Term at the
host boundary; each argument whose parameter is such a family and which
is given as a term is converted to the family's runtime value.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module.
TYPE:
|
program
|
The compiled program.
TYPE:
|
name
|
The computation's name.
TYPE:
|
arguments
|
Its host arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
The arguments, terms converted. |
Source code in src/quivers/qiec/structural_runtime.py
host_result
¶
host_result(module: QiecModule, program: Program, value: object) -> object
Read a family value returned to the host as a structural term.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module.
TYPE:
|
program
|
The compiled program.
TYPE:
|
value
|
A returned value.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
The structural term when the value belongs to a signature family, the value unchanged otherwise. |
Source code in src/quivers/qiec/structural_runtime.py
run_structural
¶
run_structural(module: QiecModule, program: Program, name: str, arguments: Sequence[object], *, fuel: int | None = None) -> ExecutionResult
Run a structural computation through the compiled PyTorch attachments.
Structural terms given for a family parameter are converted to family values; the result keeps the machine's representation.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked QIEC module.
TYPE:
|
program
|
The classic compiled container supplying encoders, decoders, losses, and their learned tensors.
TYPE:
|
name
|
The structural computation name.
TYPE:
|
arguments
|
Its host arguments.
TYPE:
|
fuel
|
Optional reference-machine step budget.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ExecutionResult
|
The typed result and trace. Torch tensor results retain their autograd graph back to the attached component parameters. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If |