Compiler¶
Compiler compiles a parsed QVR module to an executable Program
(compilation pipeline). It resolves names,
checks that domains and codomains agree, builds the runtime morphisms
(correspondences), and attaches the module's
checked Quivers Indexed Effect Core (QIEC) form. The resulting program can be run or passed to an inference procedure, and
CompileError reports a rejected module.
For interactive inspection, compile_env(defer_unresolved=True) compiles declarations
whose dependencies have known finite sizes and retains the remaining declarations
with their authored types. deferred_statements lists this dependency closure in
source order. The compiler preserves the complete checked QIEC module; unresolved
sizes do not hide errors in independent declarations. Ordinary compilation still
requires evidence for each inferred size.
compiler
¶
quivers.dsl.compiler: AST -> Program compiler.
Re-exports the public surface from the package's submodules.
Compiler
¶
Compiler(module: Module, *, module_name: str | None = None, file_path: str = '<source>', lower_qiec: bool = True, families: FamilyCatalog | None = None)
Bases: _DeclarationsMixin, _ProgramsMixin, _StructuralMixin, _DeductionsMixin, _ResolutionMixin, _ExpressionsMixin
Compile a quivers DSL AST into a Program.
The compiler maintains three environments:
- objects: name -> SetObject (discrete finite sets)
- spaces: name -> ContinuousSpace
- morphisms: name -> Morphism or ContinuousMorphism (any morphism-like)
It processes statements in order and compiles the output expression into a Program wrapping the morphism DAG.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The parsed AST.
TYPE:
|
lower_qiec
|
Whether to lower the checked QIEC projection. Tooling sets this to
TYPE:
|
families
|
Immutable custom family contracts and native implementations.
TYPE:
|
Source code in src/quivers/dsl/compiler/core.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
programs
property
¶
programs: dict[str, ProgramDecl]
Every declared program, by name.
A program with typed parameters (a template) and one without
both appear: each is a scope whose parameters and sites are
addressed by program::site paths. A program without typed
parameters also compiles to a morphism, listed in morphisms.
losses
property
¶
Declared loss heads (loss NAME : ... [on=...]).
Keyed by entry name; values are the registered :class:LossEntry
records. Empty when no loss decl appears in the module.
bundles
property
¶
Declared bundle aliases (bundle NAME = R1 | R2 | ...).
contractions
property
¶
Declared tensor-network contractions
(contraction NAME : ... [wiring=...]).
transformations
property
¶
User-declared transformation constructors / singletons.
qiec_module
property
¶
qiec_module: QiecModule | None
The checked QIEC module, or None when the source has no QIEC surface.
| RETURNS | DESCRIPTION |
|---|---|
QiecModule | None
|
The module, lowered on first access. |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If the source's QIEC surface fails to lower, other than by a program gap, which the module records instead. |
qiec_generated_declarations
property
¶
qiec_generated_declarations: tuple[GeneratedDeclaration, ...]
Return generated declarations retained by the cached QIEC check.
relation_specs
property
¶
relation_specs: dict[str, RationalRelationSpec]
Return the checked authored relation specifications in this source.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, RationalRelationSpec]
|
Topologies and live weight identities keyed by source name. |
composed_relation_specs
property
¶
composed_relation_specs: dict[str, ComposedRelationSpec]
Return checked binary compositions keyed by their authored names.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, ComposedRelationSpec]
|
Ordered operand specifications and original weight identities. |
transformed_relation_specs
property
¶
transformed_relation_specs: dict[str, UnaryRelationTransformSpec | BinaryRelationTransformSpec | RelationCascadeSpec]
Return checked sparse transformations by their authored names.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, UnaryRelationTransformSpec | BinaryRelationTransformSpec | RelationCascadeSpec]
|
Ordered original operands and selected sparse operations, including cascades. |
string_graph_specs
property
¶
string_graph_specs: dict[str, StringFactorGraphSpec]
Return checked string graphs by their authored names.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, StringFactorGraphSpec]
|
Ordered observations and factor scopes with original relation identities. |
deferred_statements
property
¶
deferred_statements: tuple[Statement, ...]
Authored declarations awaiting finite-object specialization.
| RETURNS | DESCRIPTION |
|---|---|
tuple[Statement, ...]
|
Uncompiled declarations in source order, retaining their authored types. No finite cardinalities are invented for these declarations. |
entry_points
¶
entry_points() -> tuple[EntryPoint, ...]
The executable entry points of the checked module.
| RETURNS | DESCRIPTION |
|---|---|
tuple[EntryPoint, ...]
|
Every |
Source code in src/quivers/dsl/compiler/core.py
entry
¶
entry(name: str) -> EntryPoint
One entry point of the checked module, by name.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The entry's source name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EntryPoint
|
The entry. |
| RAISES | DESCRIPTION |
|---|---|
ExecutionFailure
|
With code |
Source code in src/quivers/dsl/compiler/core.py
authored_checkpointed_gradient
¶
authored_checkpointed_gradient(name: str, arguments: tuple[int | Fraction, ...], *, max_work: int = 65536, fuel: int = 65536) -> ExactCheckpointCertificate
Differentiate a named source iteration using checkpoint replay.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The module-local checkpoint derivative declaration.
TYPE:
|
arguments
|
The exact initial state and shared parameters in declared order.
TYPE:
|
max_work
|
The bound on transition evaluations, including replay.
TYPE:
|
fuel
|
The reference step budget per transition evaluation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ExactCheckpointCertificate
|
The checked source identities, derived step count and measured result. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the declaration is absent or the request arguments are malformed. |
QiecDiagnosticError
|
If the source fails the checkpoint call-chain check. |
JvpUnsupported
|
If a reached transition fails the regular scalar derivative check. |
JvpLimit
|
If evaluation exhausts a resource limit. |
authored_implicit_gradient
¶
authored_implicit_gradient(name: str, arguments: tuple[int | Fraction, ...], *, max_work: int = 65536, fuel: int = 65536) -> ExactImplicitCertificate
Check a named source computation's implicit derivative.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The module-local implicit derivative claim.
TYPE:
|
arguments
|
The exact point in the primal's parameter order.
TYPE:
|
max_work
|
The arithmetic budget for the rational composition proof.
TYPE:
|
fuel
|
The reference evaluator step budget per run.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ExactImplicitCertificate
|
The named definitions, strict domain, and local derivative. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the claim is missing or the request arguments are malformed. |
QiecDiagnosticError
|
If a definition in the declaration fails nominal resolution. |
ImplicitRootError
|
If the identity is false or the reached root is singular. |
JvpUnsupported
|
If an exact rational proof or a regular scalar evaluation is unavailable. |
JvpLimit
|
If the proof or evaluation exhausts a bound. |
authored_derivative_rule
¶
authored_derivative_rule(name: str) -> RationalDerivativeDeclaration
Resolve a source claim's scalar derivative actions by checked identity.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The module-local name in the authored effect law declaration.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RationalDerivativeDeclaration
|
The named primal and actions in the checked source. Use the derivative checker or an effect plan request to check the formulas. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the checked source has no derivative declaration of this name. |
QiecDiagnosticError
|
If the source fails to lower or names an unknown computation. |
authored_bernoulli_completion
¶
authored_bernoulli_completion(name: str, arguments: tuple[int | Fraction, ...], direction: tuple[int | Fraction, ...], *, completed_module: QiecModule | None = None, fuel: int = 65536) -> BernoulliCompletion
Check a named source completion at an exact point and direction.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The named completion in the checked source.
TYPE:
|
arguments
|
The original computation's arguments and an exact direction.
TYPE:
|
direction
|
The original computation's arguments and an exact direction.
TYPE:
|
completed_module
|
An optional completed graph to verify against the declaration.
TYPE:
|
fuel
|
The step limit for each ordinary replay.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BernoulliCompletion
|
The completed graph and the exact original, extended and projected addressed histories at the requested point. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the completion does not exist or the arguments are invalid. |
QiecDiagnosticError
|
If the parsed source or completion fails to lower. |
JvpUnsupported
|
If the point or completed graph leaves the checked fragment. |
JvpLimit
|
If the exact replay exhausts its bound. |
authored_site_estimators
¶
authored_site_estimators(computation: str) -> tuple[SiteEstimator, ...]
Return the explicit estimator policies for one lexical computation.
| PARAMETER | DESCRIPTION |
|---|---|
computation
|
The name of the authored computation containing the sample requests.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of SiteEstimator
|
The policies in source order, bound to the original static sites. A computation with no assignments has an empty tuple. The estimator planner checks which sites execute at its point. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the source has no authored computation of this name. |
QiecDiagnosticError
|
If the checked source or an estimator assignment fails to lower. |
effect_plan
¶
effect_plan(name: str, *, obligations: tuple[EffectLawObligation, ...] = (), interchanges: tuple[FiniteHandlerInterchange, ...] = (), law_evidence: tuple[EffectLawEvidence, ...] = (), max_assignments: int = 65536, max_work: int = 65536, fuel: int = 65536) -> EffectPlan
Report checked effect analysis for one of the source's entry points.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The program or computation entry point's name.
TYPE:
|
obligations
|
The additional nominal equations to check alongside this source's authored finite laws.
TYPE:
|
interchanges
|
The additional finite handler interchanges to check after those declared in the source.
TYPE:
|
law_evidence
|
Claimed tests or assumptions bound to the requested obligations.
TYPE:
|
max_assignments
|
The domain size limit per finite obligation.
TYPE:
|
max_work
|
The work limit per scalar obligation.
TYPE:
|
fuel
|
The step limit per side and assignment in an exact interpreter.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EffectPlan
|
The entry's carrier reports, separately checked obligations, and the stages and obstacles of the ordinary discharge result. For a program, retains the matching parsed source for target reports on the public export. |
| RAISES | DESCRIPTION |
|---|---|
ExecutionFailure
|
If the source does not have the named checked entry point. |
ValueError
|
If a requested resource limit is invalid. |
Source code in src/quivers/dsl/compiler/core.py
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 | |
compile
¶
compile() -> Program
Compile the module into a trainable Program.
| RETURNS | DESCRIPTION |
|---|---|
Program
|
The compiled nn.Module wrapping the morphism DAG. |
| RAISES | DESCRIPTION |
|---|---|
CompileError
|
On semantic errors (undefined names, type mismatches, etc.), and for a module with typed holes, which has no compiled form; the message lists every hole. |
Source code in src/quivers/dsl/compiler/core.py
check
¶
Compile the module to check it, without keeping a Program.
Every check compile makes is made, but no compiled program
leaves the call, so a module with typed holes is checked around
them: a hole is well typed at its goal, and only a compiled form
has nowhere to put it.
| RAISES | DESCRIPTION |
|---|---|
CompileError
|
On semantic errors, as |
Source code in src/quivers/dsl/compiler/core.py
compile_env
¶
Compile all statements and return the full environment.
Useful for inspection without requiring an output declaration.
| PARAMETER | DESCRIPTION |
|---|---|
defer_unresolved
|
Retain unresolved finite objects and their dependent declarations symbolically, compiling independent declarations for inspection. False requires data to specialize every inferred object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Combined environment of every declared atom: the active algebra, objects, spaces, morphisms, rules, programs (parametric templates), deductions, signatures, encoders, decoders, losses, bundles, contractions, transformations. |
Source code in src/quivers/dsl/compiler/core.py
1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 | |
CompileError
¶
Bases: Exception
Raised when the compiler encounters a semantic error.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Error description.
TYPE:
|
line
|
Source line number (0 if unknown).
TYPE:
|
col
|
Source column number (0 if unknown).
TYPE:
|