You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
engine: systems writer reorders flows so the model simulates differently #400
Writing a systems model back out can reorder its flows so that it simulates differently when read again.
In the systems format, declaration order is meaningful: flows run last-declared first, and a rate that names another stock sees that stock after the outflows that have already run.
The writer gets this wrong when a rate reads a stock part-way through that stock's outflows.
Example
test/systems-format/cross_stock.txt:
A(10) > B @ 1
C(2) > D @ A
A > E @ 8
A > E runs first, so C > D reads A after that one drain (2), not after both (1).
The writer only records that C > D read a drained A, not how many of A's outflows had run, and places every A flow after it:
C(2) > D @ A
A(10) > B @ 1
A > E @ 8
Read back, C > D now sees A after both drains, so D gets 1 in the first round instead of 2.
This is from reading the code; it has not been run. cross_stock.txt is simulated against the Python systems package's output but is not in the round-trip tests, which only cover models without this pattern.
Why it matters
Affects to_systems (libsimlin's systems export) for any model where a rate reads a stock with two or more outflows.
Seen only in the constructed fixture above.
Fix
The translator names each drained value {stock}_drained_N, where N is how many of the stock's outflow variables had run (a conversion counts twice, for its waste flow).
Have the writer read N and require only the flows that had drained the stock to come after the reading flow, and the stock's other flows before it.
Then add cross_stock.txt to the round-trip tests.
changed the title [-]Systems format writer groups flows by source stock, breaking round-trip for cross-stock references[/-][+]engine: systems writer reorders flows so the model simulates differently[/+]on Oct 12, 2026
Activity
[-]Systems format writer groups flows by source stock, breaking round-trip for cross-stock references[/-][+]engine: systems writer reorders flows so the model simulates differently[/+]