Skip to content
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

Develop-sticky merge #199

Merged
merged 187 commits into from
Aug 12, 2020
Merged

Conversation

emolinab
Copy link
Contributor

@emolinab emolinab commented Jul 2, 2020

Description

The following PR includes the incorporation of the new "sticky" realization for calculation of factor costs, and the way modules with investment decisions account for overall costs.

Purpose of this PR

  • The purpose is to improve MAgPIE's performance in the spatial sense, favoring crop area expansion in cells with preexisting farmland and capital. Also, to improve the calculation of costs where investment decisions are taken.

Performance loss/gain from the current default behavior

image

Default run time: 0.7 hours
New PR: 1.4 hours
Comparison: 1.8 times slower.

Type of change

  • Bug fix (Change which fixes an issue).
  • New feature (Change which adds functionality).
  • Minor change (Change which does not modify core model code i.e., in /modules).
  • Major change (fix or feature that would change current model behavior).

How Has This Been Tested?

  • Runs using starting script which tests current defaults (using test_runs.R).
  • Runs using starting script which successfully runs the same scenarios as in test_runs.R but with the changes from PR.

Default configuration additions/changes:

  • Realizations:
  • Scalars/Constants:
  • Other changes:

Checklist:

  • Self-review of my own code.
  • Added changes to CHANGELOG.md
  • No hardcoded numbers and cluster/country/region names.
  • The code doesn't contain declared but unused parameters or variables.
  • In-code comments added including documentation comments.
  • Compiled and checked resulting documentation with goxygen::goxygen() for the new/updated parts.
  • Changes to magpie4 R library for post-processing of model output (ideally backward compatible).

Special comments/warnings

  • The use of sticky increases run times, and overall cost due to larger input costs. Please, be cautious when you use region setting different to the usual ones.

@tscheypidi
Copy link
Member

Just for clarification: You ticked all categories for Default configuration additions/changes which would mean that you changed default settings in all categories, but my understanding is that you did not touch any default settings. Am I right? If so, please correct your description of the pull request and untick the corresponding categories.

In addition, please do not delete lines from the template which contain check boxes. Just keep the lines unchecked to make clear what does not apply for your PR.

@emolinab
Copy link
Contributor Author

emolinab commented Jul 2, 2020

Thanks Jan! Issues fixed. You are right, I didn't change any of the default configurations, so those items are now unticked, and I have left the unchecked items in the "Type of change" category.

Copy link
Member

@tscheypidi tscheypidi left a comment

Choose a reason for hiding this comment

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

looks good, only some minor requests from my side before it can be merged


**scripts** removed GP_final start script due to obsolescence


Copy link
Member

Choose a reason for hiding this comment

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

add your changes to the existing unreleased section instead of introducing a second unreleased section

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@@ -197,7 +197,7 @@ $title magpie
*
*
*
* Last modification (input data): Thu Jun 18 18:28:38 2020
* Last modification (input data): Thu Jun 25 17:37:27 2020
*
Copy link
Member

Choose a reason for hiding this comment

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

ideally, you should not add files to your commit with irrelevant changes such as the modification date update. In case of main.gms it should be in most cases excluded from a commit.

You can keep it in the PR this time, but please avoid adding such files next time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect, I'll keep it in mind for the next one.

;

parameters
p38_ovcosts(t,i,kcr) Overall factor costs (mio USD05MER)
Copy link
Member

Choose a reason for hiding this comment

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

is p38_ovcosts required/used in the fixed case?

@@ -5,15 +5,19 @@
*** | MAgPIE License Exception, version 1.0 (see LICENSE file).
*** | Contact: magpie@pik-potsdam.de

p38_ovcosts(t,i,kcr) = vm_cost_prod.l(i,kcr);
Copy link
Member

Choose a reason for hiding this comment

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

what is this used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

p38_ovcost originally accounts for the overall costs coming from sticky. Since I modified the costs.R function in magpie4 to read p38_ovcosts, I used it in the postsolve of all the factor costs realizations.

Copy link
Member

Choose a reason for hiding this comment

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

for reporting please use ov_cost_prod instead (and remove p38_octcosts again)...it contains the values of vm_cost_prod for all time steps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean for the fixed and mixed realizations of factor costs, or for all the modules and realizations where I used these pxx_overall_costs parameters?

Copy link
Member

Choose a reason for hiding this comment

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

If the costs are not influencing the subsequent periods, then it should not be in the gams code.
all "pure" prosprocessing can happen in R, based on the level values of the variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okie dokie

Copy link
Member

Choose a reason for hiding this comment

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

from what I saw, it is only used in postprocessing. Then remove this parameter from the GAMS code and make the calculations in the magpie4 library.

@abhimishr abhimishr added the enhancement New feature or request label Jul 2, 2020
Copy link
Member

@tscheypidi tscheypidi left a comment

Choose a reason for hiding this comment

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

looks good to me

Copy link
Member

@bodirsky bodirsky left a comment

Choose a reason for hiding this comment

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

in a run with different region setting, the calibration runs become infeasible.
Feli and I tracked it down:

its the upper bound for the investment constraint in the presolve. We have small region in africa (ruanda, uganda, tanzania) where this constraint is too narrow, as investments are higher than the defined gdp share.

Not sure whether this is only in the calibration, or in general with the model. The constraint should be relaxed.

@@ -5,15 +5,19 @@
*** | MAgPIE License Exception, version 1.0 (see LICENSE file).
*** | Contact: magpie@pik-potsdam.de

p38_ovcosts(t,i,kcr) = vm_cost_prod.l(i,kcr);
Copy link
Member

Choose a reason for hiding this comment

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

from what I saw, it is only used in postprocessing. Then remove this parameter from the GAMS code and make the calculations in the magpie4 library.

@emolinab
Copy link
Contributor Author

emolinab commented Jul 22, 2020

in a run with different region setting, the calibration runs become infeasible.
Feli and I tracked it down:

its the upper bound for the investment constraint in the presolve. We have small region in africa (ruanda, uganda, tanzania) where this constraint is too narrow, as investments are higher than the defined gdp share.

Not sure whether this is only in the calibration, or in general with the model. The constraint should be relaxed.

I have looked into it, and the maximum value of the capital investment in Feli's runs is close to 11%. I had set up this value for 5% for the default region setting (based on previous runs). I am thinking about increasing this value to 15%. Are there any other important regional settings that I might run, to make sure this constraint is valid in any case?

***It is important to mention that this constraint is key for speed performance, so increasing it might increase run times.

@emolinab emolinab requested a review from bodirsky July 23, 2020 14:11
@bodirsky bodirsky merged commit e2854ae into magpiemodel:develop Aug 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers Major Substantial modifications
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants