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

Refine time index of Flows #1077

Merged
merged 20 commits into from
Jun 24, 2024
Merged

Refine time index of Flows #1077

merged 20 commits into from
Jun 24, 2024

Conversation

p-snft
Copy link
Member

@p-snft p-snft commented Jun 5, 2024

As different types of periods will be used for multi-period optimisation (long-term investment planing) and working with aggregated time-series (e.g. using tsam), I suggest to change the indexing. This PR implements Flows that use timesteps [int] instead of timeindex currently ([int, int]).

An index entry should not be needed for the flow. In preparation for
time-series aggegration, a cleanup might make sense, to keep overall
complexity managable.
@pep8speaks
Copy link

pep8speaks commented Jun 5, 2024

Hello @p-snft! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2024-06-06 11:44:58 UTC

@p-snft
Copy link
Member Author

p-snft commented Jun 12, 2024

Maybe, we should split this into several PRs and merge this as a first step.

@p-snft p-snft mentioned this pull request Jun 12, 2024
6 tasks
@p-snft p-snft changed the title Refine time index Refine time index of Flows Jun 12, 2024
@p-snft p-snft requested a review from jokochems June 12, 2024 19:59
@p-snft p-snft marked this pull request as ready for review June 12, 2024 20:03
@p-snft p-snft requested a review from fwitte June 19, 2024 12:39
@@ -743,17 +743,11 @@ def _positive_gradient_flow_constraint(_):
m.flow[
i,
o,
m.TIMEINDEX[index][0],
m.TIMEINDEX[index][1],
m.TIMESTEPS[index],
Copy link
Member

Choose a reason for hiding this comment

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

Kind of not directly related, but why does line 740 iterate over a numeric index instead of t as is done everywhere else? I guess there is a good reason for it...

Copy link
Member Author

Choose a reason for hiding this comment

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

To my understanding, this is because of the positive_gradient_constr needing the TIMEINDEX (including periods) to be allowed to consider investment (periods) in the ramping. (@jokochems might now better.) There is probably a more elegant way to do this, but I did not want to touch this now.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe also something to be discussed in a separate issue to not delay the progress too much

Copy link
Member

Choose a reason for hiding this comment

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

Well if you want to change it, it should rather be p for periods instead of t as the first index of the TIMEINDEX set refers to the periods, the second to the time steps.

What is more, is the previous formulation was just my inconvenient way of working around ramping events crossing periods. This is a nasty thing for the two-dimensional indexing, but vastly simplified when returning back to a one-dimensional flow index.

Maybe to add on that: I have never really used non-convex in combination with multi-period investments, but wanted to have it there in case somebody is willing to use that.

Copy link
Member Author

Choose a reason for hiding this comment

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

If it is really the periods, I did something wrong, as m.TIMESTEPS[p] does not make sense.

@fwitte
Copy link
Member

fwitte commented Jun 20, 2024

Thank you for the work @p-snft, since the tests are working things look fine for me. However, I am not very knowledgeable yet on how multi-period would work and cannot really check the changes for content. Also, I did not check the lp-files changes... That is simply too much, so #1079 is really welcome! :)

@p-snft p-snft added this to the v0.5.x milestone Jun 20, 2024
Copy link
Member

@fwitte fwitte left a comment

Choose a reason for hiding this comment

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

All remaining issues are side issues, which can be handled in a different PR

Copy link
Member

@jokochems jokochems left a comment

Choose a reason for hiding this comment

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

Thank you, @p-snft!

It has always bugged me that the multi-period feature brought along this inconsistency between indexing flows and other variables.

I thought about indexing every not investment-related variable with the TIMEINDEX set, but getting rid of the TIMEINDEX and indexing flows in TIMESTEPS instead, seems more user-friendly and intuitive to me. I just did not come up with that because I seem to have been too routine-blinded.

Preserving periods where needed can be achieved by using the TIMEINDEX set for iterations, as you did. Well actually you just did not touch upon that and kept it as is.

Long story short: I am happy to approve this as well. I only had one minor suggestion for renaming.

P.S.: It has been a while since I looked into the code base, but I still have the feeling of understanding it, which is a very good thing. ;-)

@@ -743,17 +743,11 @@ def _positive_gradient_flow_constraint(_):
m.flow[
i,
o,
m.TIMEINDEX[index][0],
m.TIMEINDEX[index][1],
m.TIMESTEPS[index],
Copy link
Member

Choose a reason for hiding this comment

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

Well if you want to change it, it should rather be p for periods instead of t as the first index of the TIMEINDEX set refers to the periods, the second to the time steps.

What is more, is the previous formulation was just my inconvenient way of working around ramping events crossing periods. This is a nasty thing for the two-dimensional indexing, but vastly simplified when returning back to a one-dimensional flow index.

Maybe to add on that: I have never really used non-convex in combination with multi-period investments, but wanted to have it there in case somebody is willing to use that.

src/oemof/solph/processing.py Outdated Show resolved Hide resolved
@jokochems
Copy link
Member

@p-snft I'm fine with you addressing the two comments according to your preferences (as I already approved it) and then merging it rightaways. Thank you very much!

@p-snft
Copy link
Member Author

p-snft commented Jun 24, 2024

As the gradient constraint has problems anyway, I will not touch it in this PR.

@p-snft p-snft merged commit f2b40f9 into dev Jun 24, 2024
9 of 12 checks passed
@p-snft p-snft deleted the revision/refine_timeindex branch June 24, 2024 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants