Skip to content

engine: non-negative stocks and flows are not enforced #545

Closed as not planned

Description

@bpowers

A stock or flow marked non-negative simulates exactly as if it were unmarked: the engine reads and saves the marking but never clamps the value.
A model that relies on it, such as an inventory that should stop at zero, can go negative.

Example

A stock inventory with initial value 10, a constant outflow of 5 per time unit, and <non_negative/> reaches -40 at time 10.
XMILE 1.0 section 4.2 says non-negative "is not directly supported by XMILE"; the marking exists "partly for documentation, partly to allow a vendor to invoke a macro to implement the functionality".
What Stella does exactly (clamp the stock, or limit its outflows in priority order) is unverified.

Why it matters

Seen in a real model: an AI-generated model checked by the validation battery (#1077) has three flows marked non-negative that go far below zero in its own run.
The validation battery and the save check flag a marked series that goes below zero and say the engine does not enforce the marking.
LTM cannot show the balancing loop a non-negative constraint creates, because the constraint is not in the simulation (docs/reference/ltm--loops-that-matter.md, the Workers example).

Fix

Keep not enforcing it, as already decided; the battery and save check make the gap visible.
If that changes: settle stock and flow semantics against real Stella output first, then clamp in the stock update.

Pointers

  • src/simlin-engine/src/tools/battery.rs, src/simlin-engine/src/save_check.rs: where the gap is reported
  • src/simlin-engine/src/variable.rs: non_negative on Variable::Stock and Variable::Var
  • src/simlin-engine/src/compiler/mod.rs, src/simlin-engine/src/compiler/symbolic.rs: notes on how a clamp would fit the stock update

Activity

  1. added
    engine
    on May 14, 2026
  2. added
    enhancement
    on Oct 12, 2026
  3. changed the title [-]engine: non_negative variable flag is parsed and stored but never enforced in the compiler or VM[/-] [+]engine: non-negative stocks and flows are not enforced[/+] on Oct 12, 2026
  4. added
    wontfix
    on Oct 12, 2026
  5. bpowers commented on Oct 12, 2026

    @bpowers
    OwnerAuthor

    Closing as won't fix.

    You decided on 2026-10-01 to keep not enforcing it. XMILE 4.2 says it 'is not directly supported by XMILE', and the battery and save check (#1077) now report the gap.

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

    engineenhancementwontfix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions