From a45a52226c0c2f0e12921b3abf0277b16a0e5c96 Mon Sep 17 00:00:00 2001
From: David Klein <dklein@pik-potsdam.de>
Date: Mon, 13 Jan 2020 09:58:14 +0100
Subject: [PATCH] Refactoring: -start scripts (part 5): renamed submit_run(cfg)
 into submit.R(cfg), deleted conopt files

---
 config/conopt3.op4                            | 10 --------
 config/conopt3.op5                            | 10 --------
 config/conopt3.op8                            | 10 --------
 config/conopt4.op2                            | 10 --------
 config/conopt4.op3                            | 10 --------
 config/conopt4.op4                            | 10 --------
 config/conopt4.op5                            | 10 --------
 config/conopt4.op8                            | 10 --------
 config/conopt4.op9                            | 10 --------
 config/conopt4.opt                            | 10 --------
 config/default.cfg                            |  7 +-----
 modules/80_optimization/negishi/solve.gms     | 24 +++++++++----------
 modules/80_optimization/testOneRegi/solve.gms |  3 +--
 scripts/start/prepare_and_run.R               | 23 ++++++------------
 scripts/start/{submit_run.R => submit.R}      |  2 +-
 start_coupled.R                               |  4 ++--
 start_new.R                                   |  4 ++--
 17 files changed, 26 insertions(+), 141 deletions(-)
 delete mode 100644 config/conopt3.op4
 delete mode 100644 config/conopt3.op5
 delete mode 100644 config/conopt3.op8
 delete mode 100644 config/conopt4.op2
 delete mode 100644 config/conopt4.op3
 delete mode 100644 config/conopt4.op4
 delete mode 100644 config/conopt4.op5
 delete mode 100644 config/conopt4.op8
 delete mode 100644 config/conopt4.op9
 delete mode 100644 config/conopt4.opt
 rename scripts/start/{submit_run.R => submit.R} (99%)

diff --git a/config/conopt3.op4 b/config/conopt3.op4
deleted file mode 100644
index ee300d6..0000000
--- a/config/conopt3.op4
+++ /dev/null
@@ -1,10 +0,0 @@
-rtnwtr = 1.e-7;
-lfnicr = 1000;
-lfstal = 1000;
-lfilog = 500;
-rtredg = 1.d-7;
-rvhess 100;
-lfdegi 500;
-lfnsup 7000;
-rtmins 0.0009765625;
-rtnwmi = 1.d-9;
diff --git a/config/conopt3.op5 b/config/conopt3.op5
deleted file mode 100644
index ee300d6..0000000
--- a/config/conopt3.op5
+++ /dev/null
@@ -1,10 +0,0 @@
-rtnwtr = 1.e-7;
-lfnicr = 1000;
-lfstal = 1000;
-lfilog = 500;
-rtredg = 1.d-7;
-rvhess 100;
-lfdegi 500;
-lfnsup 7000;
-rtmins 0.0009765625;
-rtnwmi = 1.d-9;
diff --git a/config/conopt3.op8 b/config/conopt3.op8
deleted file mode 100644
index b3cd021..0000000
--- a/config/conopt3.op8
+++ /dev/null
@@ -1,10 +0,0 @@
-rtnwtr = 1.e-7;
-lfnicr = 1000;
-lfstal = 1000;
-lfilog = 500;
-rtredg = 1.d-8;
-rvhess 100;
-lfdegi 500;
-lfnsup 7000;
-rtmins 0.0009765625;
-rtnwmi = 1.d-9;
diff --git a/config/conopt4.op2 b/config/conopt4.op2
deleted file mode 100644
index 0bd27e7..0000000
--- a/config/conopt4.op2
+++ /dev/null
@@ -1,10 +0,0 @@
-rtnwtr = 1.e-7;
-lfnicr = 1000;
-lfstal = 1000;
-lfilog = 500;
-rtredg = 1.d-6;
-rvhess 100;
-lfdegi 500;
-lfnsup 7000;
-rtmins 0.0009765625;
-rtnwmi = 1.d-9;
diff --git a/config/conopt4.op3 b/config/conopt4.op3
deleted file mode 100644
index ee300d6..0000000
--- a/config/conopt4.op3
+++ /dev/null
@@ -1,10 +0,0 @@
-rtnwtr = 1.e-7;
-lfnicr = 1000;
-lfstal = 1000;
-lfilog = 500;
-rtredg = 1.d-7;
-rvhess 100;
-lfdegi 500;
-lfnsup 7000;
-rtmins 0.0009765625;
-rtnwmi = 1.d-9;
diff --git a/config/conopt4.op4 b/config/conopt4.op4
deleted file mode 100644
index ee300d6..0000000
--- a/config/conopt4.op4
+++ /dev/null
@@ -1,10 +0,0 @@
-rtnwtr = 1.e-7;
-lfnicr = 1000;
-lfstal = 1000;
-lfilog = 500;
-rtredg = 1.d-7;
-rvhess 100;
-lfdegi 500;
-lfnsup 7000;
-rtmins 0.0009765625;
-rtnwmi = 1.d-9;
diff --git a/config/conopt4.op5 b/config/conopt4.op5
deleted file mode 100644
index ee300d6..0000000
--- a/config/conopt4.op5
+++ /dev/null
@@ -1,10 +0,0 @@
-rtnwtr = 1.e-7;
-lfnicr = 1000;
-lfstal = 1000;
-lfilog = 500;
-rtredg = 1.d-7;
-rvhess 100;
-lfdegi 500;
-lfnsup 7000;
-rtmins 0.0009765625;
-rtnwmi = 1.d-9;
diff --git a/config/conopt4.op8 b/config/conopt4.op8
deleted file mode 100644
index b3cd021..0000000
--- a/config/conopt4.op8
+++ /dev/null
@@ -1,10 +0,0 @@
-rtnwtr = 1.e-7;
-lfnicr = 1000;
-lfstal = 1000;
-lfilog = 500;
-rtredg = 1.d-8;
-rvhess 100;
-lfdegi 500;
-lfnsup 7000;
-rtmins 0.0009765625;
-rtnwmi = 1.d-9;
diff --git a/config/conopt4.op9 b/config/conopt4.op9
deleted file mode 100644
index f2a6e21..0000000
--- a/config/conopt4.op9
+++ /dev/null
@@ -1,10 +0,0 @@
-rtnwtr = 1.e-7;
-lfnicr = 1000;
-lfstal = 1000;
-lfilog = 500;
-rtredg = 1.d-9;
-rvhess 100;
-lfdegi 500;
-lfnsup 7000;
-rtmins 0.0009765625;
-rtnwmi = 1.d-9;
diff --git a/config/conopt4.opt b/config/conopt4.opt
deleted file mode 100644
index 81e2b17..0000000
--- a/config/conopt4.opt
+++ /dev/null
@@ -1,10 +0,0 @@
-rtnwtr = 1.e-7;
-lfnicr = 1000;
-lfstal = 1000;
-lfilog = 500;
-rtredg = 1.d-5;
-rvhess 100;
-lfdegi 500;
-lfnsup 7000;
-rtmins 0.0009765625;
-rtnwmi = 1.d-9;
diff --git a/config/default.cfg b/config/default.cfg
index 6a5e714..2331fe6 100755
--- a/config/default.cfg
+++ b/config/default.cfg
@@ -425,12 +425,7 @@ cfg$files2export <- list()
 cfg$files2export$start <- c("config/conopt3.opt",
                             "config/conopt3.op2",
                             "config/conopt3.op3",
-                            "config/conopt3.op4",
-                            "config/conopt3.op5",
-                            "config/conopt3.op8",
                             "config/conopt3.op9",
-                            "scripts/run_submit/submit.cmd",
-                            "scripts/run_submit/submit.R",
                             "scripts/run_submit/run_magicc.R",
                             "scripts/run_submit/run_magicc_temperatureImpulseResponse.R",
                             "scripts/run_submit/read_DAT_TOTAL_ANTHRO_RF.R",
@@ -439,7 +434,7 @@ cfg$files2export$start <- c("config/conopt3.opt",
                             "scripts/input/exoGAINSAirpollutants.R",
                             "config/input.gdx",
                             "config/input_ref.gdx",
-							"core/magicc",
+							              "core/magicc",
                             ".Rprofile",
                             "config/mappingEDGEtoREMINDsectors.csv")
 
diff --git a/modules/80_optimization/negishi/solve.gms b/modules/80_optimization/negishi/solve.gms
index 1178dd7..867a525 100644
--- a/modules/80_optimization/negishi/solve.gms
+++ b/modules/80_optimization/negishi/solve.gms
@@ -24,20 +24,20 @@ if(o_modelstat eq 2,
 
 IF(o_modelstat eq 2, 
 *AJS*2013-05* Default Negishi convergence scheme:
-    if (ord(iteration) eq 1, s80_cnptfile = 2);
-    if (ord(iteration) eq 2, s80_cnptfile = 3);
-    if (ord(iteration) eq 3, s80_cnptfile = 4);
-    if (ord(iteration) eq 4, s80_cnptfile = 5);
+    if (ord(iteration) eq 1, s80_cnptfile = 2); !! rtredg = 1.d-6
+    if (ord(iteration) eq 2, s80_cnptfile = 3); !! rtredg = 1.d-7
+    if (ord(iteration) eq 3, s80_cnptfile = 3); !! rtredg = 1.d-7
+    if (ord(iteration) eq 4, s80_cnptfile = 3); !! rtredg = 1.d-7
 *RP* Slower convergence scheme
 $IFTHEN.cm_SlowConvergence %cm_SlowConvergence% == "on"
-    if (ord(iteration) eq 1, s80_cnptfile = 1);
-    if (ord(iteration) eq 2, s80_cnptfile = 2);
-    if (ord(iteration) eq 3, s80_cnptfile = 2);
-    if (ord(iteration) eq 4, s80_cnptfile = 3);
-    if (ord(iteration) eq 5, s80_cnptfile = 3);
-    if (ord(iteration) eq 6, s80_cnptfile = 4);
-    if (ord(iteration) eq 7, s80_cnptfile = 4);
-    if (ord(iteration) eq 8, s80_cnptfile = 5);
+    if (ord(iteration) eq 1, s80_cnptfile = 1); !! rtredg = 1.d-5
+    if (ord(iteration) eq 2, s80_cnptfile = 2); !! rtredg = 1.d-6
+    if (ord(iteration) eq 3, s80_cnptfile = 2); !! rtredg = 1.d-6
+    if (ord(iteration) eq 4, s80_cnptfile = 3); !! rtredg = 1.d-7
+    if (ord(iteration) eq 5, s80_cnptfile = 3); !! rtredg = 1.d-7
+    if (ord(iteration) eq 6, s80_cnptfile = 3); !! rtredg = 1.d-7
+    if (ord(iteration) eq 7, s80_cnptfile = 3); !! rtredg = 1.d-7
+    if (ord(iteration) eq 8, s80_cnptfile = 3); !! rtredg = 1.d-7
 $ENDIF.cm_SlowConvergence
 );
 *** EOF ./modules/80_optimization/negishi/solve.gms
diff --git a/modules/80_optimization/testOneRegi/solve.gms b/modules/80_optimization/testOneRegi/solve.gms
index 870fece..d411b54 100644
--- a/modules/80_optimization/testOneRegi/solve.gms
+++ b/modules/80_optimization/testOneRegi/solve.gms
@@ -6,8 +6,7 @@
 *** |  Contact: remind@pik-potsdam.de
 *** SOF ./modules/80_optimization/testOneRegi/solve.gms
 
-$IFI %optimization% == "testOneRegi" s80_cnptfile = 9;
-hybrid.optfile = s80_cnptfile;
+hybrid.optfile = 9;
 
 ***reduce the problem to one region
 regi(all_regi) = NO;
diff --git a/scripts/start/prepare_and_run.R b/scripts/start/prepare_and_run.R
index 1337443..4bdeca0 100644
--- a/scripts/start/prepare_and_run.R
+++ b/scripts/start/prepare_and_run.R
@@ -688,6 +688,9 @@ prepare_and_run <- function() {
     }
   }
 
+  # Print REMIND runtime
+  cat("\n gams_runtime is ", gams_runtime, "\n")
+
   # Collect and submit run statistics to central data base
   lucode::runstatistics(file       = "runstatistics.rda",
                         modelstat  = readGDX(gdx="fulldata.gdx","o_modelstat", format="first_found"),
@@ -714,7 +717,7 @@ prepare_and_run <- function() {
   no_ref_runs <- identical(cfg$RunsUsingTHISgdxAsBAU,character(0)) | all(is.na(cfg$RunsUsingTHISgdxAsBAU)) | coupled_run
 
   if(!no_ref_runs) {
-    source("scripts/start/submit_run.R")
+    source("scripts/start/submit.R")
     # Save the current cfg settings into a different data object, so that they are not overwritten
     cfg_main <- cfg
     
@@ -740,7 +743,7 @@ prepare_and_run <- function() {
   } else {
     # Save the current cfg settings into a different data object, so that they are not overwritten
     cfg_main <- cfg
-    source("scripts/start/submit_run.R")
+    source("scripts/start/submit.R")
     
     for(run in seq(1,length(cfg_main$subsequentruns))){
       # for each of the subsequent runs, read in the cfg, ...
@@ -753,7 +756,7 @@ prepare_and_run <- function() {
       # Subsequent runs will be started in submit.R using the RData files written above 
       # after the current run has finished.
       cat("Starting subsequent run ",cfg_main$subsequentruns[run],"\n")
-      submit_run(cfg)
+      submit(cfg)
     }
     # Set cfg back to original
     cfg <- cfg_main
@@ -783,18 +786,6 @@ prepare_and_run <- function() {
 
   #=================== END - Subsequent runs ========================
     
-  # Reload the REMIND run configuration
-  load(cfg$val_workspace) 
-
-  # Print REMIND runtime
-  cat("\n gams_runtime is ", gams_runtime, "\n")
-
-  # Save runtime for REMIND validation
-  validation$technical$time$full.gms <- gams_runtime
-  save(validation, file = cfg$val_workspace)
-  # Remove unused variables
-  rm(gams_runtime, validation)
-
   # Copy important files into output_folder (after REMIND execution)
   for (file in cfg$files2export$end)
     file.copy(file, cfg$results_folder, overwrite = TRUE)
@@ -814,5 +805,5 @@ prepare_and_run <- function() {
   
 }
 
-# call prepare and run (always without cfg, because cfg is always read from results folder, where it has been copied by submit_run(cfg))
+# call prepare and run (always without cfg, because cfg is always read from results folder, where it has been copied by submit(cfg))
 prepare_and_run()
\ No newline at end of file
diff --git a/scripts/start/submit_run.R b/scripts/start/submit.R
similarity index 99%
rename from scripts/start/submit_run.R
rename to scripts/start/submit.R
index 3076d39..e100b46 100644
--- a/scripts/start/submit_run.R
+++ b/scripts/start/submit.R
@@ -13,7 +13,7 @@
 
 ############## Define function: runsubmit #########################
 
-submit_run <- function(cfg) {
+submit <- function(cfg) {
   
   # Create name of output folder and output folder itself
   date <- format(Sys.time(), "_%Y-%m-%d_%H.%M.%S")
diff --git a/start_coupled.R b/start_coupled.R
index aae8e91..63ca85f 100644
--- a/start_coupled.R
+++ b/start_coupled.R
@@ -104,7 +104,7 @@ start_coupled <- function(path_remind,path_magpie,cfg_rem,cfg_mag,runname,max_it
       cfg_rem$gms$cm_MAgPIE_coupling <- "off"
       cat("### COUPLING ### No MAgPIE report for REMIND input provided.\n")
       cat("### COUPLING ### REMIND will be startet in stand-alone mode with\n    ",runname,"\n    ",cfg_rem$results_folder,"\n")
-      outfolder_rem <- submit_run(cfg_rem)
+      outfolder_rem <- submit(cfg_rem)
     } else if (grepl(paste0("report.mif"),report)) { # if it is a MAgPIE report
       ######### S T A R T   R E M I N D   C O U P L E D ##############
       cfg_rem$gms$cm_MAgPIE_coupling <- "on"
@@ -114,7 +114,7 @@ start_coupled <- function(path_remind,path_magpie,cfg_rem,cfg_mag,runname,max_it
       mag_report_keep_in_mind <- report
       ####### START REMIND #######
       cfg_rem$pathToMagpieReport <- report
-      outfolder_rem <- submit_run(cfg_rem)
+      outfolder_rem <- submit(cfg_rem)
       ############################
     } else if (grepl("REMIND_generic_",report)) { # if it is a REMIND report
       ############### O M I T   R E M I N D  ###############################
diff --git a/start_new.R b/start_new.R
index e2a8c2d..457b54e 100644
--- a/start_new.R
+++ b/start_new.R
@@ -1,6 +1,6 @@
 library(lucode)
 
-source("scripts/start/submit_run.R")
+source("scripts/start/submit.R")
 
 #######################################################################
 ############### Select slurm partitiion ###############################
@@ -191,7 +191,7 @@ for (scen in rownames(scenarios)) {
   
   if (start_now){
    cat("Creating and starting: ",cfg$title,"\n")
-   submit_run(cfg)
+   submit(cfg)
    }
 }
   
-- 
GitLab