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: a circular definition through a module runs with wrong numbers #1095
A circular definition that passes through a module is not detected.
The model runs and returns numbers that depend on evaluation order.
The same equations without the module are refused.
Example
main: driver = 100 + reader*0.5
reader = sub.output
module sub, with its input connected to driver
sub: output = input*2
These have no solution: they reduce to driver = 100 + driver.
Expected: the error the flat version gives, circular_dependency -- 'driver' depends on itself.
It is a wrong answer with no error.
We have only seen it in a case we constructed, but any module with an output computed from an input, with no stock between them, can do it.
Fix
The cycle check treats a module instance as depending on nothing, so no loop can pass through one.
Give an instance a dependency from an output to an input when the sub-model computes that output from that input within the step.
That needs one reachability query per sub-model, and must leave loops through a SMOOTH or DELAY alone, since a stock breaks them.
Alternative: refuse every loop through a module unless the output read is a stock, which is simpler but rejects valid models.
Pointers
src/simlin-engine/src/db/dep_graph.rs: walk_successors ("A module is a sink in both phases") and the comment on ordering_edges, which notes that the cycle check cannot see such a loop
Activity