Skip to content

Add support for capturing data for any variable at runtime #105

@chrispcampbell

Description

@chrispcampbell

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:

  1. 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.)

  2. Accept a new outputIndices buffer parameter:

void runModelWithBuffers(double* inputs, double* outputs, int32_t* outputIndices) {
  1. 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:

  • Allow --genc and --list in the same command so that we don't have to run sde twice
  • Exclude variables from storeOutput if they have more than 3 dimensions (we only support variables with <= 3 dimensions for now)

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions