Skip to content

Catch EMS variables initialized after reference, follow-up#11551

Draft
joseph-robertson wants to merge 11 commits intodevelopfrom
fix-ems-var-init-after-ref2
Draft

Catch EMS variables initialized after reference, follow-up#11551
joseph-robertson wants to merge 11 commits intodevelopfrom
fix-ems-var-init-after-ref2

Conversation

@joseph-robertson
Copy link
Copy Markdown
Collaborator

Pull request overview

Description of the purpose of this PR

Pull Request Author

  • Title of PR should be user-synopsis style (clearly understandable in a standalone changelog context)
  • Label the PR with at least one of: Defect, Refactoring, NewFeature, Performance, and/or DoNoPublish
  • Pull requests that impact EnergyPlus code must also include unit tests to cover enhancement or defect repair
  • Author should provide a "walkthrough" of relevant code changes using a GitHub code review comment process
  • If any diffs are expected, author must demonstrate they are justified using plots and descriptions
  • If changes fix a defect, the fix should be demonstrated in plots and descriptions
  • If any defect files are updated to a more recent version, upload new versions here or on DevSupport
  • If IDD requires transition, transition source, rules, ExpandObjects, and IDFs must be updated, and add IDDChange label
  • If structural output changes, add to output rules file and add OutputChange label
  • If adding/removing any LaTeX docs or figures, update that document's CMakeLists file dependencies
  • If adding/removing any output files (e.g., eplustbl.*)
    • Update ..\scripts\Epl-run.bat
    • Update ..\scripts\RunEPlus.bat
    • Update ..\src\EPLaunch\ MainModule.bas, epl-ui.frm, and epl.vbp (VersionComments)
    • Update ...github\workflows\energyplus.py

Reviewer

  • Perform a Code Review on GitHub
  • If branch is behind develop, merge develop and build locally to check for side effects of the merge
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified
  • Check that performance is not impacted (CI Linux results include performance check)
  • Run Unit Test(s) locally
  • Check any new function arguments for performance impacts
  • Verify IDF naming conventions and styles, memos and notes and defaults
  • If new idf included, locally check the err file and other outputs

@joseph-robertson joseph-robertson self-assigned this Apr 27, 2026
@joseph-robertson joseph-robertson added the Defect Includes code to repair a defect in EnergyPlus label Apr 27, 2026
@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on ubuntu-24.04 for commit 534ee08

Regression Summary
  • ESO Small Diffs: 705
  • Table Small Diffs: 391
  • EDD: 22
  • MTR Small Diffs: 523
  • Table String Diffs: 177
  • EIO: 397
  • JSON Small Diffs: 2
  • ZSZ Small Diffs: 72
  • Table Big Diffs: 37
  • ERR: 22
  • MTR Big Diffs: 3
  • ESO Big Diffs: 11
  • SSZ Small Diffs: 13
  • JSON Big Diffs: 2

@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on macos-14 for commit 6255180

Regression Summary
  • EDD: 21
  • ERR: 12
  • EIO: 1
  • ESO Big Diffs: 1
  • MTR Big Diffs: 1
  • Table Big Diffs: 1
  • Table String Diffs: 1

@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on macos-14 for commit 6e33a44

Regression Summary
  • EDD: 21
  • ERR: 12
  • EIO: 1
  • ESO Big Diffs: 1
  • MTR Big Diffs: 1
  • Table Big Diffs: 1
  • Table String Diffs: 1

@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on ubuntu-24.04 for commit 6255180

Regression Summary
  • EDD: 22
  • ERR: 12
  • EIO: 1
  • ESO Big Diffs: 1
  • MTR Big Diffs: 1
  • Table Big Diffs: 1
  • Table String Diffs: 1

@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on macos-14 for commit 534ee08

Regression Summary
  • EDD: 21
  • ERR: 12
  • EIO: 1
  • ESO Big Diffs: 1
  • MTR Big Diffs: 1
  • Table Big Diffs: 1
  • Table String Diffs: 1

@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on ubuntu-24.04 for commit 6e33a44

Regression Summary
  • EDD: 22
  • ERR: 12
  • EIO: 1
  • ESO Big Diffs: 1
  • MTR Big Diffs: 1
  • Table Big Diffs: 1
  • Table String Diffs: 1


} else if (thisOperand.Type == Value::Variable) {
auto const &thisErlVar = state.dataRuntimeLang->ErlVariable(thisOperand.Variable);
auto &thisErlVar = state.dataRuntimeLang->ErlVariable(thisOperand.Variable);
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.

Remove const since we may be updating Value.SetupInit.

Comment on lines -77658 to -77693
EnergyManagementSystem:GlobalVariable,
A, !- Erl Variable 1 Name
B, !- Erl Variable 2 Name
C, !- Erl Variable 3 Name
D, !- <none>
E, !- <none>
F, !- <none>
G, !- <none>
H, !- <none>
I, !- <none>
J, !- <none>
K, !- <none>
L, !- <none>
M, !- <none>
N, !- <none>
O, !- <none>
P, !- <none>
Q, !- <none>
R, !- <none>
S, !- <none>
T, !- <none>
U, !- <none>
V, !- <none>
W, !- <none>
X, !- <none>
Y, !- <none>
Z, !- <none>
AA, !- <none>
BB, !- <none>
CC, !- <none>
DD, !- <none>
EE, !- <none>
FF, !- <none>
GG, !- <none>
HH, !- <none>
II; !- <none>
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.

This reverts the IDF additions from #11409.

Comment on lines -7788 to -7791
EnergyManagementSystem:GlobalVariable,
Qducts, !- Erl Variable 1 Name
Qsupply, !- Erl Variable 2 Name
Qexhaust; !- Erl Variable 3 Name
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.

This reverts the IDF additions from #11409.

Comment thread testfiles/_ResidentialBase.idf Outdated
Comment on lines +7788 to +7798
EnergyManagementSystem:Program,
init, !- Name
Set CENTRAL_AC_AND_FURNACE_AIRLOOP_0_DUCTIMBALLKSUPFANEQUIVDZ = 0.0, !- <none>
Set CENTRAL_AC_AND_FURNACE_AIRLOOP_0_DUCTIMBALLKEXHFANEQUIVDZ = 0.0, !- <none>
Set CENTRAL_AC_AND_FURNACE_AIRLOOP_0_DUCTIMBALLKSUPFANEQUIVCOND = 0.0,
Set CENTRAL_AC_AND_FURNACE_AIRLOOP_0_DUCTIMBALLKEXHFANEQUIVCOND = 0.0;

EnergyManagementSystem:ProgramCallingManager,
init calling manager, !- Name
BeginNewEnvironment, !- EnergyPlus Model Calling Point
init; !- Program Name 1
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.

This fixes the legitimate error that exists in the EMS programs.

Comment on lines -8069 to -8070
DeltaT, !- Erl Variable 2 Name
ratioT, !- Erl Variable 3 Name
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.

This reverts the IDF additions from #11409.

Comment thread testfiles/RetailPackagedTESCoil.idf Outdated
Comment on lines +915 to +919
if (!state.dataGlobal->DoingSizing) {
cEnvHeader = " During Setup, Environment=";
} else {
cEnvHeader = " During Setup & Sizing, Environment=";
}
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.

This is entered during SetupSimulation.

ReturnValue.Error = "EvaluateExpression: Variable = '" + thisErlVar.Name + "' used in expression has not been initialized!";
// Use SetupInit in BeginEnvrnInitializeRuntimeLanguage for "un-initializing" Erl variables that may have been
// initialized to zero during setup. This can happen since SetupSimulation does not call BeginNewEnvironment.
thisErlVar.Value.SetupInit = false;
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.

Revert the change from #11409, and instead just add this single line.

Comment on lines +314 to +316
if (!state.dataRuntimeLang->ErlVariable(ErlVariableNum).Value.SetupInit) {
state.dataRuntimeLang->ErlVariable(ErlVariableNum).Value.initialized = false;
}
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.

Right before BeginNewEnvironment, "un-initialize" any Erl variables that had originally hit the EvaluateExpression: Variable = 'xyz' used in expression has not been initialized! error. If BeginNewEnvironment initializes them, then initialized is set back to true and we're good; if it doesn't, or there are other legitimate Erl variable initialization errors, the EvaluateExpression ... will throw.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refines EMS runtime diagnostics and initialization behavior to better catch “variable used before initialization” cases and to make EDD/trace timing labels distinguish SetupSimulation from Warmup.

Changes:

  • Add SetupFlag to tag SetupSimulation timesteps and use it in EMS trace + timestamped error outputs (“During Setup” vs “During Warmup”).
  • Add SetupInit tracking on Erl values to support re-initialization behavior across environments when uninitialized-variable errors occur.
  • Update several test IDFs to avoid/clean up EMS initialization and variable declarations.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
testfiles/_ResidentialBase.idf Adds a BeginNewEnvironment EMS init program to pre-initialize specific duct imbalance variables.
testfiles/RetailPackagedTESCoil.idf Adjusts EMS initialization and global variable declarations for the roof microclimate EMS.
testfiles/HospitalBaselineReheatReportEMS.idf Removes a large block of temporary EMS global variable declarations (A..II).
src/EnergyPlus/UtilityRoutines.cc Updates timestamp headers to label “During Setup” when applicable.
src/EnergyPlus/SimulationManager.cc Sets/clears the new SetupFlag around SetupSimulation.
src/EnergyPlus/RuntimeLanguageProcessor.cc Updates EMS trace timing strings and Erl variable/environment re-init behavior; refines uninitialized-variable handling.
src/EnergyPlus/DataRuntimeLanguage.hh Adds SetupInit to ErlValueType and updates related constructors/defaults.
src/EnergyPlus/DataGlobals.hh Adds SetupFlag global state.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread testfiles/RetailPackagedTESCoil.idf Outdated
Comment on lines +7952 to +7953
InitializeParameters, !- Name
Set Troof = 0.0,
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

InitializeParameters is called every timestep via the Model Flat Roof Microclimate ProgramCallingManager (BeginTimestepBeforePredictor). Adding Set Troof = 0.0 here resets Troof each timestep, which changes the microclimate algorithm because CalcBouyancyTerms uses Troof earlier in the same timestep. If the goal is only to avoid an uninitialized-variable error on the very first call, initialize Troof once at BeginNewEnvironment (or with a one-time init program/flag) rather than re-zeroing it every timestep.

Suggested change
InitializeParameters, !- Name
Set Troof = 0.0,
InitializeRoofTemperature, !- Name
Set Troof = 0.0; !- Program Line 1
EnergyManagementSystem:ProgramCallingManager,
InitializeRoofTemperatureOnBeginNewEnvironment, !- Name
BeginNewEnvironment, !- EnergyPlus Model Calling Point
InitializeRoofTemperature; !- Program Name 1
EnergyManagementSystem:Program,
InitializeParameters, !- Name

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

@joseph-robertson joseph-robertson Apr 28, 2026

Choose a reason for hiding this comment

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

44cb5eb

This fixes the legitimate uninitialized Troof error.

Comment thread testfiles/RetailPackagedTESCoil.idf Outdated
Comment thread src/EnergyPlus/DataRuntimeLanguage.hh Outdated
int TrendVarPointer; // index to match in TrendVariable structure
std::string Error; // holds error message string for reporting
bool initialized; // true if number value has been SET (ie. has been on LHS in SET expression)
bool SetupInit; // false if EvaluateExpression is thrown for Erl variable
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

The SetupInit field comment is unclear/inaccurate: EvaluateExpression doesn't "throw", it returns an error ErlValueType. Consider renaming the flag or rewording the comment to describe the actual behavior (e.g., that it's used to mark variables involved in an uninitialized-variable error so they can be treated as uninitialized at BeginNewEnvironment).

Suggested change
bool SetupInit; // false if EvaluateExpression is thrown for Erl variable
bool SetupInit; // false when marked by an uninitialized-variable evaluation error so it can be treated as uninitialized later

Copilot uses AI. Check for mistakes.
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.

@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on macos-14 for commit 8ffe344

Regression Summary
  • EDD: 21
  • ERR: 12

@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on ubuntu-24.04 for commit 8ffe344

Regression Summary
  • EDD: 22
  • ERR: 12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Defect Includes code to repair a defect in EnergyPlus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EDD output incorrectly labeled as Warmup Confusing EMS error in E+ 26.1

3 participants