pvlib-python: Slow calculation and memory leaking with 0.5.1
Hi all,
I am using pvlib to calculate many pv arrays and do this by looping over the individual system specs. Since updating on 0.5.1, I noticed much longer calculation times and a steady increase in memory usage.
From a quick glance at the changes from 0.5.0 I couldn’t determine an obvious cause for this behavior. Did I miss something?
My parameters for the calculation are
ModelChain(system, location, dc_model='singlediode', ac_model='snlinverter', spectral_model='no_loss', temp_model='sapm', aoi_model='ashrae', solar_position_method='nrel_numba', transposition_model='haydavies', losses_model='pvwatts', clearsky_model='simplified_solis', orientation_strategy=None)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 31 (31 by maintainers)
I think I know why this memory leak happens, and I think there’s an issue for us but I haven’t quite got the issue nailed down. In @jkfm script,
mc.solar_position
is computed twice each loop, once explicitly using theLocation.get_solarposition
method, and again insideModelChain.run_model
at theprepare_inputs
step:The memory leak only happens when both calculations are in the loop: comment either one out, and no leak.
The leak appears to be caused by cycling between
nrel_numpy
andnrel_numba
values for thesolar_position_method
kwarg.When
mc
is created,solar_position_method
is set tonrel_numba
. However, that attribute is NOT used by the attachedLocation
object’s methodAs a consequence, the first time solar position is calculated,
nrel_numpy
(the default) is used. The next time is via this line inModelChain.prepare_inputs
:which passes the value
self.solar_position_method='nrel_numba'
, assigned when the ModelChain instance is created.The issue for us, is that
ModelChain.location
brings a methodget_solarposition
that does not inspectModelChain.solar_position_method
and hence if called, defaults tonrel_numpy
. How to fix this, or whether to fix it, is where I’m unclear.Cause confirmed. Adding the method argument
stops the leak.