Skip to content

MDL writer does not reconstruct GET DIRECT calls for arrayed variables #393

Description

@bpowers

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 (the Equation::Arrayed match 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:

Activity

  1. added
    engineIssues with the rust-based simulation engine
    compatCompatibility (XMILE, Vensim, etc) problem or enhancement
    on Jun 8, 2026
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

    compatCompatibility (XMILE, Vensim, etc) problem or enhancementengineIssues with the rust-based simulation engine

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions