Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions packages/compile/src/generate/code-gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ ${chunkedFunctions('evalLevels', Model.levelVars(), ' // Evaluate levels.')}
// Input/output section
//
function emitIOCode() {
let headerVars = outputAllVars ? expandedVarNames(true) : spec.outputVars
let headerVars = outputAllVars ? expandedVarNames(true) : spec.outputVarNames
let outputVars = outputAllVars ? expandedVarNames() : spec.outputVars
mode = 'io'
return `void setInputs(const char* inputData) {${inputsFromStringImpl()}}

void setInputsFromBuffer(double* inputData) {${inputsFromBufferImpl()}}

const char* getHeader() {
return "${R.map(varName => headerTitle(varName), headerVars).join('\\t')}";
return "${headerVars.join('\\t')}";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ToddFincannonEI: It looks like the build is failing due to a test failure when running the "allocate" model, but probably others are affected as well:
https://github.com/climateinteractive/SDEverywhere/actions/runs/8741036880/job/23986139008

The error points back to this line, which will fail if headerVars is undefined.

The issue is that there are two ways to specify output variables in the spec.json, you can either use outputVars (which takes C names) or outputVarNames (which takes Vensim names). In the case of outputVarNames, we convert to outputVars in this code in Model.read so that the rest of the code only needs to deal with outputVars (sort of a lowest common denominator):

  if (spec) {
    // If the spec file contains `input/outputVarNames` (with full Vensim variable names)
    // convert those to C names first.  Otherwise, use `input/outputNames` which are already
    // assumed to be valid C names.
    if (spec.inputVarNames) {
      spec.inputVars = R.map(cName, spec.inputVarNames)
    }
    if (spec.outputVarNames) {
      spec.outputVars = R.map(cName, spec.outputVarNames)
    }
    // Save the input vars locally so that they can be referenced by `isInputVar`.
    if (spec.inputVars) {
      inputVars = spec.inputVars
    }
  }

There are only 3 sample models that use the older outputVars form (allocate, arrays_cname, longeqns).

There are a few different ways we could solve this. I don't think it's imperative that we retain support for outputVars. For En-ROADS/C-ROADS we use the newer outputVarNames and all the new build stuff in SDE also uses that form, so I doubt anyone out in the wild is relying on outputVars. I think if we changed those 3 tests to use outputVarNames and effectively drop support for outputVars, then your proposed fix will be nearly correct (though I'd need to look through the rest of the code to see if any other changes are needed).

Let me know which approach you'd like to take.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I forgot to run the tests before submitting. EPS uses outputVarNames too, so your proposed solution looks good to me. I will change the tests and resubmit.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the only purpose of the arrays_cname test model is to test the outputVars C name support in spec files. I propose deleting this model, since we are dropping support for outputVars.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ToddFincannonEI: I agree with deleting arrays_cname, and also suggest renaming arrays_varname back to just arrays, but I'd be OK handling that myself in a separate PR after this one.

}

void storeOutputData() {
Expand Down Expand Up @@ -382,9 +382,6 @@ ${postStep}
}
return inputVars
}
function headerTitle(varName) {
return Model.vensimName(varName).replace(/"/g, '\\"')
}

return {
generate: generate
Expand Down