-
Notifications
You must be signed in to change notification settings - Fork 1.1k
add v_from_i, improve singlediode speed by 2x #190
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
Will, The numerical issue is to handle overflow in the lambertw function. Cliff |
What do you think about replacing the golden section determination of Pmp by a lambertw approach? Is the Pmp determination the limiting performance step in this subroutine? We used a Pmp from lambertw approach in PVLib matlab to get past a piece of custom optimization for which we couldn't release source code. It still uses an iteration so maybe we can reuse the golden section search code. |
The Pmp determination is the limiting step and it would be great to speed it up in any way. Over the weekend I benchmarked some of Scipy's optimization routines for Pmp but could not find anything as fast as what we already have. The fastest was scipy.optimize.fmin_tnc and it was 50% slower than our method. I also implemented a dpower/dcurrent function based on Jain and Kapoor and supplied it to the optimization routines. If I remember correctly, the optimizer is about twice as slow if it has to compute the gradients numerically, though it varies a bit depending on which optimizer you choose. In any case, I pushed what I did to my scipyoptimize branch. Here's the crux of it: https://github.com/wholmgren/pvlib-python/blob/scipyoptimize/pvlib/pvsystem.py#L1422 It might be possible to speed up that loop with multithreading or numba JIT. That scipy function should release the GIL and allow for efficient multithreading, but it won't make any difference if the functions that it's calling are Python functions. It might not be too hard to write the these simple functions in cython, though. The first thing I would do is decorate the function with numba.jit and see if it helps (see spa.py for examples, though it does a little bit of work first to avoid making numba a pvlib requirement). If that's all new to you, then welcome to Python's multithreading hell. |
I added |
Matlab PVLib currently uses a bisection to find Vmp, then gets Imp from Vmp. Its faster than the Matlab root finder, and guarantees convergence. The function operated on by the bisection (to find a zero) involves Lamberts W. I can implement in python next week (I hope) when I’m back from catching fish. Cliff |
Great, thanks. I'm going to merge this in the meantime. |
I implemented a
v_from_i
function, similar toi_from_v
, by following Jain and Kapoor (2004) and PVLIB MATLAB pvl_singlediode.m. This lets us replace thesinglediode
function's numerical solver for v_oc with an analytic solution. Thus, thesinglediode
function is about 2x faster.The analytic solution differs from the numerical solution by a little more than 1 part in 1000, which is similar to the tolerance of the
_golden_sect_DataFrame
numerical solver.