Skip to content

systems format: stock max lost when stock has no incoming flows #408

@bpowers

Description

@bpowers

Description

The systems format translator only creates dest_capacity aux variables for stocks that are destinations of flows. If a stock has an explicit max but is not a destination of any flow, the max value is silently dropped during translation and cannot be reconstructed by the writer.

Concrete example: A(10, 20) > B @ 1 round-trips as A(10) > B @ Rate(1), losing max=20 on stock A.

Why it matters

This is a round-trip fidelity bug. Users who write a stock with a max and later read it back will get different semantics. The max constraint disappears entirely, which changes model behavior if flows are later added targeting that stock.

Component(s) affected

  • src/simlin-engine -- systems format translator (builds the intermediate project)
  • src/simlin-engine -- systems format writer (reconstructs text from the project)

Root cause

The translator creates dest_capacity aux variables by iterating over flows and looking at their destination stocks. Stocks that have a max but are never a flow destination are never visited, so their max is never stored in the translated project.

Possible approaches

  1. After processing flows, make a second pass over all stocks. For any stock with a max that did not get a dest_capacity aux (i.e., it is not a flow destination), store the max directly on the stock's range or create a standalone capacity marker.
  2. Have the writer check the original stock definitions for max values that are not represented by dest_capacity auxes.

Context

Identified during code review of PR #398 (systems-format branch).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions