-
Notifications
You must be signed in to change notification settings - Fork 25
Description
After implementing initial support for Stella/XMILE models (see #468), there are still two test models that aren't yet working with the XMILE backend in SDE's compiler (arrays.stmx and allocate.stmx).
Almost everything in the arrays model is handled correctly by the XMILE backend, but SDE's compiler does not yet support the Stella-style subscript mapping that is demonstrated in one place in the arrays.stmx model).
The arrays.stmx model uses the following approach for mapping DimA to DimB:
<aux name="dim ab map">
<dimensions><dim name="DimB"/></dimensions>
<eqn>DimB</eqn>
</aux>And references it in expressions like:
<eqn>inputA[dim_ab_map]*10</eqn>This is different from the approach taken by Vensim, and SDE's compiler doesn't yet accept a variable in subscript position. Supporting this would take a bit of work so I'm splitting this into a separate issue that can be tackled by someone after the initial XMILE work is merged.
You can run the test with the XMILE backend as follows:
$ INPUT_FORMAT=stmx ./tests/modeltests arrays
Testing the arrays model
Converting arrays.csv to DAT format
ERROR: undefined hasMapping fromSubscript : '_dim_ab_map'
TypeError: Cannot read properties of undefined (reading 'mappings')
at hasMapping (file://.../packages/compile/src/_shared/subscript.js:188:15)
at file://.../packages/compile/src/model/read-equations.js:1092:61
at Array.findIndex (<anonymous>)
at resolveRhsSubOrDim (file://.../packages/compile/src/model/read-equations.js:1092:39)
at file://.../packages/compile/src/model/read-equations.js:1022:53
at Array.map (<anonymous>)
at expandedRefIdsForVar (file://.../packages/compile/src/model/read-equations.js:1022:37)
at visitVariableRef (file://.../packages/compile/src/model/read-equations.js:318:26)
at visitExpr (file://.../packages/compile/src/model/read-equations.js:237:7)
at visitExpr (file://.../packages/compile/src/model/read-equations.js:245:7)
I asked Claude Opus 4.5 to summarize how Stella-style mapping (which we don't yet support) compares to Vensim's (which we do support). See analysis below.
Details
Symptom
ERROR: undefined hasMapping fromSubscript : '_dim_ab_map'
TypeError: Cannot read properties of undefined (reading 'mappings')
Root Cause
The arrays.stmx model uses Vensim-style subscript mapping patterns:
DimB ```And references it in expressions like:
<eqn>inputA[dim_ab_map]*10</eqn>The problem:
dim ab mapis parsed as a regular variable, not a subscript dimension- When the compiler tries to resolve
dim_ab_mapas a subscript, it doesn't exist hasMapping()receivesundefinedand crashes trying to access.mappings
Proposed Fix
Option A: Implement XMILE Subscript Mapping Support
Research how XMILE represents dimension mappings and implement parsing support. This may require:
- Understanding XMILE's mapping syntax (if it exists)
- Modifying
parse-xmile-dimension-def.tsto populatesubscriptMappings
Option B: Handle Variables as Subscript References
If XMILE uses variables to represent mappings (like the dim ab map aux variable):
- Detect when a subscript reference is actually a variable name
- Evaluate the variable to get the actual subscript value
- This is more complex as it involves runtime subscript resolution