-
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).
The allocate test is failing because we haven't implemented support for Stella's ALLOCATE function. In theory the function should behave like Vensim's ALLOCATE AVAILABLE (which we do support in the Vensim backend for C code gen / runtime), but the parameters are passed differently in Stella's ALLOCATE function (see below for Claude's summary of the differences).
We should be able to make some small modifications to the equation reader and code gen to handle these differences, and then update the existing function in the C runtime (maybe split it into two variants to handle the different argument lists/approaches).
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 allocate
Testing the allocate model
Converting allocate.csv to DAT format
Error: Unhandled function '_ALLOCATE' in readEquations for 'shipments[region]'
at visitFunctionCall (file://.../packages/compile/src/model/read-equations.js:813:17)
at visitExpr (file://.../packages/compile/src/model/read-equations.js:265:7)
at readEquation (file://.../packages/compile/src/model/read-equations.js:186:9)
at file://.../packages/compile/src/model/model.js:360:5
at Array.forEach (<anonymous>)
at analyze (file://.../packages/compile/src/model/model.js:359:13)
at Object.read (file://.../packages/compile/src/model/model.js:187:3)
at Object.generate (file://.../packages/compile/src/generate/gen-code-c.js:28:11)
at generateC (file://.../packages/compile/src/generate/gen-code-c.js:11:43)
at generateCode (file://.../packages/compile/src/generate/gen-code.js:34:12)
I asked Claude Opus 4.5 to summarize the differences between the Stella and Vensim versions of these functions. See analysis below.
Click for Claude Summary/Plan
Symptom
Error: Unhandled function '_ALLOCATE' in readEquations for 'shipments[region]'
Root Cause
Critical Incompatibility: Stella's ALLOCATE function has a fundamentally different signature than Vensim's ALLOCATE AVAILABLE:
Vensim (3 parameters):
shipments[branch] = ALLOCATE AVAILABLE(demand[branch], priority[branch,ptype], supply available)
Stella (6 parameters):
<eqn>ALLOCATE(total_supply_available, region, demand, priority_vector[*,ppriority], priority_vector[region,pwidth], priority_vector[region,ptype])</eqn>Key differences:
- Stella has 6 parameters vs Vensim's 3
- Parameter order is different (Stella puts availability FIRST, Vensim puts it LAST)
- Stella explicitly names the dimension to iterate over
- Stella separates priority parameters (mean, width, type) instead of packing them in a 2D array
Current Implementation Status
- Vensim: Fully implemented
- Parsing in
read-equations.js(lines 478-481) - C code generation in
gen-expr.js(lines 855-928) - C runtime in
vensim.c(lines 408-504)
- Parsing in
- Stella: NOT implemented (4 test cases explicitly skipped in
read-equations-xmile.spec.ts)
Proposed Fix
Option A: Full Implementation (Recommended for Completeness)
- Add
case '_ALLOCATE':tovalidateStellaFunctionCall()inread-equations.js - Create parameter adapter to map Stella's 6-param signature to internal representation
- Either:
- Create new C runtime function for Stella's signature, OR
- Create wrapper that converts Stella params to Vensim format
Option B: Skip for Now
- Document incompatibility
- Keep tests skipped
- Focus on higher-priority functions first