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)

Most upvoted comments

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 the Location.get_solarposition method, and again inside ModelChain.run_model at the prepare_inputs step:

for i in range(rg):
    system = get_system()
    location = get_location()
    mc = get_mc(system, location)
    mc.solar_position = mc.location.get_solarposition(times)
    weather = get_weather(mc, times)
    mc.run_model(times=times, weather=weather)

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 and nrel_numba values for the solar_position_method kwarg.

When mc is created, solar_position_method is set to nrel_numba. However, that attribute is NOT used by the attached Location object’s method

mc.solar_position = mc.location.get_solarposition(times)

As a consequence, the first time solar position is calculated, nrel_numpy (the default) is used. The next time is via this line in ModelChain.prepare_inputs:

       self.solar_position = self.location.get_solarposition(
            self.times, method=self.solar_position_method)

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 method get_solarposition that does not inspect ModelChain.solar_position_method and hence if called, defaults to nrel_numpy. How to fix this, or whether to fix it, is where I’m unclear.

Cause confirmed. Adding the method argument

mc.solar_position = mc.location.get_solarposition(times, method=mc.solar_position_method)

stops the leak.