We ran into a subtle issue with the En-ROADS model and the latest SDE where sde would fail in the case where a subscripted variable is only partially defined in the mdl file. For example:
Constant Partial 1 = 1
~~|
Constant Partial 2 = 2
~~|
Initial Partial[C1] =
INITIAL( Constant Partial 1 )
~~|
Initial Partial[C2] =
INITIAL( Constant Partial 2 )
~~|
Partial[C2] =
Initial Partial[C2]
~~|
In this case, technically Initial Partial[C1] is unused and doesn't need to be included in the compiled code, but the removeUnusedVariables function is currently conservative and doesn't eliminate unused subscript cases.
As currently written, one part of that function would skip over Initial Partial[C1] because it appears to be unreferenced, but then another part of the code would try to include all subscript variants of Initial Partial when emitting the code, and there would be a broken dependency, leading to this sort of error message:
ERROR: no var found for refId : '_constant_partial_1'
no var with refId for _constant_partial_1, referenced by _initial_partial[_c1]
ERROR: no var found for refId : '_constant_partial_1'
TypeError: Cannot read property 'varType' of undefined
The fix is to make both parts of the code equally conservative for now. Eventually we might be able to try a different approach that eliminates the unused subscripted variable, but for now, better to be safe.
We ran into a subtle issue with the En-ROADS model and the latest SDE where
sdewould fail in the case where a subscripted variable is only partially defined in the mdl file. For example:In this case, technically
Initial Partial[C1]is unused and doesn't need to be included in the compiled code, but theremoveUnusedVariablesfunction is currently conservative and doesn't eliminate unused subscript cases.As currently written, one part of that function would skip over
Initial Partial[C1]because it appears to be unreferenced, but then another part of the code would try to include all subscript variants ofInitial Partialwhen emitting the code, and there would be a broken dependency, leading to this sort of error message:The fix is to make both parts of the code equally conservative for now. Eventually we might be able to try a different approach that eliminates the unused subscripted variable, but for now, better to be safe.