-
Notifications
You must be signed in to change notification settings - Fork 154
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
Resolve the issue of zero capacity factor #561
Conversation
Codecov Report
@@ Coverage Diff @@
## main #561 +/- ##
=======================================
+ Coverage 92.7% 92.8% +0.1%
=======================================
Files 41 42 +1
Lines 3236 3287 +51
=======================================
+ Hits 3001 3052 +51
Misses 235 235
|
@khaeru, I went further and resolved the issue in the GAMS formulation, by adding a new masking set ("is_capacity_factor"). For populating this set on the python side, I copied the code you suggested in #514 (the part related to the |
Will jump in here once #559 is addressed. |
eb27371
to
5f25a49
Compare
e697161
to
11a503b
Compare
@behnam-zakeri I've now done this (about 2.5 hours), saving us about 400 lines of code in the test files while still doing all the same tests. To me, at least, they are now easier to read & distinguish from one another. However, one question came up in the process, so I hope you can help: Two of the tests ( def test_func():
try:
do_stuff()
except AssertionError:
pass This test will pass if do_stuff() raises an AssertionError. But it will also pass if do_stuff() doesn't raise any error at all. So the expected behaviour is ambiguous. I changed these to the standard way of using pytest: def test_func():
with pytest.raises(AssertionError):
do_stuff() This is more explicit: it will pass if do_stuff() raises an AssertionError as expected, but the test will fail if the error is not raised. I find these tests now fail. From the docstrings/comments:
Can you identify what's going on in each case? What do we actually expect—maybe that the model actually should solve in each case, but the assertions in check_solution(scen) should fail? |
The last commit makes this change, and the tests now pass, so I assume that was the case. |
87dff44
to
bf145f9
Compare
Thanks a lot @khaeru for reformatting and improvements. Related to your question |
- Adapted from .test_feature_capacity_factor.model_generator() with the following improvements: - Don't generate and assert in the same function; split assertions to a separate function, check_solution() that remains with test code. - Use the pytest `request` fixture to access `test_mp` instead of passing it separately. - Use `request.node.name` instead of defining and passing a `comment` argument. - Remove the `year` argument, since calls to the function never override the default. - Collapse separate function add_cap_par() into the function body, since this is the only place it is used. - Use make_df() instead of assuming dimension order. - Use PEP 257-compliant docstrings, i.e. initial line is a single line.
Improve docstrings
1dec9a5
to
fae1455
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you! Just some, suggestions in line.
if existing.equals(expected): | ||
continue # Contents are as expected; do nothing | ||
# else: | ||
# scenario.add_set(set_name, expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be sure, both lines above are commented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm not sure why; they're not on #514 from which this was cherry-picked. That PR will need to be deconflicted when it is rebased, so we can clean up/remove then.
tec_dict["gas_ppl"]["time_origin"] = ["year"] | ||
|
||
scen = make_subannual( | ||
request, | ||
tec_dict, | ||
time_steps=[("summer", 1, "season", "year")], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also think about moving this up and create e.g. TS_0 to reduce duplication (this line and line 75).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, true. I skipped this one because it doesn't save on # of lines.
Co-authored-by: Laura Wienpahl <57132039+LauWien@users.noreply.github.com>
Thanks for the review! Will merge once checks again pass. |
Thanks @behnam-zakeri for the contributions! 🎉 |
This PR adds tests for parameter "capacity_factor" to address the requirements mentioned in #515.
How to review
Please make a copy of this branch, run the test with the existing code, and the tests should pass.
PR checklist
model_generator()
methods in test_feature_temporal_level.py and test_feature_capacity_factor.py (@khaeru)