Skip to content

MDL writer EXCEPT round-trip changes behavior for excluded elements #350

Closed

Description

@bpowers

Problem

When writing an Equation::Arrayed with default_equation set (from Vensim's :EXCEPT: syntax), the MDL writer emits name[Dim...]=default_eq which applies the default equation to ALL dimension elements. Elements that were originally excluded via :EXCEPT: (and intentionally absent from the elements list, defaulting to 0 in simulation) incorrectly receive the default equation value after MDL round-tripping.

Example

  • Original MDL: x[DimA] :EXCEPT: [A2]= 5 (meaning A1=5, A2 defaults to 0)
  • Current writer output: x[DimA]= 5 followed by x[A1]= 5
  • After re-import: A1=5, A2=5 (behavior change -- A2 should still be 0)

Why it matters

This is a correctness bug. An MDL file written by Simlin and re-imported (by Simlin or by Vensim) will produce different simulation results for any model that uses :EXCEPT: syntax to exclude elements from a default equation. The excluded elements silently change from 0 to the default equation value, which can produce subtly wrong simulation output without any error or warning.

Component(s) affected

  • src/simlin-engine/src/mdl/writer.rs (lines 988-991)

Possible approaches

  1. Pass dimension definitions to the MDL writer so it can determine which elements are excluded and emit proper :EXCEPT: syntax in the output (e.g., x[DimA] :EXCEPT: [A2]= 5).

  2. Only write element-specific equations without the dimension-level default -- instead of emitting a dimension-level equation, emit individual element equations only for elements that appear in the elements list (e.g., x[A1]= 5). This avoids the need for :EXCEPT: syntax in the output but may produce more verbose MDL.

Approach 1 is more faithful to the original MDL representation. Approach 2 is simpler but changes the structure of the output.

Context

Identified during review of MDL full compatibility work on branch mdl-full-compat.

Related issues

Activity

  1. bpowers commented on Mar 8, 2026

    @bpowers
    OwnerAuthor

    Fixed in commit 9a72185 — MDL writer now emits :EXCEPT: syntax preserving original semantics.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions