When a spec.json file is used to expose a subset of output variables, only those specified variables can be accessed as outputs. For a testing tool we are working on internally, we would like to be able to inspect the data for any variable in the model, not just the ones exposed as outputs. The En-ROADS model uses thousands of variables; if we listed them all as outputs, it would use a lot of memory and would slow down the model. It would be preferable to have a way at runtime to select the variables for which to capture data into the output buffer.
I'm envisioning a few parts to this:
-
Add a new sde generate --listjson option that outputs a JSON file containing information about all variables and subscripts used in the model. (This would also be useful for a dependency tree tracking tool that we developed internally.)
-
Accept a new outputIndices buffer parameter:
void runModelWithBuffers(double* inputs, double* outputs, int32_t* outputIndices) {
- Generate a new
storeOutput function that includes a big switch statement, which will select the output (and subscripts) by index based on the values from the outputIndices buffer:
void storeOutput(size_t varIndex, size_t subIndex0, size_t subIndex1, size_t subIndex2) {
#define USE_OUTPUT_INDICES 0
#if USE_OUTPUT_INDICES
switch (varIndex) {
case 1:
outputVar(_a);
break;
case 2:
outputVar(_b);
break;
case 3:
outputVar(_c[subIndex0][subIndex1]);
break;
// ...
default:
break;
}
#end
}
The flag would be set to 0 by default so that there would be no impact on size/speed unless you opt-in to use this new output mode.
Things to revisit before finalizing this work:
When a
spec.jsonfile is used to expose a subset of output variables, only those specified variables can be accessed as outputs. For a testing tool we are working on internally, we would like to be able to inspect the data for any variable in the model, not just the ones exposed as outputs. The En-ROADS model uses thousands of variables; if we listed them all as outputs, it would use a lot of memory and would slow down the model. It would be preferable to have a way at runtime to select the variables for which to capture data into the output buffer.I'm envisioning a few parts to this:
Add a new
sde generate --listjsonoption that outputs a JSON file containing information about all variables and subscripts used in the model. (This would also be useful for a dependency tree tracking tool that we developed internally.)Accept a new
outputIndicesbuffer parameter:storeOutputfunction that includes a big switch statement, which will select the output (and subscripts) by index based on the values from theoutputIndicesbuffer:The flag would be set to 0 by default so that there would be no impact on size/speed unless you opt-in to use this new output mode.
Things to revisit before finalizing this work:
--gencand--listin the same command so that we don't have to runsdetwicestoreOutputif they have more than 3 dimensions (we only support variables with <= 3 dimensions for now)