Compiler¶
Lowering from a DSL AST to an executable Program.
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)
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:
|
Source code in src/quivers/dsl/compiler/core.py
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. |
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
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.). |
Source code in src/quivers/dsl/compiler/core.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
compile_env
¶
Compile all statements and return the full environment.
Useful for inspection without requiring an output declaration.
| 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
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:
|