Abort GAMS run on coupling Rscript failure - #2426
Merged
Merged
Conversation
Use `execute.checkErrorLevel` for the Rscript calls that spawn R coupling scripts and then load their gdx output, in: - `15_climate/magicc7_ar6/postsolve.gms` (interim + impulse response) - `50_damages/KotzWenz/postsolve.gms` - `35_transport/edge_esm/presolve.gms` A bare `execute` does not abort, so a failed R call was silently ignored and GAMS continued to `Execute_Loadpoint` a possibly stale gdx from a prior iteration. `checkErrorLevel` makes GAMS abort on any non-zero exit
Contributor
|
Thank you, @tonnrueter. |
ahagen-pik
approved these changes
Aug 12, 2026
tonnrueter
marked this pull request as ready for review
August 12, 2026 15:28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose of this PR
A bare
execute "Rscript ..."stashes the child's exit code inerrorLevelbut then keeps running. If the R coupling call fails, GAMS continues on toexecute_load. The absence of an associated gdx-file is usually the point of failure then. However, in case the coupling script successfully ran at least once GAMS will pick up a stale gdx from a previous iteration.execute.checkErrorLevelmakes GAMS abort on any non-zero exit. This is applies to:15_climate/magicc7_ar6/postsolve.gms(interim + impulse response)35_transport/edge_esm/presolve.gms50_damages/KotzWenz/postsolve.gmsType of change
Indicate the items relevant for your PR by replacing ◻️ with ☑️.
Do not delete any lines. This makes it easier to understand which areas are affected by your changes and which are not.
Parts concerned
Impact
Checklist
Do not delete any line. Leave unfinished elements unchecked so others know how far along you are.
In the end all checkboxes must be ticked before you can merge.
make test) after my final commit and all tests pass (FAIL 0)remind2if and where it was neededforbiddenColumnNamesin readCheckScenarioConfig.R in case the PR leads to deprecated switchesCHANGELOG.mdcorrectly (added, changed, fixed, removed, input data/calibration)Further information (optional)
c.f. attached
mve.gms,coupling.Rinmve_checkErrorLevel.zipThis change is difficult to test in a REMIND run, here's a minimum viable experience. Load the PIAM module, place both files in the same folder
Usage
Expected outcomes
--guard--failoff1*** Status: Normal completion(+ a>>> STALE gdxwarning in the log)on1executecall (rc =/= 0);*** Status: Execution error(s); never loads0The
off/1runs a bareexecuteand lets a failed coupling call finishmve.gmswith**** Status: Normal completion on stale data, just logs a non-fatal>>> STALE gdxwarning. The end of the run looks fine, but isn't.on/1usesexecute.checkErrorLevel, logs*** Error at line 35: Execution halted: execute.checkErrorLevel returned with 1and finishes with*** Status: Execution error(s)`