Skip to content

engine: MDL writer silently drops GraphicalFunction.kind (extrapolate/discrete lookups exported as plain continuous) #854

Closed

Description

@bpowers

Problem

The MDL writer ignores GraphicalFunction.kind when exporting lookups, so any non-continuous graphical function is written back as a plain continuous lookup -- a silent semantic change.

Concretely:

  • The MDL importer (src/simlin-engine/src/mdl/convert/variables.rs:1434-1439) produces GraphicalFunctionKind::Extrapolate when table.extrapolate is set or the lookup is used via LOOKUP EXTRAPOLATE / TABXL anywhere in the model.
  • The MDL writer (src/simlin-engine/src/mdl/writer.rs, write_lookup_body at line 784 and write_lookup at line 816, plus their call sites at lines 1256/1266/1324/1333) only reads x_points/y_points/x_scale/y_scale. gf.kind is never consulted anywhere in writer.rs.

Consequences on a round trip (or on XMILE -> MDL export of a discrete/extrapolate GF):

  • Extrapolate lookups become clamping lookups: behavior outside the table's x-range silently changes (Vensim's default LOOKUP clamps at the endpoints; LOOKUP EXTRAPOLATE extends the end segments linearly).
  • Discrete GFs (XMILE type="discrete") become interpolating lookups: behavior between points silently changes from stepwise to linear interpolation.

Why it matters

Silent simulation-semantics change on export (medium severity). A model that simulates one way in Simlin produces different results after export to Vensim, with no error or warning.

Component

src/simlin-engine/src/mdl/writer.rs (and the round-trip contract with src/simlin-engine/src/mdl/convert/variables.rs).

Possible approach

  • For GraphicalFunctionKind::Extrapolate, emit LOOKUP EXTRAPOLATE(<table>, <input>) call syntax at WITH LOOKUP call sites (and/or preserve whatever original spelling produced the extrapolate flag). Note the importer sets Extrapolate on the table when any use site is LOOKUP EXTRAPOLATE/TABXL, so the writer may need to emit extrapolating call syntax at the lookup's use sites rather than in the table definition itself.
  • For GraphicalFunctionKind::Discrete, Vensim has no direct WITH LOOKUP equivalent; the writer should at minimum error or emit a loud warning instead of silently changing interpolation semantics.
  • Add MDL round-trip tests covering extrapolate and discrete kinds (import LOOKUP EXTRAPOLATE -> write -> re-import -> assert kind preserved; XMILE discrete GF -> MDL export -> expect error/warning).

Related (distinct) known gaps

Discovery context

Identified during code review of the MDL writer's lookup path.

Activity

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