Skip to content

adjust variable = value regexp in manipulateConfig to avoid false positives in comments #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 6, 2024

Conversation

orichters
Copy link
Contributor

@orichters orichters commented Aug 5, 2024

  • Try to fix manipulateConfig: doesn't handle GAMS unquoted comments that include "=" sign properly #203
  • Running manipulateConfig() on REMIND's main.gms file (with the default settings read from that file) leads to the substitutions below. Any occurence of a switch name followed by = is substituted, leading to completely unreadable and misleading comments, and also leading to model fails.
  • I suggest to only replace variable = value constructions that show up at the beginning of the line, not anywhere.
  • I am not certain whether this creates any negative effects somewhere else – whether there are possible intended uses of replacing code in the middle of the line.
  • I first thought might cause problems here, but as this is no .gms file, this is not going into this part of the if-chain.
  • Also avoid that for the setglobal regexp, the number of spaces between the switch name and the value is changed.
269c269
< *' * (CMIP5): downscale GMT to regional temperature based on CMIP5 data (between iterations, no runtime impact). [Requires climate = off, cm_rcp_scen = none, iterative_target_adj = 9] curved convergence of CO2 prices between regions until cm_CO2priceRegConvEndYr; developed countries have linear path from 0 in 2010 through cm_co2_tax_2020 in 2020;
---
> *' * (CMIP5): downscale GMT to regional temperature based on CMIP5 data (between iterations, no runtime impact). [Requires climate = off; developed countries have linear path from 0 in 2010 through cm_co2_tax_2020 in 2020;
375,379c375,376
< *' * (exponential): [please use new diffExp2Lin with cm_co2_tax_spread = 1 and iterative_target_adj = 5 for exponential carbon pricing until end of century (without regional differentiation)] 4.5% exponential increase over time of the tax level in 2020 set via cm_co2_tax_2020 (combined with emiscen = 9 and cm_co2_tax_2020>0)
< *' * (expoLinear): 4.5% exponential increase until c_expoLinear_yearStart, transitioning into linear increase thereafter
< *' * (exogenous): carbon price is specified using an external input file or using the switch cm_regiExoPrice. Requires cm_emiscen = 9 and cm_iterative_target_adj = 0
< *' * (linear): [please use new diffLin2Lin with cm_co2_tax_spread = 1 and iterative_target_adj = 5 for linear carbon pricing until end of century (without regional differentiation)] linear increase over time of the tax level in 2020 set via cm_co2_tax_2020 (combined with emiscen = 9 and cm_co2_tax_2020>0)
< *' * (temperatureNotToExceed): [test and verify before using it!] Find the optimal carbon carbon tax (set cm_emiscen = 1, iterative_target_adj = 9] curved convergence of CO2 prices between regions until cm_CO2priceRegConvEndYr; developed countries have linear path from 0 in 2010 through cm_co2_tax_2020 in 2020;
---
> *' * (exponential): [please use new diffExp2Lin with cm_co2_tax_spread = 10' * (expoLinear): 4.5% exponential increase until c_expoLinear_yearStart, transitioning into linear increase thereafter
> *' * (exogenous): carbon price is specified using an external input file or using the switch cm_regiExoPrice. Requires cm_emiscen = 1' * (linear): [please use new diffLin2Lin with cm_co2_tax_spread = 10' * (temperatureNotToExceed): [test and verify before using it!] Find the optimal carbon carbon tax (set cm_emiscen = 1; developed countries have linear path from 0 in 2010 through cm_co2_tax_2020 in 2020;
1273,1274c1270
< *' *  ("GLO 0.005") reproduces c_ccsinjecratescen = 1
< *' *  ("GLO 0.00125, CAZ_regi 0.0045, CHA_regi 0.004, EUR_regi 0.0045, IND_regi 0.004, JPN_regi 0.002, USA_regi 0.002") "example that is taylored such that NDC goals are achieved without excessive CCS in a delayed transition scenario. Globally, 75% reduction, 10% reduction in CAZ etc. compared to reference case with c_ccsinjecratescen = 1"
---
> *' *  ("GLO 0.005") reproduces c_ccsinjecratescen = 1' *  ("GLO 0.00125, CAZ_regi 0.0045, CHA_regi 0.004, EUR_regi 0.0045, IND_regi 0.004, JPN_regi 0.002, USA_regi 0.002") "example that is taylored such that NDC goals are achieved without excessive CCS in a delayed transition scenario. Globally, 75% reduction, 10% reduction in CAZ etc. compared to reference case with c_ccsinjecratescen = 1"
1285c1281
< ***     cm_emiMktTarget = '2020.2050.EU27_regi.all.budget.netGHG_noBunkers 72, 2020.2050.DEU.all.year.netGHG_noBunkers 0.1'
---
> ***     cm_emiMktTarget = 'off'
1287c1283
< ***     cm_emiMktTarget = 'nzero'
---
> ***     cm_emiMktTarget = 'off'
1296c1292
< ***      cm_emiMktTarget_tolerance = 'GLO 0.004, DEU 0.01'. All regional emission targets will be considered converged if they have at most 0.4% of the target deviation, except for Germany that requires 1%.
---
> ***      cm_emiMktTarget_tolerance = 'GLO 0.01'. All regional emission targets will be considered converged if they have at most 0.4% of the target deviation, except for Germany that requires 1%.
1327,1328c1323
< ***   Example on how to use the switch with cm_implicitQttyTargetType = config:
< ***     cm_implicitQttyTarget  "2030.EU27_regi.tax.t.FE.all 1.03263"
---
> ***   Example on how to use the switch with cm_implicitQttyTargetType = config"2030.EU27_regi.tax.t.FE.all 1.03263"
1335,1336c1330
< ***   Example on how to use the switch with cm_implicitQttyTargetType = scenario:
< ***     cm_implicitQttyTarget  "EU27_RpEUEff,EU27_bio4"
---
> ***   Example on how to use the switch with cm_implicitQttyTargetType = config"EU27_RpEUEff,EU27_bio4"
1359c1353
< ***     cm_VREminShare = "2050.EUR_regi 0.7".
---
> ***     cm_VREminShare = "off".
1467c1461
< *** cm_SEtaxRampUpParam = "off" disables v21_tau_SE_tax
---
> *** cm_SEtaxRampUpParam = "GLO.elh2.a 0.2, GLO.elh2.b 20" disables v21_tau_SE_tax
1738c1732
< *** c_regi_nucscen              "regions to apply cm_nucscen to in case of cm_nucscen = 5 (no new nuclear investments), e.g. c_regi_nucscen <- "JPN,USA"
---
> *** c_regi_nucscen              "regions to apply cm_nucscen to in case of cm_nucscen = 2"JPN,USA"

@orichters orichters marked this pull request as draft August 5, 2024 12:14
@orichters orichters requested a review from tscheypidi August 5, 2024 12:18
@tscheypidi
Copy link
Member

@orichters for such a critical function it is really complex to have all relevant use cases in mind. That said, your changes look sensible to me. Luckily, we already have some tests capturing the main use cases of the function. Please also add test cases reflecting the new aspects your PR tries to cover (e.g. a test making sure that a comment is not messed up anymore)

@orichters
Copy link
Contributor Author

orichters commented Aug 6, 2024

I will add some tests, although I am quite confident it works because of this new test in remindmodel that shows that the 1831 messy lines of main.gms are not changed at all by running manipulateConfig with the default configuration.

The more crucial question to me seems to be: is there any possibility where it might be intended to manipulate a line such as

Parameter yourswitch = yourvalue

or something like that, where yourswitch is not at the beginning of the line. I don't see any reason to do that, but I'm not sure enough…

@tscheypidi
Copy link
Member

to my understanding the case in which the line starts with "parameter" or similar is already covered by the search&replace pattern2 which you did not change, right?

@orichters
Copy link
Contributor Author

to my understanding the case in which the line starts with "parameter" or similar is already covered by the search&replace pattern2 which you did not change, right?

Yes, scalars or parameters are not affected by this change.

@orichters orichters merged commit 03e6423 into pik-piam:master Aug 6, 2024
2 checks passed
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.

manipulateConfig: doesn't handle GAMS unquoted comments that include "=" sign properly
2 participants