Repository navigation
Closed
Description
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) producesGraphicalFunctionKind::Extrapolatewhentable.extrapolateis set or the lookup is used viaLOOKUP EXTRAPOLATE/TABXLanywhere in the model. - The MDL writer (
src/simlin-engine/src/mdl/writer.rs,write_lookup_bodyat line 784 andwrite_lookupat line 816, plus their call sites at lines 1256/1266/1324/1333) only readsx_points/y_points/x_scale/y_scale.gf.kindis 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 EXTRAPOLATEextends 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, emitLOOKUP 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 isLOOKUP 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
- mdl: saving an arrayed GET DIRECT variable drops the GET DIRECT call #393 -- MDL writer does not reconstruct GET DIRECT calls for arrayed variables.
- The arrayed/per-element GF write path similarly ignores per-element comments and
Equation::Arrayed+compat.active_initial/data_sourcecombinations.
Discovery context
Identified during code review of the MDL writer's lookup path.
Metadata
Metadata
Assignees
Labels
No labels
Activity