-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Problem
When writing arrayed variables back to MDL format, the MDL writer (src/simlin-engine/src/mdl/writer.rs, around line 785 in the Equation::Arrayed branch) emits individual resolved element equations instead of reconstructing the original GET DIRECT CONSTANTS/GET DIRECT DATA/GET DIRECT LOOKUPS call. This breaks MDL-to-MDL round-trip fidelity for models with arrayed external data references.
For example, an arrayed variable originally defined as:
variable name[DimA] = GET DIRECT CONSTANTS('file.xlsx', 'Sheet1', 'B2*', 'A2')
gets written back as individual element equations rather than the single GET DIRECT call.
Why it matters
- Round-trip fidelity: Models exported back to MDL lose their external data references, making the output structurally different from the input.
- Interoperability: Other tools (Vensim, SyntheSim) expect GET DIRECT calls and would not understand the expanded element-by-element form.
- Data locality: The GET DIRECT pattern is a deliberate design choice by modelers to keep data in external files; expanding it defeats that intent.
Components affected
src/simlin-engine/src/mdl/writer.rs(theEquation::Arrayedmatch arm)
Possible approach
The compat.data_source metadata is now preserved on arrayed variables (added in the close-array-gaps branch). The MDL writer's Equation::Arrayed branch should check whether compat.data_source is Some, and if so, reconstruct the original GET DIRECT ... expression from the DataSource fields (kind, file, tab_or_delimiter, row_or_col, cell) instead of emitting per-element equations.
Context
Identified during the close-array-gaps branch work. Related but distinct from:
- Add protobuf support for EXCEPT equations, element-level dimension mappings, and DataSource metadata #341 (protobuf serialization of DataSource metadata)
- Add XMILE support for EXCEPT equations, element-level dimension mappings, and DataSource metadata #342 (XMILE serialization of DataSource metadata)
- engine: directdata/directconst/directlookups/directsubs blocks 4 simulation tests #348 (runtime GET DIRECT simulation support)