Repository navigation
Description
LTM treats PREVIOUS() as state in the model being analyzed, but not inside a sub-model.
A model whose only state is a PREVIOUS lag inside a module is treated as having no state, so LTM produces no link or loop scores for it, and a pinned loop is dropped with no warning.
The loop list (model_detected_loops) still reports the loop, so the user sees a loop that never gets a score.
Example
main: driver = 1 + 0.5 * reader
sub = module lag (in = driver)
reader = sub.out
lag: out = PREVIOUS(in, 0)
This compiles and simulates as a one-step lag in a feedback loop.
Expected: one scored loop driver -> sub -> reader -> driver.
Actual: no LTM variables; a pin on {driver, sub, reader} is silently ignored.
With the same PREVIOUS written in main (reader = PREVIOUS(driver, 0)) the loop is scored.
Why it matters
Hits a user sub-model that implements a custom delay or smoothing with PREVIOUS instead of a stock.
No real model reported; the shape was found by reading the code.
The result is missing output, not wrong numbers.
Fix
Count module-internal lags as state on both surfaces together:
- the stateless check:
modules_carry_statewalks sub-models looking for stocks; also count a sub-model variable that reads something only throughPREVIOUS; - pin validation, which rejects a pinned loop with no state on it; it must see the lag inside the module's path too, or the loop becomes scored but unpinnable.
Changing only the first recreates a loop that is scored but cannot be pinned.
Pointers
src/simlin-engine/src/db/ltm/mod.rs:model_is_stateless,model_has_lagged_dt_deps,modules_carry_statesrc/simlin-engine/src/db/ltm/pinned.rs:cycle_has_lagged_edge- ltm: pins on a model with no stocks are dropped without a warning #772 (pins on a stateless model are dropped silently)
- ltm: relative score is always ±1 for loops whose state is in a module #774 (partitions for module-internal state; the same lag would also need a partition)
Activity
[-]ltm: module-internal PREVIOUS lag is uncounted state on every surface (lag-only sub-model loops unscored and unpinnable)[/-][+]ltm: PREVIOUS inside a sub-model is not counted as state[/+]