-
Notifications
You must be signed in to change notification settings - Fork 169
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
bugfixes for more robust feasibility #744
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing these infeasibilities!
v10_balance_positive.scale(j) = 10e-10; | ||
v10_balance_negative.scale(j) = 10e-10; | ||
v10_balance_positive.scale(j,land_from) = 10e-7; | ||
v10_balance_negative.scale(j,land_from) = 10e-7; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain what is happening here? Why does it help to switch to 10^-7?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran gdx2::calcScaling(gdx)
on a couple of different test runs. For most of them the suggestion is to use 10^-7
for scaling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay this may be more of an understanding question, so the scaling tells gams the order of magnitude of step lengths when iterating towards a local optimum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.gams.com/latest/docs/S_CONOPT4.html#CONOPT4_SCALING
internal_model = user_model / scaling_factor
GAMS is also doing automatic scaling but the default for Tol_Scale_Min
is 1. Since we have manual scaling factors < 1 I think we should use Tol_Scale_Min = 1.e-10;
in the optFile.
https://www.gams.com/latest/docs/S_CONOPT4.html#CONOPTTol_Scale_Min
@@ -23,7 +23,7 @@ else | |||
); | |||
p44_bii_lower_bound(t2,i,biome44)$(p44_bii_lower_bound(t2,i,biome44) >= 1) = 1; | |||
p44_bii_lower_bound(t2,i,biome44)$(m_year(t2) < s44_start_year) = 0; | |||
p44_bii_lower_bound(t2,i,biome44)$(sum(cell(i,j), f44_biome(j,biome44)) = 0) = 0; | |||
p44_bii_lower_bound(t2,i,biome44)$(sum(cell(i,j), f44_biome(j,biome44)) <= 1e-10) = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change (and other similar changes where 0 is replaced with 1e-10) necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this specific case for bii_target
it was inconsistent with presolve and equations, where it is already 1e-10.
The intention is to fix v44_bii
to zero in case the biome share f44_biome
is very small. And this case also the lower bound should be zero.
I implemented the same logic for the bii_target_apr24
realisation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced. Replacing small values with 0 / treating zeros the same as tiny numbers seems like losing control. We don't quite know why this works, but if we replace it with zero it works, and it's almost zero anyway... I have a bad feeling about this practice, we are piling up ultra hard to debug problems in our code this way is my feeling. This is of course more a general comment and not specific to this instance/PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this point. Why should it be an issue to treat tiny numbers like zero?
My understanding is that such tiny numbers might cause issues for the solver.
We also do this in other parts of the model.
For debugging we have off / simple module realizations in many cases.
Do you have another suggestion for addressing this problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should it be an issue to treat tiny numbers like zero?
It's just mathematically wrong, and we don't understand the implications. This lack of control what's going on is what's bugging me, but that is of course inherent to using gams/conopt4, so not something we can change easily :/
We also do this in other parts of the model.
That is not a great argument and just makes me feel more anxious.
Do you have another suggestion for addressing this problem?
Unfortunately no, I cannot follow what is happening really, so I'll approve. Wanted to emphasize my concerns though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be interested in the other reviewers perspective on this @tscheypidi @FelicitasBeier @k4rst3ns :) Am I just worrying to much? 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally get your concern. It has been a common practice in the past, though. So maybe something to discuss in the next MAgPIE meeting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same concern here.
On Florians:
My understanding is that such tiny numbers might cause issues for the solver
... I would not know why theoretically and generally this should be an issue.
We observed that over the years, but do not have a great understanding here.
But I am also see @flohump point: this is not specific to this PR. And I like @FelicitasBeier suggestion bringing this up to the MAgPIE meeting and approving this for now.
|
||
q10_transition_to(j2,land_to) .. | ||
sum(land_from, vm_lu_transitions(j2,land_from,land_to)) =e= | ||
vm_land(j2,land_to); | ||
|
||
q10_transition_from(j2,land_from) .. | ||
sum(land_to, vm_lu_transitions(j2,land_from,land_to)) =e= | ||
pcm_land(j2,land_from); | ||
vm_land.l(j2,land_from) + v10_balance_positive(j2,land_from) - v10_balance_negative(j2,land_from); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know this formulation from equations. Thought that's a presolve/postsolve thing. Are you sure that works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in the above two equations, you really want the variable and not the level, right? Just to make sure because the first one (q10_transition_matrix) has changed from pcm_land to vm_land, not vm_land.l
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know this formulation from equations. Thought that's a presolve/postsolve thing. Are you sure that works?
Yes, it works ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in the above two equations, you really want the variable and not the level, right? Just to make sure because the first one (q10_transition_matrix) has changed from pcm_land to vm_land, not vm_land.l
I was thinking about the reasons for the infeasible solutions and came to the conclusiong that it might be due to inconsistencies in these 3 equations from the use of vm_land and pcm_land.
Therefore, I switched to vm_land in the first two equations and vm_land.l in third equation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't fully understand why, but I am happy the infeasibilities are gone, so I'm gonna approve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not too much understanding of the changes I believe.
Happy to get feedback on the pcm_land
to vm_land.l
change before approval (sorry 😅 )
|
||
q10_transition_to(j2,land_to) .. | ||
sum(land_from, vm_lu_transitions(j2,land_from,land_to)) =e= | ||
vm_land(j2,land_to); | ||
|
||
q10_transition_from(j2,land_from) .. | ||
sum(land_to, vm_lu_transitions(j2,land_from,land_to)) =e= | ||
pcm_land(j2,land_from); | ||
vm_land.l(j2,land_from) + v10_balance_positive(j2,land_from) - v10_balance_negative(j2,land_from); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that vm_land.l
should suppose to be the same as pcm_land.
But as you also pointed out pcm_land is actually changed in some resolve functions, so this is not at all identical or not?
I am not 100% sure why we need this balancing, if we could just define a variable with a level that has the correct value of pcm_land?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this instance it does not make a difference if we use pcm_land
or vm_land.l
. They should be identical.
The point is that vm_land.l
is changed in the presolve based on parameters, which seem to have a different accuracy than the variable.
I tried without the balancing variables. But without them some of the test runs are infeasible.
@@ -23,7 +23,7 @@ else | |||
); | |||
p44_bii_lower_bound(t2,i,biome44)$(p44_bii_lower_bound(t2,i,biome44) >= 1) = 1; | |||
p44_bii_lower_bound(t2,i,biome44)$(m_year(t2) < s44_start_year) = 0; | |||
p44_bii_lower_bound(t2,i,biome44)$(sum(cell(i,j), f44_biome(j,biome44)) = 0) = 0; | |||
p44_bii_lower_bound(t2,i,biome44)$(sum(cell(i,j), f44_biome(j,biome44)) <= 1e-10) = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same concern here.
On Florians:
My understanding is that such tiny numbers might cause issues for the solver
... I would not know why theoretically and generally this should be an issue.
We observed that over the years, but do not have a great understanding here.
But I am also see @flohump point: this is not specific to this PR. And I like @FelicitasBeier suggestion bringing this up to the MAgPIE meeting and approving this for now.
🐦 Description of this PR 🐦
This PR aims to fix infeasibilies that I have repeatedly encountered for single runs when testing the current develop with the full set of FSEC runs and runs with H16 resolution.
The fix in
10_land
for the land transtion matrix is to use only variables (vm_land) and variables levels (vm_land.l), and not a mix of variables and parameters. The issue is that GAMS seems to have different accuracies for variables and parameters. However, vm_land.l is updated between time steps based on parameters. Therefore, the balance variables are still needed.This PR has been successfully tested with
test_runs.R
, the full set of FSEC runs and some H16EU runs with rev4.114. Tests with rev4.115 are underway.🔧 Checklist for PR creator 🔧
Label pull request from the label list.
Self-review own code
magpie4
R library has been updated accordingly and backwards compatible where necessary.scenario_config.csv
has been updated accordingly (important ifdefault.cfg
has been updated)Document changes
CHANGELOG.md
goxygen::goxygen()
and verify the modified code is properly documentedPerform test runs
Rscript start.R --> "compilation check"
Rscript start.R --> "test runs"
Rscript start.R --> "test runs"
📉 Performance changes 📈
🚨 Checklist for reviewer 🚨
CHANGELOG
is updated correctly