math_spec.lowering
Lower a model to a :class:~math_spec.program.Program — the pass that decides every expression.
One lowering, on the language side, run when a :class:~math_spec.model.Spec
loads: it reads every expression and where string into the program's own
nodes, checks every rule decidable without data, and packages the
declarations, section for section. The program mirrors the model it was
lowered from: a piecewise: block the model still declares is a curve on
the program, and :meth:~math_spec.model.Spec.expand is what writes it out
as rows.
lower(schema)
#
Lower schema's own declarations, checking every rule decidable without data.
What is checked:
- every rule one declaration is held to against the others
(:func:
~math_spec.validation.reference_errors), before any expression is read, since resolution assumes each of them; - the expression parses, and constraints hold exactly one comparison where objectives hold none;
- every referenced name resolves, and every operator is a built-in whose dimension arguments name declared dimensions;
- where strings parse and resolve — an unknown name there is an error, not a silently-empty mask;
- macro formals may shadow model names but not a declared dimension, since
over=snapshotunder a formalsnapshotcannot say which it means; - no name a set or curve writes out is one the file declares
(:func:
~math_spec.validation.emitted_name_errors), read off the curve as lowered; - every dim rule (
dimensions.check_schema), once names resolve.
A piecewise: block's links are resolved and its frame checked here, on
the link the file wrote, so the expansion writes rows the language has
already held to every rule; what its method assumes of the breakpoints
stands under the program's assumptions with the file's own, so a model
states what it assumes whether or not its curves are written out.
| RETURNS | DESCRIPTION |
|---|---|
Program
|
The program of what schema declares, section for section. |
| RAISES | DESCRIPTION |
|---|---|
SchemaError
|
Listing every problem found, one per line. A name a set or curve writes that the file declares is listed once every other problem is gone, since it is read off the curve as lowered. |
DimensionError
|
The first dim rule a declaration breaks, once every name resolves. |
Source code in src/math_spec/lowering.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 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 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 | |