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

Benchmark test for heat sector #524

Merged
merged 43 commits into from
Sep 1, 2020
Merged

Benchmark test for heat sector #524

merged 43 commits into from
Sep 1, 2020

Conversation

ursulaelmir
Copy link
Collaborator

@ursulaelmir ursulaelmir commented Aug 21, 2020

Fix #503

Changes proposed in this pull request:

  • Prepare input files for electric grid + heat pump + heat grid
  • Write benchmark test
  • Write definitions for all benchmark tests

The following steps were realized, as well (if applies):

  • Use in-line comments to explain your code
  • Write docstrings to your code
  • For new functionalities: Explain in readthedocs
  • Write test(s) for your new patch of code
  • Update the CHANGELOG.md
  • Apply black (black . --exclude docs/)
  • Check if benchmark tests pass locally (EXECUTE_TESTS_ON=master pytest)

Please mark above checkboxes as following:

  • Open
  • Done

❌ Check not applicable to this PR

For more information on how to contribute check the CONTRIBUTING.md.

@ursulaelmir
Copy link
Collaborator Author

Hi @smartie2076 , I was thinking of integrating a time series for the electricity DSO in this benchmark test, so it would also look into #506

Why I am thinking about that, it's basically because in this simple test with electricity DSO, heat DSO and heat pump, the heat pump will only be used when electricity_price/COP < heat_price
so I can have a time series of only two values and can check that the heat pump is only used when this is valid.
What do you think?

I am actually trying to implement it myself but I get this error: json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
when energy_price for electricity DSO is "{0.1 , 0.3}"

@ursulaelmir
Copy link
Collaborator Author

or this could also be implemented as a sensitivity analysis @smartie2076 @Bachibouzouk

@ursulaelmir
Copy link
Collaborator Author

@smartie2076 I have written the benchmark tests which are ready for review. Please let me know if we will include the time series here or not :)

@smartie2076
Copy link
Collaborator

Hi Ursula! Actually, you should be able to implement a timeseriers with "{‘file_name’: ‘your_file_name.csv’, ‘header’: ‘your_header’, ‘unit’: ‘your_unit’}". You can not use two values in the timeseries, the series has to be as long as the others.

The idea is good!

(readthedocs says "{‘value’: {‘file_name’: ‘your_file_name.csv’, ‘header’: ‘your_header’}, ‘unit’: ‘your_unit’}", but I don't think that's true)

@smartie2076
Copy link
Collaborator

Including the quotation marks!

@ursulaelmir
Copy link
Collaborator Author

hi @smartie2076 , I tried both ways and the error is still the same: json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1) .. I am not sure what the problem is..

@smartie2076
Copy link
Collaborator

Okay, please push with the input files and I look into it tomorrow.

@smartie2076
Copy link
Collaborator

The dict has to be defined using string delimiter ', otherwise the data can not be parsed.

A new error occurs now with the function C3.check_feedin_tariff() as that function can not process timeseries yet. You can write something like

If value in feedin-tariff or value in electricity price:
Diff = fit - ep
If any(diff) > 0:
Warning 

It might be that this only works for mixed problems (one series, one scalar) if the scalar is of type int. Please check if it can be float (because it will most likely be a float). Maybe use pd.multiply or something then.

ursulaelmir and others added 3 commits August 25, 2020 14:39
@ursulaelmir
Copy link
Collaborator Author

ursulaelmir commented Aug 27, 2020

hi @smartie2076
I am not so sure if what I am doing is what you're looking for.. something like that? (of course it is not done.. but errors accumulate)

    for provider in dict_values[ENERGY_PROVIDERS].keys():
        feedin_tariff = dict_values[ENERGY_PROVIDERS][provider][FEEDIN_TARIFF]
        electricity_price = dict_values[ENERGY_PROVIDERS][provider][ENERGY_PRICE]
        if "value" in feedin_tariff and "value" in electricity_price:
            diff = feedin_tariff["value"] - electricity_price["value"]
            if diff > 0:
                msg = f"Feed-in tariff > energy price of energy provider asset '{dict_values[ENERGY_PROVIDERS][provider][LABEL]}' would cause an unbound solution and terminate the optimization."
                raise ValueError(msg)
        elif "value" in feedin_tariff and "flow" in electricity_price:
            for i in range(0, electricity_price["flow"]["data"]):
                diff[i] = feedin_tariff["value"] - electricity_price["flow"]["data"][i]
                if any(diff) > 0:
                    msg = f"Feed-in tariff > energy price of energy provider asset '{dict_values[ENERGY_PROVIDERS][provider][LABEL]}' would cause an unbound solution and terminate the optimization."
                    raise ValueError(msg)

@Bachibouzouk
Copy link
Collaborator

hi @smartie2076
I am not so sure if what I am doing is what you're looking for.. something like that? (of course it is not done.. but errors accumulate)

@ursulaelmir if you set the code between ```python

and ```
it will highlight it like a python editor ;)

@smartie2076
Copy link
Collaborator

smartie2076 commented Aug 27, 2020

Yeah, something like that! Please always use global variables:

    for provider in dict_values[ENERGY_PROVIDERS].keys():
        feedin_tariff = dict_values[ENERGY_PROVIDERS][provider][FEEDIN_TARIFF]
        electricity_price = dict_values[ENERGY_PROVIDERS][provider][ENERGY_PRICE]
        if VALUE in feedin_tariff and VALUE in electricity_price:
            diff = feedin_tariff[VALUE] - electricity_price[VALUE]
            if diff > 0:
                msg = f"Feed-in tariff > energy price for the energy provider asset '{dict_values[ENERGY_PROVIDERS][provider][LABEL]}' would cause an unbound solution and terminate the optimization. Please reconsider your feed-in tariff and energy price."
                raise ValueError(msg)
        else: 
            diff = feedin_tariff - electricity_price
            boolean = [k > 0 for k in diff.values] # True if there is an instance where feedin tarrif > electricity_price
            if any(boolean) == True:
               instances = sum(boolean) # Count instances
                msg = f"Feed-in tariff > energy price in {instances} during the simulation time for the energy provider asset '{dict_values[ENERGY_PROVIDERS][provider][LABEL]}'. This would cause an unbound solution and terminate the optimization. Please reconsider your feed-in tariff and energy price."
                raise ValueError(msg)

@ursulaelmir
Copy link
Collaborator Author

at the moment there's a keyError 0 and when I print electricity price, it's
{'file_name': 'tariff_timeseries.csv', 'header': 'currency/kWh', 'unit': 'currency/kWh'}
for the electricity dso. not sure how to access the csv values.. @smartie2076

Copy link
Collaborator

@smartie2076 smartie2076 left a comment

Choose a reason for hiding this comment

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

Okay, nice that we have the feature of energy price tariffs tested now as well, combined with the electricity sector.

I would propose though that we split the benchmark tests into multiple files: By now I wonder what "simple_scenarios" are. I think a sector coupling example is not necessarily a simple scenario.

Also, we should add docstrings to our benchmark tests, so that we know what they are about and how we might have to fix them.

src/C0_data_processing.py Outdated Show resolved Hide resolved
tests/test_benchmark_simple_scenarios.py Outdated Show resolved Hide resolved
tests/test_benchmark_simple_scenarios.py Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
ursulaelmir and others added 9 commits August 31, 2020 16:52
Co-authored-by: smartie2076 <44204527+smartie2076@users.noreply.github.com>
Co-authored-by: smartie2076 <44204527+smartie2076@users.noreply.github.com>
Co-authored-by: smartie2076 <44204527+smartie2076@users.noreply.github.com>
Co-authored-by: smartie2076 <44204527+smartie2076@users.noreply.github.com>
@Bachibouzouk
Copy link
Collaborator

By now I wonder what "simple_scenarios" are. I think a sector coupling example is not necessarily a simple scenario.

I view the name "simple scenario" as "the simplest possible case of sector coupling". Even though sector coupling might be considered more complicated than just PV + battery.

@ursulaelmir
Copy link
Collaborator Author

@smartie2076 I added some definitions for the benchmark tests and removed the word "simple" for now. Is this okay?

@smartie2076
Copy link
Collaborator

By now I wonder what "simple_scenarios" are. I think a sector coupling example is not necessarily a simple scenario.

I view the name "simple scenario" as "the simplest possible case of sector coupling". Even though sector coupling might be considered more complicated than just PV + battery.

Hm, but the file includes all benchmark tests for the electricity sector (#106), as well as for the heat sector - basically sector-coupled cases - (#503), and also peak demand pricing...

I probably understand it better if we have following benchmark test groups in seperate files:

  • energy system modelling ("simple scenarios")
  • extreme scenarios and validation
  • features (peak demand pricing, timeseries instead of scalars for efficiencies)
  • KPI (investment optimization, expected KPI)
  • Constraints (minimal renewable share, net zero, co2)

...@Bachibouzouk are these too many files? I am a bit peculiar in organising my files, so I am not sure.

@Bachibouzouk
Copy link
Collaborator

...@Bachibouzouk are these too many files? I am a bit peculiar in organising my files, so I am not sure.

I don't think it is too many files, it is fine :)

Copy link
Collaborator

@smartie2076 smartie2076 left a comment

Choose a reason for hiding this comment

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

Two suggestions, otherwise ready to merge!

We can rename the benchmark tests according to my suggestions in another PR. :)

docs/simulating_with_the_mvs.rst Outdated Show resolved Hide resolved
tests/test_benchmark_scenarios.py Outdated Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
ursulaelmir and others added 3 commits September 1, 2020 10:35
Co-authored-by: smartie2076 <44204527+smartie2076@users.noreply.github.com>
Co-authored-by: smartie2076 <44204527+smartie2076@users.noreply.github.com>
@ursulaelmir
Copy link
Collaborator Author

@smartie2076 there is an error I think related to merging dev into this branch. am I missing something?

@smartie2076
Copy link
Collaborator

@smartie2076 there is an error I think related to merging dev into this branch. am I missing something?

Have you added the required file constraints.csv to your benchmark tests? Is the key minimal_renewable_share in there? I got that hint from this error message:

E                   AssertionError: Key minimal_renewable_share is not in extra_parameters, but is in missing_parameters in the folder /home/travis/build/rl-institut/mvs_eland/tests/benchmark_test_inputs/AFG_grid_heatpump_heat.

E                   assert 'minimal_renewable_share' in {'maximumCap': {'default': None, 'required in files': ['energyConversion', 'energyProduction'], 'unit': 'None', 'warni...s': ['energyProviders'], 'unit': 'str', 'warning_text': 'defines the unit of power provided by a DSO (Values: str). '}}

@ursulaelmir
Copy link
Collaborator Author

@smartie2076 there is an error I think related to merging dev into this branch. am I missing something?

Have you added the required file constraints.csv to your benchmark tests? Is the key minimal_renewable_share in there? I got that hint from this error message:

E                   AssertionError: Key minimal_renewable_share is not in extra_parameters, but is in missing_parameters in the folder /home/travis/build/rl-institut/mvs_eland/tests/benchmark_test_inputs/AFG_grid_heatpump_heat.

E                   assert 'minimal_renewable_share' in {'maximumCap': {'default': None, 'required in files': ['energyConversion', 'energyProduction'], 'unit': 'None', 'warni...s': ['energyProviders'], 'unit': 'str', 'warning_text': 'defines the unit of power provided by a DSO (Values: str). '}}

THANKS!

@ursulaelmir ursulaelmir merged commit 6cea79d into dev Sep 1, 2020
@ursulaelmir ursulaelmir deleted the Benchmark_heat branch September 1, 2020 11:43
@Bachibouzouk Bachibouzouk mentioned this pull request Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write benchmark tests for heat sector
3 participants