-
Notifications
You must be signed in to change notification settings - Fork 156
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
Speed up turbine loading operation #966
Conversation
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.
Reviewing the code and checking the tests this all looks good. the only thought I had, would 1 or 2 additional tests where the number of unique turbine types is different than the number of turbines (and some assertions about what should be observed) be good to add while we're at it? Or is that all sufficiently covered by existing tests?
Looking across the speed results here and on #965, it seems that the "remaining" time between the n_findex=300 and n_findex=3000 cases is approximately 5 seconds across various machines (or more like 3 seconds when using python 3.11) when setting 1000 turbines. |
Yeah, I could add a quick test for that. The test I've added currently have 5 turbines, one of which is different, but I should check that now if |
…anges as expected.
I have now added this test |
Good to go from me then! |
@misi9170 Yea, this looks nice! Just one suggestion in my comment above. |
This is now done |
@Bartdoekemeijer points out in #965 that instantiating the
FlorisModel
can be slow, especially when there are many turbines. @achenry had also pointed out a similar problem in #885.After looking into this some, and using the profiling method suggested by @achenry, I found that a lot of time is being spent in the
construct_turbine_map()
method ofFarm
. Essentially, eachTurbine
is being instantiated separately, even if all turbines are the same type (which is often the case).This PR proposes a fix to this that only calls
Turbine.from_dict()
once for each type of turbine, and then uses those (fewer) instantiations to construct theFarm.turbine_map
. I'm seeing a substantial speed up, and now I think (after the change) that instantiation speed is dominated byn_findex
rather thann_turbines
.There may be other opportunities for speed up during instantiation, but I think this may be the lowest hanging fruit.
Notes
I took the opportunity to also partly address #864, which raises the issue that the
"turbine_type"
key of the turbine dictionary must be changed in order to implement changes to other parts of the dictionary. While the changes I have made here do not necessarily "fix" the issue, now an informative error is raised when this situation arises.Affected areas of the code
Tests
"turbine_type"
turbine_map
correctlyExamples
The main relevant example is examples/examples_turbine/002_multiple_turbine_types.py. I see no change to the outputs, as expected.
Performance
Using the example code in #965, I get the following performance on the develop branch:
while this PR provides: