Skip to content

Move MAgPIE coupling between the Nash iterations - #2249

Merged
dklein-pik merged 154 commits into
remindmodel:developfrom
dklein-pik:mergeRemindIntoRemMagNash
Dec 5, 2025
Merged

Move MAgPIE coupling between the Nash iterations#2249
dklein-pik merged 154 commits into
remindmodel:developfrom
dklein-pik:mergeRemindIntoRemMagNash

Conversation

@dklein-pik

@dklein-pik dklein-pik commented Nov 24, 2025

Copy link
Copy Markdown
Contributor

Purpose of this PR

This PR replaces the previous coupling, in which REMIND and MAgPIE run sequentially, with shifting the MAgPIE runs between the Nash iterations. start_bundle_coupled.R and start_coupled.R have been removed. Use start.R together with a scenario_config_magpie*.csv file (formerly known as scenario_config_coupled.csv) to activate the MAgPIE coupling, e.g.

Rscript start.R config/scenario_config_magpie.R

The new coupling is mainly perforemd in core/presolve.gms, by calling an external R script, that transfers the data of the latest Nash solution to MAgPIE, runs MAgPIE, and transfers the MAgPIE data to a magpieData.gdx, which is then read by GAMS.

If you need to continue runs to yield a better convergence, paste the path to a previous REMIND or MAgPIE report into the column continueFromHere in the scenario_config_magpie.csv and start the respective scenario.

Create convergence plots for individual runs with

Rscript output.R -> single -> plotRemMagNash.R

and for continued runs with

Rscript output.R -> comparison -> plotRemMagNash.R

Leftorvers

  • add test for new coupled mode (old test_20-coupled.R does not work with the new coupling and has been removed)
  • this requires: make empty_magpie work
  • update documentation in the tutorials folder
  • add path_gdx and friends to coupled config and evaluate in start.R
  • adapt configureCfg L58ff such that it finds the right precursor, i.e. it looks for C_ runs
  • make referencing another run by name work for path_mif_ghgprice_land
  • use short reporting for MAgPIE to save time, use full reporting in last iteration

Type of change

Parts concerned

  • ☑️ GAMS Code
  • ☑️ R-scripts
  • ◻️ Documentation (GAMS incode documentation, comments, tutorials)
  • ◻️ Input data / CES parameters
  • ◻️ Tests, CI/CD (continuous integration/deployment)
  • ☑️ Configuration (switches in main.gms, default.cfg, and scenario_config*.csv files)
  • ◻️ Other (please give a description)

Impact

  • ◻️ Bug fix
  • ☑️ Refactoring
  • ☑️ New feature
  • ◻️ Change of parameter values or input data (including CES parameters)
  • ◻️ Minor change (default scenarios show only small differences)
  • ◻️ Fundamental change of results of default scenarios

Checklist

  • I executed the automated model tests (make test) after my final commit and all tests pass (FAIL 0)
  • I adjusted the reporting in remind2 if and where it was needed
  • I adjusted the madrat packages (mrremind and other packages involved) for input data generation if and where it was needed
  • My code follows the coding etiquette
  • I explained my changes within the PR, particularly in hard-to-understand areas
  • I checked that the in-code documentation is up-to-date
  • I adjusted forbiddenColumnNames in readCheckScenarioConfig.R in case the PR leads to deprecated switches
  • I updated the CHANGELOG.md correctly (added, changed, fixed, removed, input data/calibration)

Further information (optional)

  • Runs with these changes are here: /p/tmp/dklein/remMagNash-Comp/
  • Comparison of results: old versus new coupling
    Results are almost identical. Differences are due to slightly different solution paths, since in the old coupling REMIND is running multiple times, each time restarting not exactly where it left (e.g. co2 prices in the initial Nash iterations), whereas in the new coupling the next Nash iteration continues exactly where the old left (except for the variables that are exchanged in the couping).
image

dklein-pik added 30 commits July 3, 2025 15:12
Add new realization 'magpie' to module '30_biomass' copying 'magpie_40' and renaming everything.
Any changes needed for the new coupling that are module-related (i.e. not in the core) will be done in the new module.
- updating biomass prices and biomass demand
- calculating shift factors for supply curves
Introduce new preliminary switch 'cm_MAgPIE_Nash' to activate biomass coupling while still using the old emissions
… it from a csv file (CSVread), since CSVread filled up the memory when it was called in the solve loop, leading to out of memory errors.

Added R script that writes the MAgPIE data into a gdx.
Add mapping from MAgPIE variables to REMIND parameters.
- core/preloop.gms -> core/presolve.gms
- 47_regipol/regiCarbonPrice/datainput.gms -> 47_regipol/regiCarbonPrice/presolve.gms
…f MAgPIE iterations sm_magpieIter to trigger the import of magpieData.gdx. Use coupling switch cm_MAgPIE_Nash only to activate the MAgPIE run itself.
Introduce decision and switch when to run MAgPIE
Load MAgPIE data only after MAgPIE has run at least once, otherwise use input data.
Set some switches only after MAgPIE has run at least one (macSwitch, n2obio).
@dklein-pik
dklein-pik requested review from LaviniaBaumstark and removed request for laurinks December 2, 2025 15:25

@LaviniaBaumstark LaviniaBaumstark left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks for all the comments and documentation!

Comment thread config/default.cfg
Comment thread core/datainput.gms
Comment thread core/declarations.gms
Comment thread core/presolve.gms Outdated
Comment thread core/presolve.gms
Comment thread main.gms Outdated
Comment thread modules/47_regipol/regiCarbonPrice/datainput.gms Outdated
Comment thread scripts/input/mag2rem.R Outdated
Comment thread start.R
Comment thread main.gms Outdated

@LaviniaBaumstark LaviniaBaumstark left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks!

@dklein-pik
dklein-pik merged commit c98b886 into remindmodel:develop Dec 5, 2025
2 checks passed
@dklein-pik dklein-pik mentioned this pull request Dec 11, 2025
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants