Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include grouped and sorted arrays of variable instances in JSON listing #534

Open
chrispcampbell opened this issue Sep 15, 2024 · 0 comments

Comments

@chrispcampbell
Copy link
Contributor

As mentioned in #307, when diagnosing differences between in output between SDEverywhere and Vensim, it's helpful to be able to compare variables in the order that they are evaluated in the code generated by the SDEverywhere compiler.

Currently there are two limitations that make it difficult to do this sort of comparison:

  • The JSON listing contains variables in roughly the order of evaluation, but they are not exactly grouped according to the exact order of evaluation. Ideally we would have the variable instances grouped by type.
  • It is necessary to get the "subscript indices" needed to access these internal variables at runtime, but currently the only way to get these is to do some complex expansion of the dimensions and variables objects to derive the correct subscript indices. Ideally we would expose the specific details for each variable instance so that no post-processing is needed to access the information.

To address these limitations, I'm going to add a new varInstances field to the JSON listing that includes grouped arrays that are in evaluation order, one object per variable "instance", to make it relatively easy to request the data at runtime for a specific subscripted instance of a variable:

  "varInstances": {
    "constants": [],
    "lookupVars": [],
    "dataVars": [],
    "initVars": [],
    "levelVars": [],
    "auxVars": []
  }

Here's an example item:

      {
        "varId": "_g[_a1,_b2]",
        "varName": "g[A1,B2]",
        "varType": "const",
        "varIndex": 7,
        "subIndices": [
          0,
          1
        ]
      }

These groupings match the order of execution/evaluation in the generated model:

  • initConstants (vars of type const only, called for t=0 only)
  • initLookups (vars of type lookup only, called for t=0 only)
  • initData (vars of type data only, called for t=0 only)
  • initLevels (vars returned by initVars, a mix of initial, aux, and level vars, called for t=0 only)
  • evalLevels (vars of type level only; called before evalAux for t>0)
  • evalAux (vars of type aux only)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant