Compiler¶
Compilation from DSL AST to executable quivers.
compiler
¶
Compiler: transform a quivers DSL AST into a trainable Program.
The compiler walks the AST in declaration order, building up an environment of objects, spaces, and morphisms, then compiles the output expression into a quivers.Program (nn.Module).
Supports both discrete (FinSet-based) and continuous (ContinuousSpace- based) morphisms, including stochastic (Markov kernels), boundary (Discretize/Embed), and parameterized family distributions.
CompileError
¶
CompileError(message: str, line: int = 0, col: int = 0)
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:
|
Source code in src/quivers/dsl/compiler.py
211 212 213 214 215 | |
Compiler
¶
Compiler(module: Module)
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:
|
Source code in src/quivers/dsl/compiler.py
236 237 238 239 240 241 242 243 244 245 | |
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.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
compile_env
¶
compile_env() -> dict
Compile all statements and return the full environment.
Useful for inspection without requiring an output declaration.
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Combined environment of objects, spaces, morphisms, and the quantale. |
Source code in src/quivers/dsl/compiler.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |