iiasa / message_ix

The integrated assessment and energy systems model MESSAGEix
https://docs.messageix.org
Apache License 2.0
119 stars 153 forks source link

Westeros scenario does not solve with --foresight=1 #736

Open MESSAGEix-SK-Woo opened 1 year ago

MESSAGEix-SK-Woo commented 1 year ago

Hi, I'm making power sector model using MESSAGEix.

And I was wondering what is difference between perfect-foresight and recursive-dynamic.

So, I just try westores examples at first.

below is what i did.

1) open the 'westeros_baseline.ipynb' 2) chage a code 'scenario.solve()' to 'scenario.solve(gams_args =["--foresight=1"])' ※python version: 3.9.7 and I use latest version of all package(message-ix, ixmp, ...)

And then, the moel said 'GAMS errored with return code 3: There was an execution error'.

So I found MESSAGE_run.lst, and I can find some error like that. ※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※ Exec Error at line 2780: Equation infeasible due to rhs value INFEASIBLE EQUATIONS ... ---- CAPACITY_CONSTRAINT =L= capacity constraint for technology (by sub-annual time slice) CAPACITY_CONSTRAINT(Westeros,coal_ppl,690,700,year).. 0 =L= -18.2648401826484 ; (LHS = 0, INFES = 18.2648401826484 ) CAPACITY_CONSTRAINT(Westeros,wind_ppl,690,700,year).. 0 =L= -12.1765601217656 ; (LHS = 0, INFES = 12.1765601217656 ) REMAINING 5 ENTRIES SKIPPED

Exec Error at line 2806: Equation infeasible due to rhs value INFEASIBLE EQUATIONS ... ---- CAPACITY_MAINTENANCE_HIST =E= constraint for capacity maintenance historical installation (built before start of model horizon) CAPACITY_MAINTENANCE_HIST(Westeros,coal_ppl,690,700).. 0 =E= 18.2648401826484 ; (LHS = 0, INFES = 18.2648401826484 ) CAPACITY_MAINTENANCE_HIST(Westeros,wind_ppl,690,700).. 0 =E= 33.8237781160156 ; (LHS = 0, INFES = 33.8237781160156 )

Exec Error at line 2830: Equation infeasible due to rhs value INFEASIBLE EQUATIONS ... ---- CAPACITY_MAINTENANCE_NEW =E= constraint for capacity maintenance of new capacity built in the current period (vintage == year) CAPACITY_MAINTENANCE_NEW(Westeros,coal_ppl,700,700).. 0 =E= 3.5527136788005E-15 ; (LHS = 0, INFES = 3.5527136788005E-15 ****) ※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※

I know the above code's meanings, but...

Why did I get these results?

How can I solve it?

I guess "scenario.solve(gams_args =["--foresight=1"])" is right, because if i adjust ["--foresight=0"], it operate well( 0 means perfect-foresight, you know)

Please.. help me!

Thanks! :)

glatterf42 commented 1 year ago

Hi @MESSAGEix-SK-Woo, thanks for asking these questions and already including a lot of information :)

Two tips for including code or error messages in the future: you can include in-line code using `some code` (which you can also enable with ctrl+e) and you can format code blocks nicely using e.g. ```python

some code 
on multiple lines

```

As for your question, I have to say that I don't have a lot of model experience myself. However, search our documentation for 'perfect foresight', I found two things in particular: a theoretical explanation and some notes on use cases. From these, I understand that you are using the ["--foresight=1"] correctly, as any value greater than 0 will cause the recursive-dynamic :) I can also see that perfect foresight is used much more frequently and recursive-dynamic only for specific applications. The mathematical difference seems to be that in perfect foresight, GAMS optimizes the objective function including all years of the model, while with recursive-dynamic, GAMS loops over the years of the model and optimizes each step individually, only keeping the values of prior steps fixed. Judging from this explanation, I don't see any reason why the westeros tutorials shouldn't be solvable with recursive-dynamic, but someone with more model experience might know more about this, so I will ask one of my colleagues.

MESSAGEix-SK-Woo commented 1 year ago

Hi @glatterf42 , Thank you for giving reply and useful information.

I also agree with your comment 'perfect foresight is used much more frequently' but I want to compare with two method in my MESSAGE. That's Why I try it!

Maybe I made a mistake, but I don't know which part. Thanks you for asking this problem to your colleagues! Have a woderful day :)

khaeru commented 1 year ago

I confirm this is reproducible; here's a MWE using the testing utility we have that sets up the Westeros scenario:

import ixmp
from message_ix.testing import make_westeros

mp = ixmp.Platform()
s = make_westeros(mp)

s.solve(gams_args=["--foresight=1"])

I also attach the terminal output.txt and MESSAGE_run.lst.

@ywpratama @gidden, given your work on #697 and related, I think you are most/currently familiar with the recursive-dynamic operation of MESSAGE.

gidden commented 1 year ago

@ywpratama will have to chime in with specifics, but from my memory the current implementation of dynamic recursive solves are not expected to work on the main branch, and indeed are why #697 is needed. @MESSAGEix-SK-Woo could you try working from the branch currently in #697 to see if you get the same errors? We can then in parallel wait for @ywpratama to comment here.

I'd note that in the referenced PR there is a dynamic recursive tutorial as well, which would be a good starting point.

MESSAGEix-SK-Woo commented 1 year ago

Thanks, @khaeru and @gidden . I created a new environment in Anaconda and utilized @ywpratama 's message_ix instead of my existing message_ix. This is because I thought the problem was in the gams code itself, not in python. Also, I thought that ywpratama's message_ix was GAMS modified for recursive-dynamic.
But this also gives me an error.

glatterf42 commented 1 year ago

Take your time, no problem. You may find these links useful: