RuntimeError while using the fit_desoto function, caused by optimize.root (SciPy)
See original GitHub issueHello everyone,
while using the fit_desoto function to estimate parameters for further solar module calculations, I received the following error:
RuntimeError: Parameter estimation failed: The iteration is not making good progress, as measured by the improvement from the last five Jacobian evaluations.
The error comes from the optimize.root function from the SciPy library, which is used within the fit_desoto function.
Even if I use only 1s for the initial values of the fit_desoto function, I get this error.
The code for the function call in the main programm:
self.mp_desoto_fit = pvlib.ivtools.sdm.fit_desoto(v_mp=module['Vmpo'], i_mp=module['Impo'], v_oc=module['Voco'], i_sc=module['Isco'], alpha_sc=module['Aisc'], beta_voc=module['Bvoco'], cells_in_series=module['Cells_in_Series'], EgRef=1.121, dEgdT=-0.0002677, temp_ref=25, irrad_ref=1000, root_kwargs={'options': {'col_deriv': 0, 'xtol': 1.49012e-05, 'maxfev': 0, 'band': None, 'eps': None, 'factor': 100, 'diag': None}})
The root_kwargs in the function call of the fit_desoto function influence the solver of the root function, but different properties for the solver don’t fix the problem.
To Reproduce the error You can easily reproduce the error by simply using the fit_desoto function. It doesn’t make a difference if you use concrete values of a photovoltaic cell or just 1s. All values after cells in series (8) are default values.
mp_desoto_fit_num = pvlib.ivtools.sdm.fit_desoto(4.568, 3.3, 5.36, 3.5, 0.0010, -0.0158, 8, EgRef=1.121, dEgdT=-0.0002677, temp_ref=25, irrad_ref=1000, root_kwargs={})
or
mp_desoto_fit_ones = pvlib.ivtools.sdm.fit_desoto(1, 1, 1, 1, 1, 1, 1, EgRef=1.121, dEgdT=-0.0002677, temp_ref=25, irrad_ref=1000, root_kwargs={})
When using those code examples the error message changes to:
RuntimeError: Parameter estimation failed: The iteration is not making good progress, as measured by the improvement from the last ten iterations.
Do you have any ideas on this issue?
What I already tried:
-
Checked all types of initial values for the fit_desoto function (temperature coefficients are handed over in [A/K]).
-
Choosed different options for the root function solver with the method ‘hybr’
-
Code debugged and checked the variables inside the root_function. No NaN values or similar arise while the function is calculating
Suggestions perhaps the problem could be solved by choosing a different method for the root function via the function call of fit_desoto. The kwargs of the fit_desoto function itself can only change the options of the solver, but not which method is used. The default method is “hybr” which is only one of several.
Thanks in advance!
Versions: numpy 1.20.2 pandas 1.2.4 pvlib 0.8.1 scipy 1.6.3 python 3.9.0
I am using Spyder and/or PyCharm
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
I think the first problem in
fit_desoto
is that it raises an error and swallows the optimize_result. That makes it much harder to investigate. At most it should produce a warning.similar dialogue over at scipy on similar issue, https://github.com/scipy/scipy/issues/8904#issuecomment-395143111, is it runtime error or warning?
They opted for
display=True
&full_output=True
to return warning and the reasons why, vs.False
which raises error. AFAICTscipy.optimize.root(method='hybr')
uses the MINPACK HYBR or HYBRJ solver depending on if the Jacobian is provided or not, and always returns anOptimizedResult
with full output regardless of whether it converged or not. It’s up to the user to look at the condition of the result, which is whatfit_desoto
does here:https://github.com/pvlib/pvlib-python/blob/5bdad64434ef4e432b893313e0858a02b02480b6/pvlib/ivtools/sdm.py#L228-L232
so if we change this, then we can get the output of the
OptimizedResults