From b665c5a068a5ce2c79e25ea500d132bd922ef651 Mon Sep 17 00:00:00 2001
From: dklein <dklein@pik-potsdam.de>
Date: Thu, 30 Jan 2020 15:24:42 +0100
Subject: [PATCH] MAgPIE coupling: move reading in the REMIND report from
 start_coupled.R to start_run() from MAgPIE

---
 start_bundle_coupled.R |  8 ++++----
 start_coupled.R        | 13 ++++---------
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/start_bundle_coupled.R b/start_bundle_coupled.R
index b6ffed3..9af2e41 100644
--- a/start_bundle_coupled.R
+++ b/start_bundle_coupled.R
@@ -15,14 +15,14 @@ path_magpie <- "/p/projects/piam/runs/coupled-magpie/"
 # If there are existing runs you would like to take the gdxes (REMIND) or reportings (REMIND or MAgPIE) from provide the path and name prefix here. 
 # Note: the sceanrio names have to be identical to the runs that are to be started. If they differ please provide the names of the old scenarios in the 
 # file that you read in below to path_settings_coupled
-path_remind_oldruns <- paste0(path_remind,"output-gams26/")
-path_magpie_oldruns <- paste0(path_magpie,"output-gams26/")
+path_remind_oldruns <- paste0(path_remind,"output-20200129/")
+path_magpie_oldruns <- paste0(path_magpie,"output-20200129/")
 
 # The scripts automatically adds a prefix (name of your remind path) to the scenario names. This is useful because it enables 
 # using the same MAgPIE and REMIND output folders to store results of coupled runs from multiple REMIND revisions (prevents double names)
 # If you want the script to find gdxs or reports of older runs as starting point for new runs please 
 # provide the prefix of the old run names so the script can find them.
-prefix_oldruns <-  "coupled-remind_" # "REMIND_" # "coupled-remind_" # 
+prefix_oldruns <-  "C_" # "REMIND_" # "coupled-remind_" # 
 
 # Paths to the files where scenarios are defined
 # path_settings_remind contains the detailed configuration of the REMIND scenarios
@@ -302,7 +302,7 @@ for(scen in common){
   }
 
   if (start_now){
-      if (!exists("test")) system(paste0("sbatch --qos=standby --job-name=",runname," --output=",runname,".log --mail-type=END --comment=REMIND-MAgPIE --tasks-per-node=",nr_of_regions," --wrap=\"Rscript start_coupled.R coupled_config=",runname,".RData\""))
+      if (!exists("test")) system(paste0("sbatch --qos=priority --job-name=",runname," --output=",runname,".log --mail-type=END --comment=REMIND-MAgPIE --tasks-per-node=",nr_of_regions," --wrap=\"Rscript start_coupled.R coupled_config=",runname,".RData\""))
       else cat("Test mode: run NOT submitted to the cluster\n")
   } else {
      cat(paste0("Run ",runname," will start after preceding run ",prefix_runname,settings_remind[scen,"path_gdx_ref"]," has finished\n"))
diff --git a/start_coupled.R b/start_coupled.R
index cea6775..1d74e97 100644
--- a/start_coupled.R
+++ b/start_coupled.R
@@ -171,15 +171,9 @@ start_coupled <- function(path_remind,path_magpie,cfg_rem,cfg_mag,runname,max_it
      cfg_mag$files2export$start <- .setgdxcopy(".gdx",cfg_mag$files2export$start,gdxlist)
     }
     
-    # delete "+" and "++" from variable names
-    rep <- read.report(report)
-    names(rep[[1]]) <- "MAgPIE"
-    rep[[1]][[1]] <- deletePlus(report[[1]][[1]])
-    #write.report(rep,"report.mif")
-    sceninreport <- names(rep) # report must only contain ONE scenario
-    cat("### COUPLING ### MAgPIE will be startet with\n    Report = ",report,"\n    Scenario used as input = ",sceninreport,"\n    Folder=",cfg_mag$results_folder,"\n")
+    cat("### COUPLING ### MAgPIE will be startet with\n    Report = ",report,"\n    Folder=",cfg_mag$results_folder,"\n")
     ########### START MAGPIE #############
-    outfolder_mag <- start_run(cfg_mag,report=rep,sceninreport=sceninreport,LU_pricing=LU_pricing,codeCheck=FALSE)
+    outfolder_mag <- start_run(cfg_mag,path_to_report=report,LU_pricing=LU_pricing,codeCheck=FALSE)
     ######################################
     cat("### COUPLING ### MAgPIE output was stored in ",outfolder_mag,"\n")
     report <- paste0(path_magpie,outfolder_mag,"/report.mif")
@@ -215,7 +209,7 @@ start_coupled <- function(path_remind,path_magpie,cfg_rem,cfg_mag,runname,max_it
   #start subsequent runs via sbatch
   for(run in cfg_rem$subsequentruns){
     cat("Submitting subsequent run",run,"\n")
-    system(paste0("sbatch --qos=standby --job-name=",run," --output=",run,".log --mail-type=END --comment=REMIND-MAgPIE --tasks-per-node=",nr_of_regions," --wrap=\"Rscript start_coupled.R coupled_config=C_",run,".RData\""))
+    system(paste0("sbatch --qos=priority --job-name=C_",run," --output=C_",run,".log --mail-type=END --comment=REMIND-MAgPIE --tasks-per-node=",nr_of_regions," --wrap=\"Rscript start_coupled.R coupled_config=C_",run,".RData\""))
   }
   
   # Read runtime of ALL coupled runs (not just the current scenario) and produce comparison pdf
@@ -225,6 +219,7 @@ start_coupled <- function(path_remind,path_magpie,cfg_rem,cfg_mag,runname,max_it
   runs <- findCoupledruns(resultsfolder=remindpath)
   ret  <- findIterations(runs,modelpath=c(remindpath,magpiepath),latest=FALSE)
   readRuntime(ret,plot=TRUE,coupled=TRUE)
+  unlink(c("runtime.log","runtime.out","runtime.rda"))
   
   # combine REMIND and MAgPIE reports of last coupling iteration (and REMIND water reporting if existing)
   report_rem <- paste0(path_remind,outfolder_rem,"/REMIND_generic_",cfg_rem$title,".mif")
-- 
GitLab