-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Speedup of singlediode._lambertw function #1010
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
Comments
Not opposed but not excited about the specific proposal. What about a helper function |
Or just use Newton, or the explicit method. Why do you need Lambert W? What is your use case?
SciPy was specifically modified to allow us to use a vectorised version of See these issues |
Thanks for the suggestions. I wrote a quick performance testing script and found that import numpy as np
from time import time
from pvlib.pvsystem import singlediode
photocurrent = np.random.random(100000)*9
saturation_current = 1e-9 + np.zeros_like(photocurrent)
resistance_series = 0.5 + np.zeros_like(photocurrent)
resistance_shunt = 100 + np.zeros_like(photocurrent)
nNsVth = 1.8 + np.zeros_like(photocurrent)
start_time = time()
out = singlediode(photocurrent,saturation_current,resistance_series,resistance_shunt,
nNsVth,method='lambertw')
print('Lambertw method elapsed time: {:.3f} s'.format( time() - start_time))
start_time = time()
out = singlediode(photocurrent,saturation_current,resistance_series,resistance_shunt,
nNsVth,method='newton')
print('Newton method elapsed time: {:.3f} s'.format( time() - start_time))
# Lambertw method elapsed time: 0.685 s
# Newton method elapsed time: 0.281 s |
I believe it's because of the possibility that Newton could have trouble converging, but I also think that concern may have been overstated, b/c these curves are all monotonic. But I think this concern is also why we provided the Brent method in addition to Newton, b/c it's guaranteed to converge for monotonic curves to any point between the bounds of Isc and Voc. However the Brent method is still using |
My personal testing has shown that if you are after the most accurate solutions, the LambertW method is more reliable than the Newton/Brentq methods, but, the difference in accuracy is typically in the 11th and lower significant digits. I doubt most users would notice, or care, about these differences. |
And solving 10^5 diode equations in a fraction of a second isn't bad performance in my opinion :) |
Thanks for this advice! I think the Newton method will be accurate enough for my application. We can then avoid making any changes to the library. |
I have an application where I need to evaluate _lambertw many many times. Even a small speedup would be helpful. Currently _lambertw calculates IV curve points like
I_x
,I_xx
that I don't need. What about adding an input flag that allows us to skip the evaluation of some parameters?The version I wrote to do this is below, but there are other ways this could be done as well.
The text was updated successfully, but these errors were encountered: