Composite lets¶
Normalizing program ASTs before lowering.
Internal module
This module is an implementation detail of the compiler and its
tooling. Its __all__ is empty, so none of the names below are
part of the public API, and they may change without notice.
composite_lets
¶
Normalize program ASTs before IR lowering.
The pass expands sampled composite bindings into atomic sample and let steps. It preserves marginalize blocks for the lowering stage while expanding composite references inside their scopes.
expand_composite_lets
¶
Rewrite program_decl bodies so composite-let sample steps
become equivalent chains of atomic sample steps.
A composite let is a DefineDecl whose .expr is an ExprCompose
(the prior >> likelihood form). Each SampleStep /
ObserveStep whose morphism slot names such a let is rewritten
into a sequence of fresh SampleSteps, one per element of the
composition chain, with the trailing step keeping the original
step's bound variable name.
The returned Module shares vertex identity with the input for
every non-rewritten statement; only the program_decls with
composite-let references are rebuilt.
The rewrite is target-independent: every backend consumes the same
expanded AST, and the choice of whether to enumerate or to sample a
marginalize latent is each renderer's, taken against the lowered
IRMarginalize. target is
accepted so callers can name the backend they are compiling for
without the pass branching on it.
Source code in src/quivers/dsl/composite_lets.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 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 | |