diff --git a/main.gms b/main.gms index 3ff1951440..34e24621ed 100755 --- a/main.gms +++ b/main.gms @@ -817,7 +817,18 @@ parameter cm_permittradescen = 1; !! def = 1 !! regexp = [1-3] *' * (1): full permit trade (no restrictions) *' * (2): no permit trade (only domestic mitigation) -*' * (3): limited trade (certain percentage of GDP) +*' * (3): limited trade (certain percentage of permits) +*' +parameter + cm_permitTradeFinalYr "[TradingOnRef] Year until permit trading is allowed" +; + cm_permitTradeFinalYr = 2100; !! def = 2100 +*' + +parameter + cm_permitTradeRatio "[TradingOnRef] Share of emissions allowed for permit trading between 0 and 1" +; + cm_permitTradeRatio = 0.2; !! def = 0.2 *' parameter cm_rentdiscoil "[grades2poly] discount factor for the oil rent" diff --git a/modules/41_emicapregi/AbilityToPay/not_used.txt b/modules/41_emicapregi/AbilityToPay/not_used.txt index 009a793d19..3131f6520b 100644 --- a/modules/41_emicapregi/AbilityToPay/not_used.txt +++ b/modules/41_emicapregi/AbilityToPay/not_used.txt @@ -10,3 +10,5 @@ pm_gdp_gdx, parameter, ??? pm_budgetCO2eq, parameter, ??? vm_co2eqGlob,input,questionnaire cm_emiscen,input,questionnaire +cm_permitTradeFinalYr, input, ??? +cm_permitTradeRatio, input, ??? diff --git a/modules/41_emicapregi/CandC/not_used.txt b/modules/41_emicapregi/CandC/not_used.txt index e7413e8496..b3699610aa 100644 --- a/modules/41_emicapregi/CandC/not_used.txt +++ b/modules/41_emicapregi/CandC/not_used.txt @@ -13,3 +13,5 @@ pm_budgetCO2eq, parameter, ??? pm_shPPPMER,input,questionnaire pm_gdp,input,questionnaire cm_permittradescen,input,questionnaire +cm_permitTradeFinalYr, input, ??? +cm_permitTradeRatio, input, ??? diff --git a/modules/41_emicapregi/GDPint/not_used.txt b/modules/41_emicapregi/GDPint/not_used.txt index 22f931e772..4a39a3e606 100644 --- a/modules/41_emicapregi/GDPint/not_used.txt +++ b/modules/41_emicapregi/GDPint/not_used.txt @@ -13,3 +13,5 @@ pm_budgetCO2eq, parameter, ??? pm_shPPPMER,input,questionnaire pm_gdp,input,questionnaire cm_permittradescen,input,questionnaire +cm_permitTradeFinalYr, input, ??? +cm_permitTradeRatio, input, ??? diff --git a/modules/41_emicapregi/POPint/not_used.txt b/modules/41_emicapregi/POPint/not_used.txt index 1f082f491d..f3df1eafc1 100644 --- a/modules/41_emicapregi/POPint/not_used.txt +++ b/modules/41_emicapregi/POPint/not_used.txt @@ -11,3 +11,5 @@ vm_Mport,input,questionnaire pm_shPPPMER,input,questionnaire pm_gdp,input,questionnaire cm_permittradescen,input,questionnaire +cm_permitTradeFinalYr, input, ??? +cm_permitTradeRatio, input, ??? \ No newline at end of file diff --git a/modules/41_emicapregi/PerCapitaConvergence/not_used.txt b/modules/41_emicapregi/PerCapitaConvergence/not_used.txt index 78c95ab216..7f60d3e45d 100644 --- a/modules/41_emicapregi/PerCapitaConvergence/not_used.txt +++ b/modules/41_emicapregi/PerCapitaConvergence/not_used.txt @@ -12,3 +12,5 @@ vm_co2eqGlob,input,questionnaire pm_shPPPMER,input,questionnaire pm_gdp,input,questionnaire cm_emiscen,input,questionnaire +cm_permitTradeFinalYr, input, ??? +cm_permitTradeRatio, input, ??? \ No newline at end of file diff --git a/modules/41_emicapregi/TradingOnRef/bounds.gms b/modules/41_emicapregi/TradingOnRef/bounds.gms new file mode 100755 index 0000000000..b186a9c62b --- /dev/null +++ b/modules/41_emicapregi/TradingOnRef/bounds.gms @@ -0,0 +1,25 @@ +*** | (C) 2006-2024 Potsdam Institute for Climate Impact Research (PIK) +*** | authors, and contributors see CITATION.cff file. This file is part +*** | of REMIND and licensed under AGPL-3.0-or-later. Under Section 7 of +*** | AGPL-3.0, you are granted additional permissions described in the +*** | REMIND License Exception, version 1.0 (see LICENSE file). +*** | Contact: remind@pik-potsdam.de +*** SOF ./modules/41_emicapregi/TradingOnRef/bounds.gms +*** calculate emission cap in absolute terms +vm_perm.fx(t,regi) = p41_co2eq(t,regi); + +display vm_perm.up; + +*** deactivate permit trade +if(cm_permittradescen eq 2, +vm_Xport.fx(t,regi,"perm") = 0; +vm_Mport.fx(t,regi,"perm") = 0; +); +*** limited permit trade: limit in terms of share of allocated permits +if(cm_permittradescen eq 3, +vm_Xport.fx(t,regi,"perm") = 0; +vm_Xport.up(t,regi,"perm") $ (t.val > 2025 and t.val <= cm_permitTradeFinalYr) = cm_permitTradeRatio * abs(p41_co2eq(t,regi)); +vm_Mport.fx(t,regi,"perm") = 0; +vm_Mport.up(t,regi,"perm") $ (t.val > 2025 and t.val <= cm_permitTradeFinalYr) = cm_permitTradeRatio * abs(p41_co2eq(t,regi)); +); +*** EOF ./modules/41_emicapregi/TradingOnRef/bounds.gms diff --git a/modules/41_emicapregi/TradingOnRef/datainput.gms b/modules/41_emicapregi/TradingOnRef/datainput.gms new file mode 100755 index 0000000000..6ca8b2bb39 --- /dev/null +++ b/modules/41_emicapregi/TradingOnRef/datainput.gms @@ -0,0 +1,22 @@ +*** | (C) 2006-2024 Potsdam Institute for Climate Impact Research (PIK) +*** | authors, and contributors see CITATION.cff file. This file is part +*** | of REMIND and licensed under AGPL-3.0-or-later. Under Section 7 of +*** | AGPL-3.0, you are granted additional permissions described in the +*** | REMIND License Exception, version 1.0 (see LICENSE file). +*** | Contact: remind@pik-potsdam.de +*** SOF ./modules/41_emicapregi/TradingOnRef/datainput.gms + + +*** read in data of cost-optimal reference climate policy run +*' load CO2 emissions from reference run to assing the allocates permits + +Execute_Loadpoint "input_ref" p41_co2eq_in = vm_emiAll.l; +p41_co2eq(t, regi) = p41_co2eq_in(t,regi,"co2"); + + +*** initialization of pm_shPermit +pm_emicapglob(t) = sum(regi, p41_co2eq(t,regi)); +pm_shPerm(t,regi) = p41_co2eq(t,regi) / pm_emicapglob(t); + + +*** EOF ./modules/41_emicapregi/TradingOnRef/datainput.gms diff --git a/modules/41_emicapregi/TradingOnRef/declarations.gms b/modules/41_emicapregi/TradingOnRef/declarations.gms new file mode 100755 index 0000000000..37ad76b9ab --- /dev/null +++ b/modules/41_emicapregi/TradingOnRef/declarations.gms @@ -0,0 +1,20 @@ +*** | (C) 2006-2024 Potsdam Institute for Climate Impact Research (PIK) +*** | authors, and contributors see CITATION.cff file. This file is part +*** | of REMIND and licensed under AGPL-3.0-or-later. Under Section 7 of +*** | AGPL-3.0, you are granted additional permissions described in the +*** | REMIND License Exception, version 1.0 (see LICENSE file). +*** | Contact: remind@pik-potsdam.de +*** SOF ./modules/41_emicapregi/TradingOnRef/declarations.gms + +variables +vm_perm(ttot,all_regi) "emission allowances [GtCeq]" +; + +parameter +pm_shPerm(tall, all_regi) "emission permit shares [share]" +pm_emicapglob(tall) "global emission cap [GtC]" +p41_co2eq_in(ttot,all_regi,all_enty) "emissions from cost-optimal reference run" +p41_co2eq(ttot,all_regi) "emissions from cost-optimal reference run" +; + +*** EOF ./modules/41_emicapregi/TradingOnRef/declarations.gms diff --git a/modules/41_emicapregi/TradingOnRef/not_used.txt b/modules/41_emicapregi/TradingOnRef/not_used.txt new file mode 100755 index 0000000000..0580ec5176 --- /dev/null +++ b/modules/41_emicapregi/TradingOnRef/not_used.txt @@ -0,0 +1,18 @@ +# | (C) 2006-2024 Potsdam Institute for Climate Impact Research (PIK) +# | authors, and contributors see CITATION.cff file. This file is part +# | of REMIND and licensed under AGPL-3.0-or-later. Under Section 7 of +# | AGPL-3.0, you are granted additional permissions described in the +# | REMIND License Exception, version 1.0 (see LICENSE file). +# | Contact: remind@pik-potsdam.de +name, type, reason +sm_budgetCO2eqGlob, parameter, ??? +pm_gdp_gdx, parameter, ??? +pm_budgetCO2eq, parameter, ??? +vm_co2eqGlob,input,questionnaire +cm_emiscen,input,questionnaire +p41_precorrection_reduction, parameter, ??? +p41_correct_factor, parameter, ??? +pm_shPPPMER,input,questionnaire +pm_pop, parameter, ??? +pm_gdp,input,questionnaire +p41_co2eq_bau, parameter, ??? \ No newline at end of file diff --git a/modules/41_emicapregi/TradingOnRef/realization.gms b/modules/41_emicapregi/TradingOnRef/realization.gms new file mode 100755 index 0000000000..f1229f9770 --- /dev/null +++ b/modules/41_emicapregi/TradingOnRef/realization.gms @@ -0,0 +1,24 @@ +*** | (C) 2006-2024 Potsdam Institute for Climate Impact Research (PIK) +*** | authors, and contributors see CITATION.cff file. This file is part +*** | of REMIND and licensed under AGPL-3.0-or-later. Under Section 7 of +*** | AGPL-3.0, you are granted additional permissions described in the +*** | REMIND License Exception, version 1.0 (see LICENSE file). +*** | Contact: remind@pik-potsdam.de +*** SOF ./modules/41_emicapregi/TradingOnRef/realization.gms + +*' @description: Emission caps/permits are allocated according to a reference run +*' There are three different trade patterns currently available. +*' cm_permittradescen = 1; !! def = 1 !! regexp = [1-3] +*' * (1): full permit trade (no restrictions) +*' * (2): no permit trade (only domestic mitigation) +*' * (3): limited trade (certain percentage of regional allowances) +*' for limited trade use cm_pemittradefinalyr to set the final year until permit trading is allowed +*' with cm_pemittraderatio set the percentage of allowed trade + + +*####################### R SECTION START (PHASES) ############################## +$Ifi "%phase%" == "declarations" $include "./modules/41_emicapregi/TradingOnRef/declarations.gms" +$Ifi "%phase%" == "datainput" $include "./modules/41_emicapregi/TradingOnRef/datainput.gms" +$Ifi "%phase%" == "bounds" $include "./modules/41_emicapregi/TradingOnRef/bounds.gms" +*######################## R SECTION END (PHASES) ############################### +*** EOF ./modules/41_emicapregi/TradingOnRef/realization.gms diff --git a/modules/41_emicapregi/exog/not_used.txt b/modules/41_emicapregi/exog/not_used.txt index ad24171408..5e9156d090 100644 --- a/modules/41_emicapregi/exog/not_used.txt +++ b/modules/41_emicapregi/exog/not_used.txt @@ -16,3 +16,5 @@ cm_emiscen, switch, ??? pm_shPPPMER,input,questionnair pm_gdp,input,questionnaire cm_permittradescen,input,questionnaire +cm_permitTradeFinalYr, input, ??? +cm_permitTradeRatio, input, ??? diff --git a/modules/41_emicapregi/module.gms b/modules/41_emicapregi/module.gms index e8e89b5406..14ae2e4d0e 100644 --- a/modules/41_emicapregi/module.gms +++ b/modules/41_emicapregi/module.gms @@ -26,6 +26,7 @@ $Ifi "%emicapregi%" == "CandC" $include "./modules/41_emicapregi/CandC/realizati $Ifi "%emicapregi%" == "GDPint" $include "./modules/41_emicapregi/GDPint/realization.gms" $Ifi "%emicapregi%" == "POPint" $include "./modules/41_emicapregi/POPint/realization.gms" $Ifi "%emicapregi%" == "PerCapitaConvergence" $include "./modules/41_emicapregi/PerCapitaConvergence/realization.gms" +$Ifi "%emicapregi%" == "TradingOnRef" $include "./modules/41_emicapregi/TradingOnRef/realization.gms" $Ifi "%emicapregi%" == "exog" $include "./modules/41_emicapregi/exog/realization.gms" $Ifi "%emicapregi%" == "none" $include "./modules/41_emicapregi/none/realization.gms" *###################### R SECTION END (MODULETYPES) ############################ diff --git a/modules/41_emicapregi/none/not_used.txt b/modules/41_emicapregi/none/not_used.txt index f08fbec934..2ae02ab04f 100644 --- a/modules/41_emicapregi/none/not_used.txt +++ b/modules/41_emicapregi/none/not_used.txt @@ -14,3 +14,5 @@ cm_emiscen, switch, ??? pm_shPPPMER,input,questionnaire pm_gdp,input,questionnaire cm_permittradescen,input,questionnaire +cm_permitTradeFinalYr, input, ??? +cm_permitTradeRatio, input, ??? diff --git a/modules/80_optimization/nash/datainput.gms b/modules/80_optimization/nash/datainput.gms index 2588cb4055..c24ea97c16 100644 --- a/modules/80_optimization/nash/datainput.gms +++ b/modules/80_optimization/nash/datainput.gms @@ -37,7 +37,7 @@ cm_iteration_max = 100; ***convergences thresholds - very coarse p80_surplusMaxTolerance(tradePe) = 2* 1.5 * sm_EJ_2_TWa; !! convert EJ/yr into internal unit TWa p80_surplusMaxTolerance("good") = 2* 100/1000; !! in internal unit, trillion Dollar - p80_surplusMaxTolerance("perm") = 2* 300 * 12/44 / 1000; !! convert MtCO2eq into internal unit GtC + p80_surplusMaxTolerance("perm") = 3* 300 * 12/44 / 1000; !! convert MtCO2eq into internal unit GtC ); ); @@ -54,12 +54,12 @@ p80_etaXp("perm") = 0.2; *LB* parameter for Nash price algorithm between different iterations p80_etaLT(trade) = 0; -p80_etaLT("perm") = 0.03; +p80_etaLT("perm") = 0.04; ***These parameters are pretty sensitive. If market surpluses diverge, try higher values (up to 1). If surpluses oscillate, try lower values. p80_etaST(tradePe) = 0.3; p80_etaST("good") = 0.25; -p80_etaST("perm") = 0.3; +p80_etaST("perm") = 0.8; $ifi %banking% == "banking" p80_etaST("perm") = 0.2; !! in banking mode, the permit market reacts more sensitively. $ifi %emicapregi% == "budget" p80_etaST("perm") = 0.25; !! in budget mode, the permit market reacts more sensitively. diff --git a/modules/80_optimization/nash/equations.gms b/modules/80_optimization/nash/equations.gms index 8bc6b50d25..b7d46b2781 100644 --- a/modules/80_optimization/nash/equations.gms +++ b/modules/80_optimization/nash/equations.gms @@ -44,7 +44,7 @@ q80_costAdjNash(ttot,regi)$( ttot.val ge cm_startyear ) .. ; *' link between permit budget and emission budget -q80_budgetPermRestr(regi)$(cm_emiscen=6) .. +q80_budgetPermRestr(regi)$(cm_emiscen=6 OR cm_emiscen = 4) .. sum(ttot$(ttot.val lt sm_endBudgetCO2eq and ttot.val ge cm_startyear), pm_ts(ttot)* vm_perm(ttot,regi)) + sum(ttot$(ttot.val eq sm_endBudgetCO2eq),pm_ts(ttot)/2 * (vm_perm(ttot,regi))) =l= pm_budgetCO2eq(regi) - sum(ttot $((ttot.val ge 2005) and (ttot.val lt cm_startyear)), pm_ts(ttot)* vm_co2eq(ttot,regi)); diff --git a/modules/80_optimization/nash/preloop.gms b/modules/80_optimization/nash/preloop.gms index 9cf0c48be1..6600873cd9 100644 --- a/modules/80_optimization/nash/preloop.gms +++ b/modules/80_optimization/nash/preloop.gms @@ -61,11 +61,11 @@ loop(regi, if(p80_Mport0("2005",regi,tradePe) eq NA, p80_Mport0("2005",regi,tradePe) = 0); );); -*AJS* starting policy runs from permit prices that are all zero doesnot work. start from 30$ price path instead +*AJS* starting policy runs from permit prices that are all zero doesnot work. start from 49$ price path instead if((cm_emiscen ne 1) and (cm_emiscen ne 9) and (smax(t,pm_pvp(t,"perm"))) eq 0, loop(ttot$(ttot.val ge 2005), -***this is a 30$/tCo2eq in 2020 trajectory: - pm_pvp(ttot,"perm") = 0.11*1.05**(ttot.val-2020) * pm_pvp(ttot,"good"); +***this is a 49$/tCo2eq in 2020 trajectory ([T$/GtC]. To get $/tCO2, multiply with 272: 0.18 T$/GtC = 48.96 $/tCO2): + pm_pvp(ttot,"perm") = 0.18*1.05**(ttot.val-2020) * pm_pvp(ttot,"good"); ); pm_pvp("2005","perm")=0; ); diff --git a/renv/activate.R b/renv/activate.R index 1631cccdcd..b004f67ac6 100644 --- a/renv/activate.R +++ b/renv/activate.R @@ -3,7 +3,6 @@ local({ # the requested version of renv version <- "1.1.7" - attr(version, "md5") <- NULL attr(version, "sha") <- NULL # the project directory @@ -169,16 +168,6 @@ local({ if (quiet) return(invisible()) - # also check for config environment variables that should suppress messages - # https://github.com/rstudio/renv/issues/2214 - enabled <- Sys.getenv("RENV_CONFIG_STARTUP_QUIET", unset = NA) - if (!is.na(enabled) && tolower(enabled) %in% c("true", "1")) - return(invisible()) - - enabled <- Sys.getenv("RENV_CONFIG_SYNCHRONIZED_CHECK", unset = NA) - if (!is.na(enabled) && tolower(enabled) %in% c("false", "0")) - return(invisible()) - msg <- sprintf(fmt, ...) cat(msg, file = stdout(), sep = if (appendLF) "\n" else "") @@ -226,16 +215,6 @@ local({ section <- header(sprintf("Bootstrapping renv %s", friendly)) catf(section) - # try to install renv from cache - md5 <- attr(version, "md5", exact = TRUE) - if (length(md5)) { - pkgpath <- renv_bootstrap_find(version) - if (length(pkgpath) && file.exists(pkgpath)) { - file.copy(pkgpath, library, recursive = TRUE) - return(invisible()) - } - } - # attempt to download renv catf("- Downloading renv ... ", appendLF = FALSE) withCallingHandlers( @@ -261,6 +240,7 @@ local({ # add empty line to break up bootstrapping from normal output catf("") + return(invisible()) } @@ -277,20 +257,12 @@ local({ repos <- Sys.getenv("RENV_CONFIG_REPOS_OVERRIDE", unset = NA) if (!is.na(repos)) { - # split on ';' if present - parts <- strsplit(repos, ";", fixed = TRUE)[[1L]] - - # split into named repositories if present - idx <- regexpr("=", parts, fixed = TRUE) - keys <- substring(parts, 1L, idx - 1L) - vals <- substring(parts, idx + 1L) - names(vals) <- keys + # check for RSPM; if set, use a fallback repository for renv + rspm <- Sys.getenv("RSPM", unset = NA) + if (identical(rspm, repos)) + repos <- c(RSPM = rspm, CRAN = cran) - # if we have a single unnamed repository, call it CRAN - if (length(vals) == 1L && identical(keys, "")) - names(vals) <- "CRAN" - - return(vals) + return(repos) } @@ -539,51 +511,6 @@ local({ } - renv_bootstrap_find <- function(version) { - - path <- renv_bootstrap_find_cache(version) - if (length(path) && file.exists(path)) { - catf("- Using renv %s from global package cache", version) - return(path) - } - - } - - renv_bootstrap_find_cache <- function(version) { - - md5 <- attr(version, "md5", exact = TRUE) - if (is.null(md5)) - return() - - # infer path to renv cache - cache <- Sys.getenv("RENV_PATHS_CACHE", unset = "") - if (!nzchar(cache)) { - root <- Sys.getenv("RENV_PATHS_ROOT", unset = NA) - if (!is.na(root)) - cache <- file.path(root, "cache") - } - - if (!nzchar(cache)) { - tools <- asNamespace("tools") - if (is.function(tools$R_user_dir)) { - root <- tools$R_user_dir("renv", "cache") - cache <- file.path(root, "cache") - } - } - - # start completing path to cache - file.path( - cache, - renv_bootstrap_cache_version(), - renv_bootstrap_platform_prefix(), - "renv", - version, - md5, - "renv" - ) - - } - renv_bootstrap_download_tarball <- function(version) { # if the user has provided the path to a tarball via @@ -1052,7 +979,7 @@ local({ renv_bootstrap_validate_version_release <- function(version, description) { expected <- description[["Version"]] - is.character(expected) && identical(c(expected), c(version)) + is.character(expected) && identical(expected, version) } renv_bootstrap_hash_text <- function(text) { @@ -1254,18 +1181,6 @@ local({ } - renv_bootstrap_cache_version <- function() { - # NOTE: users should normally not override the cache version; - # this is provided just to make testing easier - Sys.getenv("RENV_CACHE_VERSION", unset = "v5") - } - - renv_bootstrap_cache_version_previous <- function() { - version <- renv_bootstrap_cache_version() - number <- as.integer(substring(version, 2L)) - paste("v", number - 1L, sep = "") - } - renv_json_read <- function(file = NULL, text = NULL) { jlerr <- NULL