Skip to content

ltm: check link scores by replaying a model's own code - #1099

Merged
bpowers merged 5 commits into
mainfrom
ltm-oracle
Nov 25, 2026
Merged

bpowers merged 5 commits into
mainfrom
ltm-oracle

Conversation

@bpowers

@bpowers bpowers commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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_replay is 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_compare compares that with the generated score of every link and names each difference by the number it is.

Active scores that agree Differ
World3 309 0
C-LEARN 2,892 67
404 corpus models, those included 5,749 94

Of C-LEARN's 67, 44 are elements of one weighted sum, each credited with the sum's whole change; 15 read a STEP whose clock stays live; 8 are rounding.
Another 107 of its links, into VECTOR SELECT and VECTOR ELM MAP, have no generated score (with a warning).

  • A corpus gate holds every model to a table of what is known to differ (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).
  • An instrument lists the differences for one model: cargo run --release -p simlin-tests --features instruments --example ltm_replay -- <model>.
  • It is all test-support: no shipped build holds it, and the VM's dispatch loop keeps its one caller.

Fixes

  • A systems-format model had no loop through any flow. A flow there is a module read through actual and remaining; LTM looked for a stdlib module's output under the name output, 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 only pop[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 MAP with 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

  • The replay is right about what it reads. Every slot's code, over rows that hold nothing of the run but its reads, gives back the run's value bit for bit at every step: no exception in 404 models. An opcode with no rule is refused, and a unit test removes each read of a model with every reading opcode in turn and expects the check to fail.
  • Each reason is a number. each_way_a_score_is_off_is_named has a model per reason; each_convention_is_the_number_it_states holds each convention to its formula.
  • The fixes fail without their change: the systems loop test reports no loop, the folded NaN reads 4.0, and the spread sum's comparison differs.
  • All 50 ignored tests pass under scripts/gates.sh.

Not covered

  • Scores are of slots. A link named for a whole array (pop -> picked for picked = pop[i]) is reported as having no slot.
  • Only link scores are compared; loop scores are products of them. The generated side runs in discovery mode, which scores every link.
  • Conveyor and queue models take no part in LTM, and a model that does not compile is skipped.
  • Shapes found off in small models we built, recorded in the tests and not fixed here: an array read twice in one equation (ltm: link score is split when an equation reads one element twice #1061), a computed subscript (ltm: reducer read through a variable index scores every row +/-1 #1042 is the reducer form), a row's weighted sum 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.

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T01:43:25.615626Z 98edabf PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.25468% with 60 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.05%. Comparing base (a21e27d) to head (d74aa2b).

Files with missing lines Patch % Lines
src/simlin-engine/src/ltm_replay_compare.rs 94.35% 39 Missing ⚠️
src/simlin-engine/src/ltm_replay.rs 97.54% 21 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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()?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +355 to +359
let slots = plain
.offsets
.iter()
.map(|(name, &slot)| (name.as_str().to_string(), slot))
.collect();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +934 to +936
for (i, first) in edges.iter().enumerate() {
if !is_variable(first.from) || !is_active(side.series(i)) {
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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.
@bpowers
bpowers merged commit 65e1635 into main Nov 25, 2026
15 of 16 checks passed
@bpowers
bpowers deleted the ltm-oracle branch November 25, 2026 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant