Chain shapes¶
chain_shape
¶
ChainShape: per-step metadata derived from a compiled QVR program.
A ChainShape walks a quivers.dsl.ast_nodes.Module
AST once and records, for every let / latent / observe /
marginalize step inside the module's program block:
- the bound variable name,
- the source line / column where the step was declared,
- the program's governing algebra (looked up from the top-level
algebra <name>declaration via the algebra registry), - the step's depth in the chain of stochastic / scoring binds,
numbered from 1 at the first
latent/observeand incremented at every subsequent stochastic step.letsteps carry the depth of the most recent preceding stochastic step (0if there isn't one yet), - the step's intermediate axis size where it can be derived from
the program's object declarations (
Respcardinality for per-row lets / observes; the plate object cardinality for per-level latents; the morphism's codomain otherwise). When the size cannot be statically inferred we recordNone.
The result is purely metadata; ChainShape never rewrites or recompiles the program. The fields are what downstream tooling (algebra-specific initialization, saturation warnings, hook-based telemetry) reads.
StepKind
module-attribute
¶
The kind tag of a StepShape: a stochastic bind (latent,
observe, marginalize) or a deterministic let.
StepShape
didactic-model
¶
StepShape(*, name: str, kind: StepKind, source_line: int = 0, source_col: int = 0, depth: int = 0, algebra_name: str = '', intermediate_size: int | None = None)
Bases: Model
Per-step metadata derived by ChainShape.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
Bound variable name (the LHS of the step).
TYPE:
|
kind |
One of
TYPE:
|
source_line, source_col |
Source position where the step was declared.
TYPE:
|
depth |
The 1-indexed position of the step in the chain of
stochastic binds (
TYPE:
|
algebra_name |
Name of the program's governing algebra.
TYPE:
|
intermediate_size |
Cardinality of the bound coordinate's intermediate axis,
when statically inferable from the AST.
TYPE:
|
ChainShape
didactic-model
¶
ChainShape(*, algebra_name: str = '', object_cardinalities: Mapping[str, int] = field(default_factory=dict, opaque=True), steps: tuple[StepShape, ...] = ())
Bases: Model
Sequence of StepShape records for a program.
| ATTRIBUTE | DESCRIPTION |
|---|---|
algebra_name |
Name of the program's governing algebra (the top-level
TYPE:
|
object_cardinalities |
Cardinality of every
TYPE:
|
steps |
Per-step metadata in source order.
TYPE:
|
stochastic_depth
property
¶
Number of stochastic-bind steps (latent, observe,
or marginalize).
algebra
property
¶
algebra: Algebra | None
Resolve algebra_name against the algebra
registry. Returns None if the name is unknown (e.g. a
user-defined inline composition rule not registered).
from_module
classmethod
¶
from_module(module: Module) -> 'ChainShape'
Build a ChainShape from a compiled
Module AST.
Walks the module's statement list, captures the algebra
name from any top-level CompositionDecl, captures
every ObjectDecl's numeric cardinality, then walks
the unique ProgramDecl's steps in source order.
MarginalizeStep bodies are walked recursively;
their inner steps are recorded after the enclosing
MarginalizeStep.
Source code in src/quivers/analysis/chain_shape.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |