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

Feature/restucture flow #856

Merged
merged 83 commits into from
Oct 18, 2022
Merged

Feature/restucture flow #856

merged 83 commits into from
Oct 18, 2022

Conversation

p-snft
Copy link
Member

@p-snft p-snft commented Jun 29, 2022

Notes: We need to either include #799 or this makes it obsolete.

Bachibouzouk and others added 20 commits June 22, 2022 11:53
Describe the change introduced by the NonConvexInvestFlow

Co-authored-by: sasa821 <83787088+sasa821@users.noreply.github.com>
Co-authored-by: sasa821 <83787088+sasa821@users.noreply.github.com>
Co-authored-by: sasa821 <83787088+sasa821@users.noreply.github.com>
Co-authored-by: sasa821 <83787088+sasa821@users.noreply.github.com>
It is a mix of the classes solph.flows.NonConvexFlow and
solph.flows.InvestmentFlow
Additional constraints will be added as well in a separate commit

Co-authored-by: sasa821 <83787088+sasa821@users.noreply.github.com>
- Required constraints to linearize the problem
- Add an argument to the solph.flows.Flow to make it possible to combine
nonconvex and investment options

Co-authored-by: sasa821 <83787088+sasa821@users.noreply.github.com>
Update MANIFEST.in as well

One example refers to a hybrid minigrid system with a diesel genset
being optimized using the solph.flows.NonConvexInvestFlow

Co-authored-by: sasa821 <83787088+sasa821@users.noreply.github.com>
Co-authored-by: Patrik Schönfeldt <patrik.schoenfeldt@dlr.de>
Remove the syntax to highlight the class names in the error messages.

Co-Authored-By: Pierre Francois <4399407+Bachibouzouk@users.noreply.github.com>
Explain what parts of the `NonConvexInvestFlow` are similar to the `NonConvexFlow` and `InvestmentFlow`, and what parts are new in the `NonConvexInvestFlow`.

Co-Authored-By: Pierre Francois <4399407+Bachibouzouk@users.noreply.github.com>
Since the new parameter `invest_non_convex` exists in the `NonConvexInvestFlow`, there is no need for the `invest_status`. Moreover, usage of the `NonConvexInvestFlow` class indicates that the `invest` always exists. Therefore, `invest_status` can be removed and by removing it, the computation time would increase.

Co-Authored-By: Pierre Francois <4399407+Bachibouzouk@users.noreply.github.com>
The sets `NON_FIXED_INVESTFLOWS` and `FIXED_INVESTFLOWS` and their corresponding constraints are removed because they seem to be unnecessary in the `NonConvexInvestFlow` and removing them would increase the computation time.

Co-Authored-By: Pierre Francois <4399407+Bachibouzouk@users.noreply.github.com>
Change the `min`, `max`, and `conversion_factors` values to numbers that can be cast from decimal to floating-point and back (e.g., 0.25, 0.5, ...) to increase the readability of the corresponding *.lp file.

Co-Authored-By: Pierre Francois <4399407+Bachibouzouk@users.noreply.github.com>
Explicitly name authors in the "SPDX-FileCopyrightText".

Co-Authored-By: Pierre Francois <4399407+Bachibouzouk@users.noreply.github.com>
In some parts, the name of the `NonConvexInvestFlow` was written incorrectly.

Co-Authored-By: Pierre Francois <4399407+Bachibouzouk@users.noreply.github.com>
Modify the example file because it is not read from somewhere else.

Co-Authored-By: Pierre Francois <4399407+Bachibouzouk@users.noreply.github.com>
Co-authored-by: sasa821 <83787088+sasa821@users.noreply.github.com>
@Bachibouzouk
Copy link
Contributor

Bachibouzouk commented Jun 29, 2022

Discussion with @p-snft , @joroeder , @sasa821 : there should not be InvestFlow, NonConvexFlow, NonConvexInvestFlow but just one Flow class and depending on the argument the user provides, the Flow can be nonconvex and/or with invest mode.

@Bachibouzouk maybe the design pattern we want to apply here is similar to this one: https://refactoring.guru/design-patterns/strategy

We should write pseudo code call with different usecase to be able to decide what should happen in each case and implement tests before refactoring

@p-snft
Copy link
Member Author

p-snft commented Jun 29, 2022

Because NonConvex and Investment are no longer mutually exclusive, we may rethink the structure of Flow, NonConvexFlow and InvestmentFlow, because there is NonConvexInvestmentFlow. For the API, it might be more intuitive to have Invest and NonConvex as options. (In my memory we wanted to get rid of the options because they were confusing because they are exclusive.)

@Bachibouzouk
Copy link
Contributor

Bachibouzouk commented Jun 29, 2022

To define a nonconvex and investment flow

solph.flows.Flow(
    nominal_value=None,
    variable_costs=...,
    min=<number in (0,1)>,
    max=<number in [min,1)>,
    investment=solph.Investment(
        ep_costs=...,
        maximum=..., # need to have maximum provided here
    )
)

Another alternative

solph.flows.Flow(
    nominal_value=None,
    variable_costs=...,
    min=<number in (0,1)>,
    max=<number in [min,1)>,
    ep_costs=...,
    investment_maximum=..., # need to have maximum provided here
    )
)

To me it should be possible to not explicitly provide nominal_value

solph.flows.Flow(
    variable_costs=...,
    min=<number in (0,1)>,
    max=<number in [min,1)>,
    ep_costs=...,
    investment_maximum=..., # need to have maximum provided here
    )
)

A special case which falls back on convex investment flow case

solph.flows.Flow(
    variable_costs=...,
    min=0,
    max=1,
    ep_costs=...,
    investment_maximum=...
    )
)

@p-snft
Copy link
Member Author

p-snft commented Jun 30, 2022

Generally, I see that all the alternatives are possible. (There are more, but more on that later.) Especially, I agree that it should be possible to not explicitly provide nominal_value. Also, if a nominal_value and an invest, that can be interpreted as existing capacity that might be increased.

I want to discuss some more open questions (Qn) using the following example:

solph.flows.Flow(
    nominal_value=<number>,
    variable_costs=...,
    min=[0 <= float <= max],  # Should a minimum imply NonConvex? (Q1)
                              # Until now, setting a min without NonConvex means always on.
    max=[min <= float],  # Currently, max can be equal to min and can also exceed 1.
                         # Should it stay like that? (Q2)
    fix=[min <= float <= max],  # Should it be possible to have a series like [0, 0, .5, None, .2],
                                # where there is not fixed value for step 4? (Q3)
                                # If yes: Should it be possible to define min, max, and fix at the same time? (Q4)
)

As I like the current solution for Q1 (minimum also excludes value of 0, always on when no NonConvex is set), I'd suggest to stick with that. However, the argument might be called e.g. binary_status, to be easier to understand for non-mathematicians.

PS: The arguments positive_gradient and negative_gradient are present in both, Flow and NonConvex. I have the feeling that they are only required once.

@jokochems
Copy link
Member

jokochems commented Jul 2, 2022

Thanks for opening this discussion.

In general, I like the idea of having one single Flow class.
I don't like putting arguments into a flat argument structure. I think, it is much more intuitive and less error prone to use a nested structure, i.e. if you want an investment to happen, in my view, the most intuitive form is something like

solph.flows.Flow(
    nominal_value=None,
    variable_costs=...,
    min=<number in (0,1)>,
    max=<number in [min,1)>,
    investment=solph.Investment(
        ep_costs=...,
        maximum=..., # need to have maximum provided here
    )
)

Also, I'd strongly suggest to split after v0.5. I seriously see #810 at risk if we keep integrating new structural changes.

It's mostly (obvious) typos.

Co-authored-by: Pierre Francois <pierre-francois.duc@netplus.ch>
@jokochems
Copy link
Member

I'm not going to go into details with a code review and at the moment, unfortunately, my time for oemof development is very limited, but I had a quick look and really like the structural improvements, this PR brings along. I'm a bit worried about integrating #828, though, but I'll try to cut some time in October to resolve merge conflicts and copy & paste the changes brought along. ;-)

@jokochems jokochems mentioned this pull request Sep 23, 2022
@p-snft
Copy link
Member Author

p-snft commented Sep 24, 2022

Were examples/nonconvex_invest_flow_examples/

  • diesel_genset_nonconvex_investment.py
  • house_with_nonconvex_investment.py
  • house_without_nonconvex_investment.py
    ran?

I would search for occurences of NonConvexInvestFlow and replace them by NonConvexInvestmentFlow

I see that the class InvestNonConvexFlowBlock is often referred to as NonConvexInvestFlowBlock in docstrings and comments

Thanks for your feedback. Adding to these points, I also forgot to align the naming if the example with the new wording.

Done. Remaining tasks are addressed in #863.

@p-snft p-snft requested review from Bachibouzouk, joroeder and uvchik and removed request for Bachibouzouk September 26, 2022 13:55
This was referenced Sep 27, 2022
Copy link
Member

@joroeder joroeder left a comment

Choose a reason for hiding this comment

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

When going through the changes, I updated the links in docs. (which is also part of #863, and made some minor suggestion for improvement.

Do we need an __init__.py in the examples. I think this is not necessary and we should remove the file.

Besides, I do not see anything against merging this PR.

:py:mod:`~oemof.solph.options` module.
Note that the usage of this class is currently not compatible with the
:py:class:`~oemof.solph.options.Investment` class.
Solph also allows you to model components with respect to more technical details,
Copy link
Member

Choose a reason for hiding this comment

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

The following paragraphs need to be revised as it describes an outdated state. I have tried to address this, and to link the right API documentation of the blocks (a short check would be nice). I think we at least should not merge code snippets with a wrong API.

Generally, I think it is really nice that there is something about the mathematical background.

docs/usage.rst Outdated Show resolved Hide resolved
docs/usage.rst Outdated Show resolved Hide resolved
docs/usage.rst Outdated Show resolved Hide resolved
docs/usage.rst Outdated Show resolved Hide resolved
docs/usage.rst Outdated Show resolved Hide resolved
docs/usage.rst Outdated Show resolved Hide resolved
docs/usage.rst Outdated Show resolved Hide resolved
docs/whatsnew/v0-5-0.rst Show resolved Hide resolved
p-snft and others added 2 commits October 18, 2022 09:39
Co-authored-by: Johannes Röder <45163075+joroeder@users.noreply.github.com>
@p-snft
Copy link
Member Author

p-snft commented Oct 18, 2022

As far as I see, there is no objection and one positive review.As some PRs already build on the changes presented here, I will now merge. Remaining clean-up (of the documentation and adjustments to the other flow classes) is addressed in #863.

@p-snft p-snft merged commit 948f873 into dev Oct 18, 2022
@p-snft p-snft deleted the feature/restucture_flow branch October 18, 2022 09:14
@sasa821 sasa821 mentioned this pull request Nov 23, 2022
@p-snft p-snft mentioned this pull request Jul 30, 2023
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.

7 participants