-
Notifications
You must be signed in to change notification settings - Fork 1.1k
add tolerance to tools._golden_sect_Dataframe #1089
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
If I recall correctly, @mikofski contributed a vectorized newton optimizer to scipy in large part so that we could remove this function. |
He did, and it's in scipy now, thanks for that reminder. I'll have to think a bit about ways to get an initial estimate of Vmp that minimizes risk of divergence. That's why the bisection algorithm was originally in PVLib for Matlab, which led to the golden section function. It also appears that at least some of the previous "known" solutions for single diode equations using the 'lambertw' method were not converged. This PR will take more work than I initially thought. |
I added 2 SciPy methods, the vectorized newton method which uses NumPy, and a cythonized api to the bounded search methods, with examples to call them with cythonize |
Toms 748 is another bounded search algorithm but idk if it's vectorized |
This is ready for review. I recalculated the IV curves used for several tests to add precision. I believe the old expected results were done by me, in Matlab, before we improved convergence in the PV_Lib Matlab code. |
I'm a little confused... the linked PR adds a warning to the user that iteration limit was exceeded, but you're removing it in this PR. Maybe you meant to point to a different PR? Still wondering if removing that exception is a good idea though. Perhaps a warning would be better than an exception and maybe more consistent with other solvers. |
Understandable. That work in PV_LIB for Matlab wasn't done via PRs, now that I look again at the one I linked. Theoretically, the exit criterion ( |
You can add I'm ok moving forward without the check if others are too. |
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.
I'm ok moving forward without the check if others are too.
I'm not familiar enough with what's happening here to vote. I don't object, anyway.
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.
Shall we merge?
I am wondering if there's a meaningful difference in execution time. If so, might be worth noting in the what's new.
For the golden section function, the old default tolerance was 1e-2. With the new default of 1e-8, convergence takes 3x longer when applied to the test function. That's probably typical of what will be seen when solving single diode equations. I don't think the increase will be visible in a ModelChain simulation (most of the execution time is in the solar position algorithm).
|
Co-authored-by: Will Holmgren <[email protected]>
iterations = 0 | ||
iterlimit = 1 + np.max( | ||
np.trunc(np.log(atol / (df['VH'] - df['VL'])) / np.log(phim1))) |
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.
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.
I agree. But handling nan
in the bounds and where returned by func
is a bit more involved. Currently, I think the optimization would run to its iteration limit.
[ ] Updates entries todocs/sphinx/source/api.rst
for API changes.docs/sphinx/source/whatsnew
for all changes. Includes link to the GitHub Issue with:issue:`num`
or this Pull Request with:pull:`num`
. Includes contributor name and/or GitHub username (link with:ghuser:`user`
).Sticking with
tools._golden_sect_DataFrame
because it vectorizes single-variable optimization, which looks clumsy (if possible at all) with existingscipy
tools. Absolute tolerance was hardwired at 0.01V. Setting a default absolute tolerance of 1e-8V takes care of the reported instability.