Skip to content

Add tests for adding minimal_renewable_share#742

Merged
mahendrark merged 18 commits intodevfrom
feature/tests_renewableshare
Jan 18, 2021
Merged

Add tests for adding minimal_renewable_share#742
mahendrark merged 18 commits intodevfrom
feature/tests_renewableshare

Conversation

@mahendrark
Copy link
Copy Markdown
Contributor

@mahendrark mahendrark commented Dec 25, 2020

Fix #732

Changes proposed in this pull request:

  • Your_changes

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

  • Use in-line comments to explain your code
  • Write docstrings to your code (example docstring)
  • For new functionalities: Explain in readthedocs
  • Write test(s) for your new patch of code (pytests, assertion debug messages)
  • 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.

@mahendrark
Copy link
Copy Markdown
Contributor Author

mahendrark commented Dec 25, 2020

@smartie2076

Can you please tell me how do I access the value of minimal_renewable_share from the oemof solph object local_energy_system ?

For example, for the maximum_emission, model.integral_limit_emission_factor.NoConstraint[0] is used for the assertion and testing the function. Is there some variable like that for minimum_renewable_share as well? And how to find it?

@mahendrark
Copy link
Copy Markdown
Contributor Author

self.exp_emission_limit = 1000

I do not understand how this test is passing.. The assertion basically means None == 1000, as I understood it

    def test_add_constraints_maximum_emissions_None(self):
        dict_values = self.dict_values.copy()
        dict_values.update(
            {
                CONSTRAINTS: {
                    MAXIMUM_EMISSIONS: {VALUE: None},
                    MINIMAL_RENEWABLE_FACTOR: {
                        VALUE: self.dict_values[CONSTRAINTS][MINIMAL_RENEWABLE_FACTOR][
                            VALUE
                        ]
                    },
                }
            }
        )
        model = D2.add_constraints(
            local_energy_system=self.model,
            dict_values=self.dict_values,
            dict_model=self.dict_model,
        )
        assert (
            model.integral_limit_emission_factor.NoConstraint[0]
            == self.exp_emission_limit
        ), f"When maximum_emission is None, no emission constraint should be added to the ESM."

@smartie2076
Copy link
Copy Markdown
Collaborator

Can you please tell me how do I access the value of minimal_renewable_share from the oemof solph object local_energy_system ?

For example, for the maximum_emission, model.integral_limit_emission_factor.NoConstraint[0] is used for the assertion and testing the function. Is there some variable like that for minimum_renewable_share as well? And how to find it?

I am not sure that this can work here. It works with the emission limit, because it is an inbuild oemof function - but the renewable share limit is actually a constraint added by us as a custom constraint. It may be possible to access the value with self.constraint_minimal_renewable_share or self.renewable_share_rule, but I do not know. @SabineHaas has much more experience in this kind of oemof tests.

(according to this pyomo command: model.constraint_minimal_renewable_share = po.Constraint(rule=renewable_share_rule))

@smartie2076 smartie2076 mentioned this pull request Jan 6, 2021
20 tasks
@smartie2076
Copy link
Copy Markdown
Collaborator

@mahendrark what did you find out about this?

@SabineHaas is the test that @mahendrark is planning possible as he proposed? Or should this PR be abandoned (and closed)?

@mahendrark
Copy link
Copy Markdown
Contributor Author

@smartie2076

I did not yet work on this after the last commits.
I still do not know how to access the particular variable I want to use in the assertion.

I will look into it again and see if I can figure it out.

Copy link
Copy Markdown
Contributor

@SabineHaas SabineHaas left a comment

Choose a reason for hiding this comment

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

As far as I can see, you can just check whether the attribute constraint_minimal_renewable_share of model exists, as it should not exist in case of minimal_renewable_share=0, see here

@SabineHaas
Copy link
Copy Markdown
Contributor

SabineHaas commented Jan 13, 2021

I do not understand how this test is passing.. The assertion basically means None == 1000, as I understood it

Ohohh thanks for noticing.
I'll fix this in a separate PR, merging into this PR as it might affect your changes @mahendrark

@mahendrark
Copy link
Copy Markdown
Contributor Author

mahendrark commented Jan 13, 2021

@SabineHaas

you can do it right here as well. That would not pose a problem for me :)

I do not plan to work on it in this week.

@SabineHaas
Copy link
Copy Markdown
Contributor

@SabineHaas

you can do it right here as well. That would not pose a problem for me :)

I do not plan to work on it in this week.

Ah, thanks, that's good to know! I will nevertheless to a PR into this PR :)

@SabineHaas
Copy link
Copy Markdown
Contributor

@mahendrark I'm done with #759. The tests will fail due to the renewable share test. I also used hasattr() now for one of the maximum emissions constraint tests, which will help you with the renewable share test.

@mahendrark mahendrark force-pushed the feature/tests_renewableshare branch from 9cccfe1 to 56968df Compare January 14, 2021 12:01
@mahendrark
Copy link
Copy Markdown
Contributor Author

@SabineHaas

Can you please advice me on how to test constraint_minimal_renewable_share function?

@SabineHaas
Copy link
Copy Markdown
Contributor

@SabineHaas

Can you please advice me on how to test constraint_minimal_renewable_share function?

As I wrote above, I would just check whether the attribute constraint_minimal_renewable_share of model exists, as it should not exist in case of minimal_renewable_share=0, see here. You can use hasattr(), check how I did that for the maximum emissions constraint. Please also take into account the comments I have already written above.

@mahendrark
Copy link
Copy Markdown
Contributor Author

@SabineHaas
Can you please advice me on how to test constraint_minimal_renewable_share function?

As I wrote above, I would just check whether the attribute constraint_minimal_renewable_share of model exists, as it should not exist in case of minimal_renewable_share=0, see here. You can use hasattr(), check how I did that for the maximum emissions constraint. Please also take into account the comments I have already written above.

I am done with this. This is not the issue.

I already wrote following tests based on your inputs and they pass without issue:

test_add_constraints_minimal_renewable_share
test_add_constraints_minimal_renewable_share_is_0

My question is how to proceed with test_constraint_minimal_renewable_share. Testing the constraint itself, like you did with test_constraint_maximum_emissions.

@mahendrark mahendrark requested a review from SabineHaas January 14, 2021 13:49
@SabineHaas
Copy link
Copy Markdown
Contributor

SabineHaas commented Jan 14, 2021

Ah I see that you have pushed the changes now.

My question is how to proceed with test_constraint_minimal_renewable_share. Testing the constraint itself, like you did with test_constraint_maximum_emissions.

I don't think it's necessary as it's functionality is tested in Test_Constraints.test_benchmark_minimal_renewable_share_constraint() already.

If you still want to test it, you would have to check for the expression rather than a value (so, differently from the maximum emissions constraint test), I think. However, I would have to look into that more closely to tell you what exactly to test and if the test is not absolutely necessary I'd rather leave this out for now.

Copy link
Copy Markdown
Contributor

@SabineHaas SabineHaas left a comment

Choose a reason for hiding this comment

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

Thanks @mahendrark !
I already reviewed your last changes.

@mahendrark mahendrark force-pushed the feature/tests_renewableshare branch from e3c0211 to 248598a Compare January 14, 2021 17:47
@mahendrark mahendrark requested a review from SabineHaas January 14, 2021 17:48
Copy link
Copy Markdown
Contributor

@SabineHaas SabineHaas left a comment

Choose a reason for hiding this comment

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

Great @mahendrark !
I only added minor suggestions. After their application you can merge.

@mahendrark mahendrark merged commit 04e8ca0 into dev Jan 18, 2021
@mahendrark mahendrark deleted the feature/tests_renewableshare branch January 18, 2021 10:36
@mahendrark
Copy link
Copy Markdown
Contributor Author

@SabineHaas

thank you for the help and guidance during this PR :)

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.

Add tests for adding renewable share constraint

3 participants