Repository navigation
Description
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]= 5followed byx[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
-
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). -
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
- Add protobuf support for EXCEPT equations, element-level dimension mappings, and DataSource metadata #341 (protobuf support for EXCEPT equations) -- covers serialization format, not writer correctness
- Add XMILE support for EXCEPT equations, element-level dimension mappings, and DataSource metadata #342 (XMILE support for EXCEPT equations) -- covers serialization format, not writer correctness
Activity
bpowers commentedon Mar 8, 2026
Fixed in commit 9a72185 — MDL writer now emits :EXCEPT: syntax preserving original semantics.