Repository navigation
ltm: check link scores by replaying a model's own code - #1099
Conversation
A VECTOR ELM MAP offset is a number the model computes, and two readings of one that names no element went wrong. An offset past what an i64 holds, from a base past the first element, overflowed the index: the VM panicked in a build with overflow checks, and wrapped to the right answer in any other. And an offset the compiler folds read the base element when it was not a number, where one the run computes is NA. Both now saturate and both read NaN as NA, so the folded spelling and the computed one agree. Found by running each variable's code over rows that hold nothing but what it reads.
A flow in a systems-format model is a module instance (systems_rate, systems_leak, systems_conversion), read through its `actual` and `remaining`. LTM looked for a stdlib module's one output under the name `output`, which the SMOOTH and DELAY models have and these do not, so no link into a systems flow had a pathway to score, every one of them scored 0, and no loop through a flow was reported: none at all, for a model of nothing but stocks and flows. A stdlib model without an `output` is now looked at as a person's own sub-model is, by the variables its readers name. Comparing the corpus's ten systems models with scores replayed from their own code, 39 links that scored 0 now agree with the replay or differ as any module with several outputs does.
`total[R] = SUM(pop[*])` reads every element of `pop` into every element of `total`. Where a reducer is a variable's whole equation, LTM takes the variable itself as the reducer's node, so the link is scored directly, with a slot per element of `total`: the diagonal alone, each element credited with the whole sum's change (a score of 1 where the element is a tenth of it), and the links between different elements not scored at all. MEAN, MIN and MAX did the same, a MAX over two dimensions scoring -0.9 where the element does nothing. Such a reducer is now a node of its own, as it is when it is written inside a larger equation, with a link from each element and one to each. A scalar variable of the same reducer is still the node itself.
LTM's link scores are equations the engine writes: a target's equation with every read but one held at the previous step, compiled beside the model. What checks them is tests that work a score out by hand, or compare two spellings, on the shapes someone thought of. ltm_replay is the method's own procedure instead. It runs the model as it is, cuts its compiled program into the code that computes each slot, and scores a link by running the target's code once more over the step before's row with the one source slot moved to this step's. It shares no equation with the generators, and it proves what it needs of itself: an opcode it has no rule for is refused, and every slot's code must give back the run's value over rows that hold nothing but what it reads. ltm_replay_compare compares the two for every link of a model and names each difference by the number it is: a documented convention, one read of several, a whole change credited to one input, a 0. The corpus gate holds 400 models to a table of the known ones, which is what any change to a generator is now read against, and an instrument lists them for one model. All of it is test-support: no shipped build holds it, and the VM's dispatch loop keeps its one caller.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1099 +/- ##
==========================================
+ Coverage 93.01% 93.05% +0.04%
==========================================
Files 300 302 +2
Lines 192638 194230 +1592
==========================================
+ Hits 179176 180739 +1563
- Misses 13462 13491 +29 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 98edabf9ed
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let project = open(path)?; | ||
| // A model that does not compile, or whose stocks the overlay does | ||
| // not take (a conveyor, a queue), has no scores. | ||
| let comparison = compare(&project).ok()?; |
There was a problem hiding this comment.
Fail the corpus gate on unexpected comparison errors
When an LTM overlay changes a model's original results, Generated::ran_the_same_model returns an error, but this .ok()? silently drops that model instead of failing the gate. Errors from cutting or replaying an otherwise compilable model are swallowed in the same way. The corpus assertions only enforce aggregate floors of 400 models and 5,700 active agreements, so individual models can disappear from coverage while the gate stays green; even the KNOWN membership check only checks paths, not successful comparisons. Distinguish explicitly permitted compile/unsupported-model skips from comparison failures and fail on the latter.
Useful? React with 👍 / 👎.
| let slots = plain | ||
| .offsets | ||
| .iter() | ||
| .map(|(name, &slot)| (name.as_str().to_string(), slot)) | ||
| .collect(); |
There was a problem hiding this comment.
Normalize singleton-array names before matching scored links
For an array whose total extent is one, flatten_model records its slot under the bare variable name, whereas link_score_offsets expands generated link endpoints with subscripts. Copying those bare names directly into slots prevents the comparator from matching real, scored slots. I reproduced this with a one-element dimension D, pop[D] = INTEG(grow[D], 100), and grow[D] = pop[D] * 0.1: both links are incorrectly reported in not_slots under their [1] names and again in not_scored under their bare names, with zero agreements. Normalize singleton-array aliases consistently on the replay and generated sides so these links are actually compared.
Useful? React with 👍 / 👎.
| for (i, first) in edges.iter().enumerate() { | ||
| if !is_variable(first.from) || !is_active(side.series(i)) { | ||
| continue; |
There was a problem hiding this comment.
Exclude undefined rows when identifying unscored links
When a target is NaN throughout the run, its replayed scores contain NaNs, which is_active treats as active because NaN != 0.0. Unlike the ordinary comparison path, unscored never applies Side::defined, so it reports missing active scores even though no row has a defined target change. I reproduced this with growing pop[R], on[R] = 0, and selected = VECTOR SELECT(on[*], pop[*], NAN, 0, 0): all three pop elements are reported as not_scored despite selected never being a number. Apply the defined-row mask before reporting one-sided activity so these undefined scores do not become false corpus regressions.
Useful? React with 👍 / 👎.
Three ways the comparison of generated and replayed link scores could say less than it seemed to. A corpus model it could not compare was skipped whatever the reason; only one that does not run is now, and a program that cannot be replayed, or a run with scores that is not the model's run, fails the gate, as does a known model that is not compared. An array of one element has no element in its results name, so its links matched nothing and were reported from both sides. And a target that is never a number counted as active, so its links were reported as going unscored.
LTM's link scores are equations the engine writes: a target's equation with every read but one held at the previous step, compiled beside the model.
This adds a check that shares nothing with them, and fixes what it found that was small and silent.
The check
ltm_replayis the method's own procedure (LTM reference, section 3.1): run the model as it is, then for each link run the target's own compiled code once more, over the step before's values with the one source moved to this step's.ltm_replay_comparecompares that with the generated score of every link and names each difference by the number it is.Of C-LEARN's 67, 44 are elements of one weighted sum, each credited with the sum's whole change; 15 read a
STEPwhose clock stays live; 8 are rounding.Another 107 of its links, into
VECTOR SELECTandVECTOR ELM MAP, have no generated score (with a warning).tests/integration/ltm_replay.rs, 4 s under the gates profile; six small models and World3 run in the default suite in 0.5 s).cargo run --release -p simlin-tests --features instruments --example ltm_replay -- <model>.test-support: no shipped build holds it, and the VM's dispatch loop keeps its one caller.Fixes
actualandremaining; LTM looked for a stdlib module's output under the nameoutput, so every link into a flow scored 0. 39 links in the ten models are now scored.total[R] = SUM(pop[*])(an array variable that is a whole array's sum, mean, maximum or minimum) scored onlypop[a] -> total[a], as 1, and not the links between different elements. The reducer is now a node of its own, as it is inside a larger equation.VECTOR ELM MAPwith an offset past what an i64 holds overflowed (a panic in a build with overflow checks), and a folded NaN offset read the base element.Evidence
each_way_a_score_is_off_is_namedhas a model per reason;each_convention_is_the_number_it_statesholds each convention to its formula.scripts/gates.sh.Not covered
pop -> pickedforpicked = pop[i]) is reported as having no slot.SUM(m[R,*] * w[*]), a sum over a subrange, a dimension's name used as a number (warned), and lags (PREVIOUS), which the generated scores leave at the new step by design.