Skip to content

engine: a circular definition through a module runs with wrong numbers #1095

Backlog

Description

@bpowers

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.
  • Actual, from simlin simulate (Euler, DT 1):
time  driver  reader  sub·input  sub·output
0     200     200     100        200
1     100     0       100        0
2     100     0       100        0

Why it matters

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

Activity

  1. added
    bug
    engine
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugengine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions