-
Notifications
You must be signed in to change notification settings - Fork 10
Create costs module and simplify code for objectives and outputs #462
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
Conversation
|
Actually the results are now different when I use the |
I think there was an error before with the Very confused about |
dalonsoa
left a comment
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.
I think this is a much needed improvement, reducing the redundancy of functions that were supposed to be doing the same thing. Homogenising the interface of the functions and reducing code duplication is also great. I think that any discrepancy with the previous results is likely to be the result of fixing a bug we didn't know we had. None of the tutorials or examples need updating so, at least for the functionality they use like LCOE, these changes have no negative impact.
Testing the results of mathematical formulas in a meaningful way is always tricky, as the only way of actually test if the numerical values are correct is to calculate them, which in turns uses the formula you're trying to test. Testing the properties of the outputs rather than the numerical values seems like a good compromise.
If you want to take one more step, you could use the hypothesis package to evaluate the functions under a range of conditions, and then evaluate properties of the results rather than specific numerical values (eg. all should be positive values, or be within certain range, or add up to 1, etc.). This is useful to find edge cases that are difficult to find manually.
|
Thanks. I'm actually quite keen to give hypothesis a try, and this seems like a good place for it, so I'll open up another issue for that |
Description
I've been digging into the code to get some more clarity on how costs (LCOE, ALCOE, EAC etc.) are calculated and used, but the issue is that the code for calculating these costs is defined in multiple places which makes it really tricky to see what's going on, could lead to inconsistencies, and is just a bad idea in general.
To tidy things up, I've created a new
costsmodule that houses these calculations, and modified other parts of the codebase (specifically the outputs and objectives modules) to call these functions rather than repeating the calculations. Hopefully this will also make #288 easier to tackle.It looks like a massive PR, but it's almost entirely just moving and deleting code, and creating some new tests.
Some more details about the specific changes:
Costs module:
objectivesmoduleannual_levelized_cost_of_energyandsupply_costhere fromquantities.pytest_costs.py. At the moment, this just goes through each function with some example data to check that the function runs, and that the dimensions of the result are as expected. I notice there are some differences between functions (e.g. the ALCOE function gets rid of theassetdimension), but this is something that can be looked into later and potentially homogenized.Outputs module:
capacity_to_service_demand(which was defined multiple times) toquantities.pyObjectives module:
agent,demand,search_space,technologiesandmarket. In all cases,search_spacewould be used to filter the technologies and reduce the dimensions of the demand object. Agent was also used in the filtering (to filter objects based on the agent's region and forecast year), and to get the forecast year while computing the objectives. Market was only used to get commodity prices.technologies,demandandprices). The objectives can get the forecast year from the demand object (a bit of a hack, but it works ok for now)test_costs.pyType of change
Please add a line in the relevant section of
CHANGELOG.md to
document the change (include PR #) - note reverse order of PR #s.
Key checklist
$ python -m pytest$ python -m sphinx -b html docs docs/buildFurther checks