oemof / oemof-solph

A model generator for energy system modelling and optimisation (LP/MILP).
https://oemof.org
MIT License
297 stars 126 forks source link

Implausible diverging results comparing 1-year-multi-period & multi-period optimization #1047

Closed mco-sch closed 7 months ago

mco-sch commented 7 months ago

Describe the bug There are implausible diverging results comparing 1-year-multi-period and multi-period optimization.

To Reproduce

Explanation of (simplified) energy system

Expected behavior

Actual multi-period optimization result

Additional Context

Desktop/System Information

---- developers note ---- I adapted the term single-period to 1-year-multi-period as these currently are different implementations but multi-period approach is used for both in this case. By passing data to the periods-parameter multi-period implementation is used which has a different handling e.g. investment costs/annuities, timepoints/timesteps concerning SOC of storages, etc

mco-sch commented 7 months ago

Within the last few days I did some more computations and I am pretty sure about the origin of the problem. It seems, as if investments and flows are not treated equally. Annualized investments are multiplied by the duration of one period (e.g. five years), while flows are not. This leads to the n-fold of investment costs while variable costs are only considered once. Hence, if an investment is competing to a source (e.g. power plant investment vs. electricity import by grid), the investment is unreasonably handicapped leading to wrong results.

It would be necessary to either multiply all flow variables by the duration of one period (the same way as investments are handled) or drop this kind of multiplication for investments.

@jokochems What do you think?

Unfortunately, I am not that experienced within the solph code itself. Maybe someone could leave me a hint about the part of the code to look at so I could go for a try.

jokochems commented 7 months ago

Hello @mco-sch,

sorry for the late and maybe unsatisfactory response:

Here are some hints regarding your setup:

Now to the concrete problem:

I hope this helps at least a little and was understandable. You might want to check the calculations within _investment_flow_block.py (line 925 following) to get a better idea of what is happening.

mco-sch commented 7 months ago

Hello @jokochems,

no problem, still thanks for your reply and good luck with your PhD. According to your reply, I assume my initial explanation was not properly enough. Sorry for that. Actually, I am neither concerned about the duration of the last period nor the investment in the last period - this all behaves as expected. But I am surprised that there are no investments before the last period, although this should be the case.

But you are right, applying your use case of annual periods does not lead to this issue. So it only seems to be a problem using multiple year steps. Hope @nailend and others are aware of this bug.

nailend commented 7 months ago

Hello @mco-sch

  • Also, be aware that I so far only considered annual periods equaling calendaric years. You are considering 5 year steps which plays a role. But anyways, @nailend and others have this use case, too. I just want to raise awareness that this is something I am not using and which is therefore not thoroughly tested.

Indeed, we have this use case and the current implementation, doesn't fully cover it yet. Especially, your situation is addressed in #992, isn't it? I had this on hold, as we ended up in a more fundamental discussion about having discounting included in the model or not.

  • The last thing I want to make you aware of is discounting. I sort of integrated that into the framework and worked with nominal cost values (which admittedly is not so common and complicates things). We are thinking of decoupling that. But you have anticipated it correctly by defining a discount_rate of 0.

To keep maintainability low and have a more generalized approach, we want to exclude the discounting internally but provide functions to directly include all the assumptions in the time series provided to the model. This way it's more sophisticated on the user side to include this, but easier on the side of development and maintainability of oemof.solph.

Please take a look at my implementaion/bugfix for your use case and be free to use it but keep in mind, this might never be merged into the main code-base.

mco-sch commented 7 months ago

Hello @nailend, yes, you are right - my situation is the same as you already addressed. Thanks for this hint. As far as I can see, I solved the issue the same way (weighting variable costs by period duration). Nevertheless, I didn't solve it within solph itself but during pre-processing my data. Up to now, this works fine for me. I will close the issue – thanks for your support.

nailend commented 7 months ago

but during pre-processing my data. Up to now, this works fine for me.

If you are open to it, you can share this preprocessing part on gist and link it here. This way, oemof-users can have a look into it and maybe integrate it later as we are planing to move it to the pre-processing anyways.

Thanks